Advertisement

Question About Moving A Vector in 3d Space

Started by August 04, 2000 05:26 PM
15 comments, last by TipTup 24 years, 2 months ago
I have a function where I pass a vector to it, and the distance (speed) it should travel using the direction the vector is pointing in. My problem is when the vector is inverted like if you were performing a backflip the z change is not accurate, you fly backwards until your not inverted.
        
	GLfloat xc =(GLfloat)gs*(GLfloat)(speed)*(GLfloat)sin(vector.yrot*PI/180);
	GLfloat xc2 = (GLfloat)gs*(GLfloat)(speed)*(GLfloat)sin((vector.xrot)*PI/180);

	GLfloat yc=(GLfloat)gs*(GLfloat)(speed)*(GLfloat)sin(vector.xrot*PI/180);
	GLfloat yc2 = (GLfloat)gs*(GLfloat)(speed)*(GLfloat)sin((vector.xrot)*PI/180);

	GLfloat zc=(GLfloat)gs*(GLfloat)(speed)*(GLfloat)sin((vector.yrot-90)*PI/180);
	GLfloat zc2 = (GLfloat)gs*(GLfloat)(speed)*(GLfloat)sin((vector.xrot)*PI/180);
	vector.x-=xc;//+xc2;

	vector.y+=yc+yc2;
	vector.z+=zc+zc2;

[/source]

all of the preceding code works except the zc2 line. (If you dont know what the bug is creating try flying inverted in Space Wars, you'll fly backwards. hehe.

Here is the code I'm using for my vector:

[source]

typedef struct vector {
	GLfloat x,y,z,xrot,yrot,zrot;
}vector;

    
any ideas on how to fix the zc2 line? I dont know any 3d math at all, all the code was either created using a little 2d math or with trial and error. lol Thanks, -TipTup TipTup.Com
Edited by - TipTup on 8/4/00 5:27:47 PM
oh and GS is a float i made which slows or speeds up the game based on fps.

-TipTup
TipTup.Com
Advertisement
hey tiptup, you''re a dumbass why did you divide PI by 180 in your code you should have just put the number that it equals instead doing extra calculations which will be slower.

p.s. Space Wars sucks dick bitch!
Sorry, TipTup, I''m a trial and error kinda guy myself, so I don''t really have an answer to your question as I haven''t yet tried it, but these anonymous posters (actually, it''s probably just the same one) are getting on my nerves, this forum should only allow registered users so we atleast know who they are.

Morgan
hey TipTup, nor do i have the solution to your problem, but i am totally agreeing with what Morgan is saying. good luck with your code, and perhaps, i'll give it a shot now....

=)

oh, and btw, i'm very capable of showing such displays of inappropriate behavior as anonymous posters, but feel that the immaturity is just unnecessary and discouraging. this post definitely was not the first thought that runs through my mind when i read such garbage. sometimes, i just want to respond to such immaturity with twice the fire, but feel that it won't solve anything. of course you guys know that already, except for gutless anonymous posters.

but to counter that putdown with a putup, i understand the reasoning by using pi/180, for clarity's sake. later in the coding process, you can optimize the code with the constant that anonymous poster has "suggested."

a2k

take 2

okay, and to answer your question with my version, i don't think it can be fixed. i think i was making the same mistake when i was learning 3d math. uh, i'm afraid you're going to have to learn matrices. that's the way everybody's doing it. (well, there's something called quaternions that you'll just LOVE once you get the matrices figured out, but save that for later. learn matrices! there are a buncha articles that cover it, but i think the Quaternion FAQ has lots of what you need to get started. dig deeper. 3d rotations are a bitch, kinda like that anonymous poster.

a2k

Edited by - a2k on August 4, 2000 12:42:13 AM
------------------General Equation, this is Private Function reporting for duty, sir!a2k
i changed it to a constant minutes after posting, and I know who that guy is anyways, hes a dumb@$$ who went to school with me and failed the same class i took cuz he didnt turn anything in.

-TipTup
TipTup.Com
Advertisement
whats strange is I know that the code I''m using now i can fix, I''m just not doing it right...........

-TipTup
TipTup.Com
well, i hope it works, cuz this could be the big matrix-beater. see, when i was trying this, whenever i wanted to do a loopdeloop, it wouldn''t do it. the 3rd dimension would either shoot into infinity or just act like another sine wave. (my ship turned, but it was pretty much moving in a sinusoidal fashion) hopefully the way you''re doing it, it''ll work... we''ll see. good luck.

a2k
------------------General Equation, this is Private Function reporting for duty, sir!a2k
i bet you when I figure it out its going to be something stupid like -result, lol


-TipTup
TipTup.Com
hey, tiptup. don''t listen to mr anonymous. I take it PI is a constant, yes? in that case; if you divide a constant with another constant in your code, it will end up as one constant (NOT a divison) in the executable.

so, mr. penis envy is not only tactless -- he''s also dead wrong.

This topic is closed to new replies.

Advertisement