Rotational axis? for movement of ball

Started by
12 comments, last by MARS_999 14 years, 10 months ago
Does velocity represent angular velocity? What does playerDir represent? Is it an angle? Also, where does the angle variable come from? (The lack of context makes it a bit difficult to make sense of the code, IMO.)

As for the 'rotate' functions, they should really set every element of the matrix to the appropriate value, rather than making assumptions about the previous state of the matrix (IMO). Also, I don't see you setting the matrix to identity anywhere in your code - are you sure it's set to identity before the rotation functions are called? Are you setting the matrix to identity and then making multiple calls to the rotation functions with the expectation that the rotations will accumulate in some way?
Advertisement
Quote:Original post by jyk
Does velocity represent angular velocity? What does playerDir represent? Is it an angle? Also, where does the angle variable come from? (The lack of context makes it a bit difficult to make sense of the code, IMO.)

As for the 'rotate' functions, they should really set every element of the matrix to the appropriate value, rather than making assumptions about the previous state of the matrix (IMO). Also, I don't see you setting the matrix to identity anywhere in your code - are you sure it's set to identity before the rotation functions are called? Are you setting the matrix to identity and then making multiple calls to the rotation functions with the expectation that the rotations will accumulate in some way?


I haven't made it represent nothing, as I just wanted to ball to move and look correct never was concerned with realistic movements or simulations on the ball. So velocity is just another name for speed...


Yes, I am calling Identity() and I changed the velocity to speed to clear up this isn't a vector I am using and starting to think I need a vector for my fwd movement and side to side to get this to work????

//Draw Player	scaleMatrix.Identity();	rotMatrix.Identity();	matrix.Identity();	glPushMatrix();			if(playerRight || playerLeft)		{			rotMatrix.ArbitraryRotation(NX::MATH::DegToRad(angle) * speedClamped, 1, 1, 1);//			rotMatrix.RotateX(NX::MATH::DegToRad(angle) * speedClamped * .1f);		}		else		{			rotMatrix.ArbitraryRotation(NX::MATH::DegToRad(angle) * speed, 1, 1, 1);//			rotMatrix.RotateX(NX::MATH::DegToRad(angle) * speed * .001f);		}				scaleMatrix.Scale(playerScale, playerScale, playerScale, true, true, true);		playerPos = playerTransformMatrix & NX::MATH::vec3<float>(0.0f, 0.0f, playerDir);		matrix.Translate(playerPos);		playerSphere.UpdateCenter(matrix);		matrix *=scaleMatrix;		matrix *=rotMatrix;		glMultMatrixf(matrix.matrix);		DrawBall();	glPopMatrix();
I can understand how to use ArbitraryRotation() with only one angle and one 'true', like it was in the first post. But I think it can't be used with 3 'true/1'. What's it gonna do, rotate around x, then y, then z by angle radian ?

Why don't you just use 3 rotation matrices like this ?
Matrix4 rotX, rotY, rotZ, rotYXZ;rotX.SetRotationX(angle_x);rotY.SetRotationY(angle_y);rotZ.SetRotationZ(angle_z);rotXYZ = rotX * rotY * rotZ; // or rather rotY * rotX * rotZ;


Then if you want, you can code a RotateXYZ functions that takes 3 angles (and no bool, an angle of 0 is enough) and makes rotXYZ without intermediary matrices, but at least it's more clear what the resulting matrix is. Note that you probably don't need the rotY matrix since you only need to go forward and on the side.
Quote:Original post by KOzymandias
I can understand how to use ArbitraryRotation() with only one angle and one 'true', like it was in the first post. But I think it can't be used with 3 'true/1'. What's it gonna do, rotate around x, then y, then z by angle radian ?

Why don't you just use 3 rotation matrices like this ?
*** Source Snippet Removed ***

Then if you want, you can code a RotateXYZ functions that takes 3 angles (and no bool, an angle of 0 is enough) and makes rotXYZ without intermediary matrices, but at least it's more clear what the resulting matrix is. Note that you probably don't need the rotY matrix since you only need to go forward and on the side.


I will try it later, but will this solve my issue at hand with the ball rotating correctly when moving side to side and side+fwd?

This topic is closed to new replies.

Advertisement