Results 1 to 10 of 10

Thread: math questions

  1. #1
    Junior Member Newbie
    Join Date
    Mar 2002
    Posts
    22

    math questions

    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 = -
    - = TEFLON DRAGON = -

  2. #2
    Senior Member Regular Contributor
    Join Date
    Feb 2002
    Posts
    374

    Re: math questions

    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

    hih

  3. #3
    Senior Member Regular Contributor
    Join Date
    Sep 2000
    Location
    Vancouver BC Canada
    Posts
    417

    Re: math questions

    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.

  4. #4
    Senior Member Regular Contributor
    Join Date
    Feb 2002
    Posts
    374

    Re: math questions

    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

  5. #5
    Junior Member Newbie
    Join Date
    Mar 2002
    Posts
    22

    Re: math questions

    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 = -
    - = TEFLON DRAGON = -

  6. #6
    Senior Member Regular Contributor
    Join Date
    Feb 2002
    Posts
    374

    Re: math questions

    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).]

  7. #7
    Senior Member Regular Contributor
    Join Date
    Jan 2002
    Location
    Kingston, Jamaica, W.I.
    Posts
    282

    Re: math questions

    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.

  8. #8
    Senior Member Regular Contributor
    Join Date
    Sep 2000
    Location
    Vancouver BC Canada
    Posts
    417

    Re: math questions

    Originally posted by satan:
    and the resulting transposed vector looks like this:

    (x, y, z)*ten o'clock

    Har har.

    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).]

  9. #9
    Junior Member Newbie
    Join Date
    Mar 2002
    Posts
    22

    Re: math questions

    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

    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 = -
    - = TEFLON DRAGON = -

  10. #10
    Senior Member Regular Contributor
    Join Date
    Feb 2002
    Posts
    374

Similar Threads

  1. 3D math lib
    By glnoob_andre in forum OpenGL: General
    Replies: 3
    Last Post: 02-06-2012, 12:15 PM
  2. math
    By in forum OpenGL: Basic Coding
    Replies: 8
    Last Post: 04-10-2002, 05:18 AM
  3. Math
    By in forum OpenGL: Basic Coding
    Replies: 19
    Last Post: 07-14-2001, 08:02 PM
  4. math.h
    By caophong in forum OpenGL: Linux
    Replies: 1
    Last Post: 05-03-2001, 09:22 AM
  5. Help! What math do I need to do 3D ?
    By imported_newbie in forum OpenGL: Basic Coding
    Replies: 7
    Last Post: 10-11-2000, 08:56 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean