   Trigonometry (Direction of moving objects)
  I am stuck with the following problem:Suppose you have a gun which is defined by a position and a rotation in space. Now that gun shoots. How do I calculate in which direction the bullet should move based on the guns direction ?I tried playing around with the tan function to find out how much to add to a specified axis for moving in a given time and did this for all three axis. The code is somewhat embaressing (this is why I don''t show any snippets here ;-))My guess is, that there are some funky D3DX Matrix functions which do the job, but I am not that fit with those things, so is there anyone who can give me a hint?    LightBrain website relaunched, BomberFUN only USD 9.99visit http://www.lightbrain.de
  no funky features at all: the only thing you need to do is extract the last row/collum (not sure witch one) of the orientationmatrix of your gun into a vector: and voila, this is the vector pointing in the direction your bullet should be heading.  ;  You need to use or get into 3D Vectors. They solve problems with easy(sometimes) solutions.    "....If heaven was around the way.......a fiend who wants to get high, would he stop smoking? Knowing on his own two feet we could just stroll in......and escape from craziness and I bet you theres a heaven for an atheist." - Nasir *NaZ* Jones(courtesy of "God''s Son");  I hate it when this happens .. here it is 2am, I am tired, but I can''t sleep until I have a solution ;-)So what you are basically saying is, when I have an orientation matrix of my gun, then this matrix already contains the values, I need to set the correct speed (increment) for the bullet.Actually I don''t have an orientation matrix. But - as far as I recognize this - I have a general FrameMove method for the objects which does some heavy matrix calculation for scale, translate and rotate the objects. Looking at this, I find something like this:D3DXMatrixRotationYawPitchRoll( &mtrxMatrix, m_vct3Rotation.y, m_vct3Rotation.x, m_vct3Rotation.z );If I got it right, this is exactly what creates an orientation matrix, isn''t it? When I rotate my gun to x = -45 degree, y = -45 degree and z = 0 degree, then this function creates a matrix with (approximately) these values: 0.71  1.50  0.71  0.00 0.50  0.71 -0.50  0.00-0.50  0.71  0.50  0.00 0.00  0.00  0.00  1.00Soooo,... you think, that either -0.50 0.71 0.50 or 0.71 -0.50 0.50 represent the vector I need for the bullet?Actually the bullet does not move in the direction it is supposed to move to. No matter which one of the above vectors I use. But that could also be a result of the fact, that the guns'' barrel has an own different basic orientation. So I am going to evaluate this further tomorr, .. erm, .. later this day. ;-)So am I on the right track? LightBrain website relaunched, BomberFUN only USD 9.99visit http://www.lightbrain.de;  yeah you are on the right track. note thoug that i cant really  tell witch row/collum you should have either: it depends on the gunmodel youre using. i only assumed that the gun was modelled so that the barrel is pointing down the z-axis, witch is represented by this third row/col. if you find your bullets shooting out of the trigger or the sides of your gun, you should try fireing your bullet along another axis.besides that... your gun probably isnt positioned in worldspace, is it? more likely its in some subspace of you character model.. ive never worked with dx, so i dont know how to do it, but you need to extract the values of the matrix in worldspace, ie after your matrices have been transformed, unless you plan to fire your bullet in gunspace, witch i doubt.anyway, i suppose you need to extract the values after your matrices have been transformed to worldspace: if theres no obvious way to do this in dx, then you need to multiply the orientationmatrix of you gun with the matrices of all its parent spaces, ie the arm of your character and then with the matrix of the character itself for example.eh well you should get an answer from someone who has worked with dx, my answers are pretty useless i suppose..  ;  You say that your gun is defined by a position and rotation in space. Do you reoresent your rotation with a matrix, or just with a couple of angles?I''ll assume anges. I''ll assume that the y-axis is up, that the variable for the angle along the xz plane is called "angle" and the angle that the gun is pointed upwards is called "pitch".the formula to calculate the bullet''s velocity is as follows:speed * ( cos(angle)*cos(pitch), sin(pitch), sin(angle)*cos(pitch) )the bullet''s position will start out as that of the gun.if the gun is moving, you may wish to add the gun''s velocity to that of the bullet, for added realism. if you want to be really realistic, then you can also apply the mementum conservation law to simulate recoil  ;  Here''s another way to do this:Create a vector that points in the same direction as your weapon.E.g of your weapon model by default points forwards, you vector might be 0, 0, 1Now, to determine in what direction your bullet must go, simply rotate this vector by the same world transformation matrix used to rotate your weapon model.;  I thought about all of your ideas and will keep things like recoil in mind for further development.For now I decided to use an orientation vector that points into the direction of the gun and transform it each time, the gun is transformed, like Jaco suggested. And it works ;-)Thanks for your time,TroneX    LightBrain website relaunched, BomberFUN only USD 9.99visit http://www.lightbrain.de