Advertisement

a very basic math problem

Started by December 03, 2001 04:01 PM
8 comments, last by glGreenhorn 23 years, 2 months ago
hey! i know this is like 3rd grade math and all, but it ain''t working: i have this object you can move around the screen that is supposed to turn when you press left/right, etc. and it does, but when i set the initial value to other than zero, it starts moving in a wrong direction. this is how it''s supposed to be done, right? X -= SpeedX * sin(AngleOfTheObject); Y -= SpeedY * cos(AngleOfTheObject); make no mistake - my math barely sucks (that means it''s well below that ) keep cool! and thanks
Even worse, how d''you do that with THREE angles?

---------------

I finally got it all together...
...and then forgot where I put it.
Advertisement
Hmm. You only need to use sin and cos when you have _one_ speed and an angle that the speed is heading along.

Since you have SpeedX and SpeedY variables, I think you''re mixing math in a way that''s not entirely kosher. Try replacing speedX and speedY with one ''Speed'' variable.
What are these X and Y variables? What do they represent?
WTF??? Erm, they represent a blue ice-cream and a red ice-cream. Sorry...

---------------

I finally got it all together...
...and then forgot where I put it.
cortision (did i spell that right?) coordinates as in a number pair on a map, basicly the location of the object
Advertisement
Try switching around the sin and cos - cos with X and sin with Y. This should get the car going in the opposite direction. Hope this helps!
You must have misunderstood my question.
You can''t rotate the object by rotating its "location" around a point. It would move the object in a circle, but not rotate it. As I understood, the goal was to actually rotate the object, so these X and Y values must present the vertex coordinates of the object. In this case these expressions are fundamentally wrong. First of all, sin() should change the Y value and cos() the X value. Secondly, the Speed[X/Y] variables in these expressions have the meaning of the rotation radius, so I don''t understand what kind of speed is meant by them. And thirdly, it is unclear from these expressions where does the pivot point lie.
The proper way to rotate an object''s vertices would be this :
X''=X0+(X-X0)*Cos(A)-(Y-Y0)*Sin(A)
Y''=Y0+(X-X0)*Sin(A)-(Y-Y0)*Cos(A)
Where :
X0 and Y0 are the pivot point''s coordinates.
X and Y are the object''s vertex coordinates(not rotated).
X'' and Y'' are the new vertex coordinates after applying rotation of angle A.
If you want to rotate your object around its origin(the pivot point is in 0,0) you can throw out X0 and Y0 :
X''=X*Cos(A)-Y*Sin(A)
Y''=X*Sin(A)-Y*Cos(A)
Rotating in 3d is slightly more complex.
But it beats me why don''t you use glRotatef(), if you use OpenGL ofcourse.
The last one was my post...

This topic is closed to new replies.

Advertisement