Thread: Simple(Or so I thought..) 2D math

1. Simple(Or so I thought..) 2D math

Ok, basically I'm making a small game that communicates over the network, now the network code works fine, but this is my first time programming in OpenGL.

I've got it setup where 4 rotates left, 6 rotates right, and 8 is up and 5 & 2 are down.

I can't seem to get the coordinate updates to work I can rotate just fine but when I press 8 to go forward it goes some random(or so it seems direction)

what is an easy way to solve this?

2. Re: Simple(Or so I thought..) 2D math

When you rotate, you're also rotating your axes. Pressing 8 after a rotation will cause a forward motion with respect to your new axes, which is why you're not seeing the kind of motion you're expecting.
Try using quaternions for your rotations.

3. Re: Simple(Or so I thought..) 2D math

there is absolutely no need for quaternions in this situation. Use sin and cos to decompose the angle and magnitude into x and y coordinates. So

X+=v*cos(angle)
Y+=v*sin(angle)

something like that

4. Re: Simple(Or so I thought..) 2D math

Ok, So the axes rotate at with the same incrementation we use to rotate our object?

Right now we have it rotating + or - 10.0f.

The way we had it set up is basically like this to change x & y:
float nXPos, nYPos = 0;
//nMovement is 3 pixels
//this is for hitting '8'
if(fHeading >= 0.0f && fHeading =< 90.0f)
{
nXPos = nXPos + (nMovement * cos(fHeading));
nYPos = nYpos + (nMovement * sin(fHeading));
}
then from there we followed the rules of trig for different angles.

So if my axes also rotate how would I adjust for that in my math?

5. Re: Simple(Or so I thought..) 2D math

you have it set up perfectly, your mistake is that sin and cos take arguments in radians and you are giving them in degrees. Just multiply by pi/180

6. Re: Simple(Or so I thought..) 2D math

Also make sure the camera and projection are plugged correctly, sometimes it's easy to mix up the rotation with the controls, because of one misplaced ",". Just a precaution if it's not the math.

Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•