Jump to content
  • Advertisement
Sign in to follow this  

vector rotation

This topic is 5230 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

i need some help with rotating a 3D normal vector with nothing but three different angles. im still working on my particle system and im trying to find a way to rotate the emitter without rotating the particles that have already been emitted (ie glRotate). make sense? ive tried using the complex matrix thats used in glRotate but i cant get it to work. ive tried this too but the particle spread doesnt work.
                        float sp = rand()%(int)floor(speedVar);
			sp = speed - sp;

			//random angle
			float xy = rand()%(int)spread-(spread*0.5);	//angle on XY plane
			float zy = rand()%(int)spread-(spread*0.5);	//angle on ZY plane

			float x = sin(xy*PIOVER180);
			float y = cos(xy*PIOVER180);
			float z = sin(zy*PIOVER180);

			x = x;
			y = sin(emitRot.x);
			z = cos(emitRot.x);
			x = cos(emitRot.y);
			y = y;
			z = sin(emitRot.y);
			x = cos(emitRot.z);
			y = sin(emitRot.z);
			z = z;

			Vector3 vect = Normalize(x, y, z);

			pArray[part].dir.x = vect.x * sp;
			pArray[part].dir.y = vect.y * sp;
			pArray[part].dir.z = vect.z * sp;

Share this post

Link to post
Share on other sites
maybe i'm confused but it looks to me like you are reassigning the x, y, and z values 3 times. the only x, y, and z values that are getting normalized are the last ones. What i mean is that in this code block, x will always be cos(emitRot.z), y will always be sin(emitRot.z), and z will always be assigned to its original value, sin(zy*PIOVER180). This may be part of your problem, but i may just be confused as to what you are trying to show here.

Share this post

Link to post
Share on other sites
wow duh i cant believe i did that, rotating the values only around the z-axis.

essentially what im trying to do is rotate the emitter around an axis (x, y, or z). all the user has to do is supply 3 angles that they want to rotate for example:

i want to rotate the emitter 45 degrees around the z-axis rotate(0, 0, 45)
and then i want to rotate the emitter 90 degrees around the y-axis rotate(0, 90, 0)

im not entirely sure of how to acheive this. im still kinda new to matrix rotations

Share this post

Link to post
Share on other sites
The simplest way to rotate 3d vector is to multiply it by rotation matrix.
Let rotation matrix (3x3) is M, and vector we want to rotate is V, then rotated vector is given by

Now, on angles. Your angles is very much like Euler angles. You can use euler angles-to-matrix to deal with that.
Also, you can look for axis-and-angle to matrix conversion. Then, you can do:
Matrix3x3 M=AxisAngleToMatrix(0,1,0,y_angle);

Then you can multiply your vectors by this matrix to transform 'em.

It's the same as
glRotate(y_angle,0,1,0);// replaces current matrix M with M*AxisAngleToMatrix(0,1,0,y_angle);
glRotate(z_angle,0,0,1);// replaces current matrix M with M*AxisAngleToMatrix(0,0,z,z_angle);
, just assuming you start with identity.

So, when firing a particle, you can first compute particle_pos and particle_velocity, and then multiply it with that matrix. Like that:
(That's assuming particles start in local origin, of course)
Other particles will not be affected.

It's critical to learn matrices if you want to program such things, and particles is good example

Share this post

Link to post
Share on other sites
Dmytry-> im a little lost. i understand the function calls but im missing the math. ive tried changing it a little with this:

float x = sin(xy*PIOVER180) + x + cos(emitRot.y) + cos(emitRot.z);
float y = cos(xy*PIOVER180) + sin(emitRot.x) + y + sin(emitRot.z);
float z = sin(zy*PIOVER180) + cos(emitRot.x) + sin(emitRot.z) + z;

it gives me some STRANGE effects. its as if its trying to rotate on all of the axises

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!