Tracking a point on a model

Started by
13 comments, last by Steelrose 20 years, 7 months ago
I don''t think it''s gonna work very well. I''ll post some code so you can take a look.

bool FireWeapon(void){	ACTOR *newshot;	newshot = new ACTOR;	newshot->worldPos = player->worldPos;    //get players position	newshot->rot = player->rot;    //get players rotation	newshot->rightVector = player->rightVector;     //get players right hand vector	newshot->upVector = player->upVector;     //get players up hand vector	newshot->rotation = player->rotation;     //get players rotation stored as QUATERNION	newshot->directionVector = player->directionVector;     //get players foward vector	switch(player->typeshot)	{		case SHOT1:			newshot->type = Weapon1.type;	//Set the actor type			newshot->typeshot = Weapon1.typeshot; //Set the shot type			newshot->active = Weapon1.active; //Activate the actor			newshot->radius = Weapon1.radius; //Set the actors radius			newshot->mass = Weapon1.mass; //Calculate the actors mass			newshot->normalMaxVelocity = Weapon1.normalMaxVelocity;			newshot->currentMaxVelocity = Weapon1.currentMaxVelocity; //Setup the max velocities			newshot->forward = Weapon1.forward;			newshot->damage = Weapon1.damage;			newshot->lifeTime = Weapon1.lifeTime;			newshot->rechargeTime = Weapon1.rechargeTime;			break;		case SHOT2:			newshot->type = Weapon2.type;	//Set the actor type			newshot->typeshot = Weapon2.typeshot; //Set the shot type			newshot->active = Weapon2.active; //Activate the actor			newshot->radius = Weapon2.radius; //Set the actors radius			newshot->mass = Weapon2.mass; //Calculate the actors mass			newshot->normalMaxVelocity = Weapon2.normalMaxVelocity;			newshot->currentMaxVelocity = Weapon2.currentMaxVelocity; //Setup the max velocities			newshot->forward = Weapon2.forward;			newshot->damage = Weapon2.damage;			newshot->lifeTime = Weapon2.lifeTime;			newshot->rechargeTime = Weapon2.rechargeTime;			break;		default:			break;	}	ShotList.Append(newshot);		return true;}


Everything in stored in classes. This bit is called when the player presses the fire key on the keyboard. Weapon1 and Weapon2 are predefined elsewhere in the program. This bit just takes data from the player and sets up the location. Then depending on the weapon fired, takes and copies data from the predefined weapon. After all this is done, it places the data into a linked list that I have written to I can access and manipulate the data. This is where I need to move the shot to the gunport.

I tried using the glPushMatrix and glPopMatrix but it doesn''t seem to work in this portion of the program. I know I am missing something but I can''t figure out what.
Dreams arn't just dreams, They're a whole new world to play in.
Advertisement
quote:Original post by Steelrose
I don''t think it''s gonna work very well. I''ll post some code so you can take a look.


Does this mean that it doesn''t work or that you haven''t tried? What I described is trivial translation theory. If the projectile isn''t spawned at the correct position it''s either because you''re not doing everything correctly (the source code you posted is pretty irrelevant to thatr particular problem), you''re not stating your problem correctly or you''re building off of incorrect information.

If you''re having a specific problem, describing it in more detail will end up benefiting everyone.
"Literally, it means that Bob is everything you can think of, but not dead; i.e., Bob is a purple-spotted, yellow-striped bumblebee/dragon/pterodactyl hybrid with a voracious addiction to Twix candy bars, but not dead."- kSquared
Yes I have tried to get the translation to work correctly using push and pop and no it didn't work. if you will recall:

/*
I tried using the glPushMatrix and glPopMatrix but it doesn't seem to work in this portion of the program. I know I am missing something but I can't figure out what.
*/

Now I will try to explain the problem in more detail.
The ship apperently has an xyz axis that is aligned with the world xyz axis. translating the gunport translates it on this axis. Therefore when I rotate the craft the gunport is translated on that axis and not on the direction vector of the ship. In other words, a shot that is supposed to fire from the right of the ship fires from the left when you rotate 180 degrees on the y axis.

Edit:
Just thought of a bit of data I left out. The shots and ships are rendered at different times. First the ships then in a seperate function, the shots. The shots are created and placed into a linked list and when the time comes to draw them, the program goes through the list and draws them after checking for collision and translating and so-forth.

[edited by - Steelrose on September 3, 2003 2:26:59 PM]
Dreams arn't just dreams, They're a whole new world to play in.
Hmm - I think you''re confused about something (and now you''re getting me slightly confused ).

Anyway, let''s start with the more trivial stuff: you can''t have an xyz axis. x, y and z are separate axes by themselves, if you pair them you get a plane (as in xz plane, xy plane) and all together they form a 3D space.

It seems to me you''re not applying the ship''s rotation after you translate to its origin, but that can''t really be the problem. Make sure you''re not applying any other rotations between drawing the ship and the projectiles - if you do, you''ll need to encapsulate these with respective glPushMatrix() and glPopMatrix() calls as well; if you get your code working, do your best to remove as many of these calls as possible, though - it will only be good for the performance). I can''t really tell from your description, but you could also be experiencing Gimbal lock - don''t use right angles and stuff in your rotations to be sure.

If all else fails, try creating an empty scene (just comment out all other code), place the ship at the world origin, allow it to rotate (but not move) and try to get the projectile position right. Then, when you''re sure it works, add all kinds of translation and gunport rotation (if you wish) stuff. I think you have a bug in your code that you''re not aware of. If you can''t tell where it is, start commenting out portions of code - it that''s the most effective method.
"Literally, it means that Bob is everything you can think of, but not dead; i.e., Bob is a purple-spotted, yellow-striped bumblebee/dragon/pterodactyl hybrid with a voracious addiction to Twix candy bars, but not dead."- kSquared
Well I am happy to say I figured out what the hell I was doing wrong. And the solution was suprisingly easy.

To give a quick sum up. In the code I had posted above I (finally) noticed that I had vectors for up, right, and forward. I realized that I had the axis for the shot right there. So I multiplied the x,y,z of the shot location with the correct vector and bingo, works like a charm.

And in case anyone was wondering, I am using Trent''s 3d space code for the basis of my own program.

Thanks to those who gave help in any way. Turns out you wern''t wrong, I just described the problem wrong.
Dreams arn't just dreams, They're a whole new world to play in.

This topic is closed to new replies.

Advertisement