View Full Version : math questions

teflon_dragon

04-24-2002, 11:30 AM

Hey everybody, it's me again. I've been experimenting a lot with OGL now, and while I'm learning some cool stuff I still can't get the desired results. I'm sure my problem lies in the math (which I know less than I do OGL! lol)

Okay, I have my little triangle I want to be able to move through space. Up / Down arrows change the pitch and left / right arrows change the yaw. RShift / RControl move it forward and backwards respectively. If, for example, the "craft" starts out at 0, 0, 0 (xyz), how do I :

(a. figure out it's heading mathematically

(b. when it is moved forwards or backwards, how do I determine what it's new X, y, and z coordinates will be depending on which way it's moving?

This problem has been plaguing me forever!! aah!! Thanks in advance!

- = TEFLON DRAGON = -

satan

04-24-2002, 12:00 PM

i recommend a search on google for vector/matrix math

sorry for not being more specific but you have to do it anyway if you wanne do 3d graphics and it's late and i am tired http://www.opengl.org/discussion_boards/ubb/smile.gif

hih

For a), all you've specified is a position. It's heading could be anything.

For b):

Let v be a vector describing the direction in which it is moving. Then:

x += (velocity * v.x) * time;

y += (velocity * v.y) * time;

z += (velocity * v.z) * time;

will update its position.

satan

04-24-2002, 10:36 PM

Originally posted by rts:

x += (velocity * v.x) * time;

y += (velocity * v.y) * time;

z += (velocity * v.z) * time;

and the resulting transposed vector looks like this:

(x, y, z)*ten o'clock http://www.opengl.org/discussion_boards/ubb/wink.gif

teflon_dragon

04-25-2002, 02:09 AM

Hey many thanks! This math stuff is killing me, but it is a must.

rts: You said for (a., let v be a vector ..

how do I get this vector? ( I assume it's a formula of sorts )

and satan: is there a difference between a vector and a transposed vector? and why do you have to multiply x, y, and z by direction .. I thought that was what V would be?

Thanks again for everything!

- = TEFLON DRAGON = -

satan

04-25-2002, 03:10 AM

first of all my last post was a little joke based on rts usage of the variable time

so what rts was trying to tell you is that your first question cannot be answered like you want it to be

meaning: if you just have a point (0,0,0) in your example, you can't get a heading

for this you need two points, or point and two angles or ...

to your second question rts answered that you shall use a vector (called v) which stores the direction in which your craft shall move

then multiply every component of this vector with the velocity and a timer (for fps independent movement) and add the result to your crafts position

to the transposed vector:

i learned in math that a vector looks like this

x

y

z

if you transpose it, it looks like this

x,y,z

that's it

since you seem not to have the basic understanding of vector math you SHOULD really look for some resource on the net, because you need it all the time and i am not sure if our answers will help you to solve your problem (although rts was totally right with what he told you to do - and btw it was explained quite clear i think)

[This message has been edited by satan (edited 04-25-2002).]

Furrage

04-25-2002, 06:17 AM

v is a unit vector (i.e sqrt(v.z^2 + v.y^2 + v.z^2) = 1). An easy way to create it is to define v as v(0, 1, 0) which points north, depending on the orientation of your co-ordinate system. Then you can rotate it using any pitch or yaw you want. Note, since it is a float or double you get rounding errors after each rotate. I've found that this becomes significant after ~5000 rotations for doubles, so you will need to normalise your vector after it's been rotated a couple of times.

velocity is the speed of your object.

time is the time interval that has past since the object last moved. So you when you move note the current time, then the next time you move subtract the noted time from the current time to get the interval. Do this once per frame instead of once per object.

Check the web for maths tutorials. This is essential.

Originally posted by satan:

and the resulting transposed vector looks like this:

(x, y, z)*ten o'clock http://www.opengl.org/discussion_boards/ubb/wink.gif

Har har. http://www.opengl.org/discussion_boards/ubb/smile.gif

I guess I should have made it a little more clear that "time" is really "elapsed time since last update".

Anyway, I have a very simple flying demo that demonstrates all of this in pretty straightforward C code. I'll clean it up and post it on my website over the weekend (http://members.shaw.ca/ryants). If you don't see it, send me a reminder (my e-mail address can be had from my profile info).

[This message has been edited by rts (edited 04-25-2002).]

teflon_dragon

04-26-2002, 11:26 PM

Hey, thanks again for all your help. Now obviously I'm not a math whiz here so try not to laugh _too_ hard when you see this code http://www.opengl.org/discussion_boards/ubb/smile.gif

if(GetAsyncKeyState(VK_RSHIFT)) {

x -= sin(pitchx/piover180);

y -= cos(rolly/piover180);

z -= tan(headingz/piover180);

}

Theoretically (and I use the term loosely) this would drive my ship forward in the direction it is pointing, but this code makes my ship go all kinds of crazy direction wise.

Any recommendations? Thanks again in advance,

- = TEFLON DRAGON = -

satan

04-27-2002, 03:01 AM

http://www.geocities.com/SiliconValley/2151/math3d.html

Powered by vBulletin® Version 4.2.2 Copyright © 2014 vBulletin Solutions, Inc. All rights reserved.