Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 71 72 [73] 74 75 ... 91

Author Topic: Programming Help Thread (For Dummies)  (Read 100484 times)

head

  • Bay Watcher
  • Whoop Whoop.
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #1080 on: June 04, 2013, 07:40:26 pm »

Well, since this is a programing issue, i hope it fits right into here.


I'll let the image explain.

Logged
Dev on Baystation12- Forums
Steam Username : Headswe

Skyrunner

  • Bay Watcher
  • ?!?!
    • View Profile
    • Portfolio
Re: Programming Help Thread (For Dummies)
« Reply #1081 on: June 04, 2013, 11:00:00 pm »

What are you doing? Rotating the triangle? O.o
Logged

bay12 lower boards IRC:irc.darkmyst.org @ #bay12lb
"Oh, they never lie. They dissemble, evade, prevaricate, confoud, confuse, distract, obscure, subtly misrepresent and willfully misunderstand with what often appears to be a positively gleeful relish ... but they never lie" -- Look To Windward

Normandy

  • Bay Watcher
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #1082 on: June 04, 2013, 11:52:03 pm »

@head:
Assuming that you are trying to rotate the triangle, there are a couple of things that could have gone wrong with your math or code:
- Are you using radians? Most programming languages use radians, not degrees.
- What exactly are you using to get the positions of point 2 and 3? The formula you give doesn't give enough information.
- Remember where your axes are and where they're pointing. In school you learn x to the right, y upwards, angles going counterclockwise from the positive x-axis (i.e. from 3 o'clock). According to your picture, you've got x to the right, y upwards, angles going counterclockwise from the north (i.e. from 12 o'clock). Computer graphics conventions are x to the right, y downwards, angles going clockwise from the positive x-axis. Using computer graphics conventions, the formula you give will generate a point directly upwards of point 1, which will rotate counterclockwise, which appears to be what you're looking for.

As an additional note:
- You don't need the modulo/remainder (%) sign, sine/cosine return the same result without it there. That being said, note that modulo has the same precedence as division, i.e. you need to put anything you're taking the remainder of in parenthesis (unitdir+180)%360.
Logged

Skyrunner

  • Bay Watcher
  • ?!?!
    • View Profile
    • Portfolio
Re: Programming Help Thread (For Dummies)
« Reply #1083 on: June 05, 2013, 02:10:09 am »

Also, unless you are already using it, or have a reason not to use it, you should try using the rotation matrix's linear forms. Could set 1 as the pivot and edit the coords of 2 and 3 for an easy rotation :O
Logged

bay12 lower boards IRC:irc.darkmyst.org @ #bay12lb
"Oh, they never lie. They dissemble, evade, prevaricate, confoud, confuse, distract, obscure, subtly misrepresent and willfully misunderstand with what often appears to be a positively gleeful relish ... but they never lie" -- Look To Windward

head

  • Bay Watcher
  • Whoop Whoop.
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #1084 on: June 05, 2013, 04:35:51 am »

wish i was less shit as explaining things but i'l try.


I have a unit, the unit can rotate 360 degrees.
direction is a float.
distance is in meters.

What i'm trying to do is to create three points behind my unit that express a triangle. 60 degrees or so in each angle.

End result, a triangle i can check if any other units are inside.
Logged
Dev on Baystation12- Forums
Steam Username : Headswe

cerapa

  • Bay Watcher
  • It wont bite....unless you are the sun.
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #1085 on: June 05, 2013, 05:01:16 am »

wish i was less shit as explaining things but i'l try.


I have a unit, the unit can rotate 360 degrees.
direction is a float.
distance is in meters.

What i'm trying to do is to create three points behind my unit that express a triangle. 60 degrees or so in each angle.

End result, a triangle i can check if any other units are inside.
I think you mean integer instead of meter. Usually better to store locations in floats rather than integers, otherwise you can't really control movement very well.

Is the units location one of the points of the triangle?

EDIT:

Ok, so, if I understand this correctly, the blue dot is the unit and behind it are 2 points seperated by 60 degrees.

The direction from the front of one of the points is unitdir+150 degrees (convert to radians if necessary)
The others is unitdir + 210 degrees.

Now they are a distance of L from the units direction.

The formulae for the points are:
x = unitX + cos(pointdir)*L
y = unitY + sin(pointdir)*L

(pretty much just moving a certain distance at a certain angle from the unit)

Looking at your stuff, it seems you flipped the sin and cos.(or I did, never was good at trigonometry). And you only brought out the formulae for a point directly behind the unit?
« Last Edit: June 05, 2013, 05:22:46 am by cerapa »
Logged

Tick, tick, tick the time goes by,
tick, tick, tick the clock blows up.

monkey

  • Bay Watcher
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #1086 on: June 05, 2013, 01:00:00 pm »

End result, a triangle i can check if any other units are inside.

I think that you can also do a dot product to check if 2 / 3 are inside a infinite cone with the apex at the leading unit, and then check distance to 1. ( C wont be a straight line )

ie:
 dot = (heading of leading unit) . ( pos of follower - pos leading unit ) 

if |dot| < some_value, you are inside the cone.

(Needs tons of verification)
Logged

head

  • Bay Watcher
  • Whoop Whoop.
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #1087 on: June 05, 2013, 05:32:15 pm »

Solved it.


Code: [Select]
_p1 = _pos;
_p2 = [(_p1 select 0) + (sin((_angle)+35)*4) , (_p1 select 1) + (cos((_angle)+35)*4.0) ];
_p3 = [(_p1 select 0) + (sin((_angle)-35)*4) , (_p1 select 1) + (cos((_angle)-35)*4.0) ];


_p = getpos _x;

_B = [_p select 0, _p select 1, _p2 select 0, _p2 select 1, _p3 select 0,_p3 select 1] call _sfp_grg_area;
_C = [_p select 0, _p select 1, _p1 select 0, _p1 select 1, _p3 select 0,_p3 select 1] call _sfp_grg_area;
_D = [_p select 0, _p select 1, _p1 select 0, _p1 select 1, _p2 select 0,_p2 select 1] call _sfp_grg_area;
player sidechat format["%1,%2",_A,(_B + _C + _D)];
if(_A >= (_B + _C + _D) && _x != player) then
--- inside.

Logged
Dev on Baystation12- Forums
Steam Username : Headswe

Errol

  • Bay Watcher
  • Heaven or Hell, Duel 1 -- Let's Rock!
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #1088 on: June 06, 2013, 01:56:22 pm »

Right, so Lua's I/O stuff frustrates me to no end. Can someone give me a quick rundown of how the thing works, and how relative paths (starting from the location of your lua file) work? I want to export chunks of the code in its own small files, and so far my failures have been nothing but miserable.

Still having this problem. I hope it doesn't kill the thread like last time. Please, someone help.
Logged
Girls are currently preparing signature, please wait warmly until it is ready.

monkey

  • Bay Watcher
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #1089 on: June 06, 2013, 04:32:45 pm »

How are you loading the .lua files ?

luaL_loadfile does a basic fopen, so every path should be relative to the current working directory of your process.
Logged

Errol

  • Bay Watcher
  • Heaven or Hell, Duel 1 -- Let's Rock!
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #1090 on: June 07, 2013, 10:31:25 am »

I seem to have tried it with dofile. The thing I wanted to do was to push sections of the code into their own files.
Logged
Girls are currently preparing signature, please wait warmly until it is ready.

Skyrunner

  • Bay Watcher
  • ?!?!
    • View Profile
    • Portfolio
Re: Programming Help Thread (For Dummies)
« Reply #1091 on: June 07, 2013, 10:34:08 am »

I just want to note my RAEEEG while trying to learn and use Python with libtcod: it does not le me access SDL, which forces me to use libtcod's input, which makes me want to tear alll my hair out ;_;

Back to the safety of C++ it is for me.

* Skyrunner scurries away
Logged

bay12 lower boards IRC:irc.darkmyst.org @ #bay12lb
"Oh, they never lie. They dissemble, evade, prevaricate, confoud, confuse, distract, obscure, subtly misrepresent and willfully misunderstand with what often appears to be a positively gleeful relish ... but they never lie" -- Look To Windward

Normandy

  • Bay Watcher
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #1092 on: June 07, 2013, 01:41:08 pm »

@Skyrunner:
Do you think you could just use pygame along with libtcod and use pygame's event handling?
Logged

kytuzian

  • Bay Watcher
    • View Profile
    • Kytuzian - Youtube
Re: Programming Help Thread (For Dummies)
« Reply #1093 on: June 07, 2013, 02:28:37 pm »

Right, so Lua's I/O stuff frustrates me to no end. Can someone give me a quick rundown of how the thing works, and how relative paths (starting from the location of your lua file) work? I want to export chunks of the code in its own small files, and so far my failures have been nothing but miserable.

Still having this problem. I hope it doesn't kill the thread like last time. Please, someone help.

Relative paths are started by a period, just like in every other programming/scripting language I've ever used.

For example:
Code: [Select]
dofile("./army.lua")

If you want to know why, open the Command Prompt, then type "cd .".
« Last Edit: June 07, 2013, 02:38:50 pm by kytuzian »
Logged

Skyrunner

  • Bay Watcher
  • ?!?!
    • View Profile
    • Portfolio
Re: Programming Help Thread (For Dummies)
« Reply #1094 on: June 08, 2013, 03:14:26 am »

@Skyrunner:
Do you think you could just use pygame along with libtcod and use pygame's event handling?

I'd think that pygame would create a different window of SDL. >_>
Logged

bay12 lower boards IRC:irc.darkmyst.org @ #bay12lb
"Oh, they never lie. They dissemble, evade, prevaricate, confoud, confuse, distract, obscure, subtly misrepresent and willfully misunderstand with what often appears to be a positively gleeful relish ... but they never lie" -- Look To Windward
Pages: 1 ... 71 72 [73] 74 75 ... 91