Skip to main content
gamedev.net
🔒 Locked

Rotation Problem?

Started by Phy Apr 9, 2005 at 6:58 PM 1 replies 450+ views
Original Post
Phy
Phy
Can someone tell me if theres anything wrong with this function? I'm getting weird results in game. Whenever I call it multiple times each frames, the first value is OK, but every one afterward is screwed up...

void CBaseWeapon::SpreadProjectile( Vertex3f *v, scalar spread )
{
	Vertex3f	vOut;
	vOut = v;
	scalar	c,s;
	scalar	pitch = randomf() * spread;
	scalar	roll = randomf() * 360;

	SinCos( DEG2RAD(pitch), &s, &c );
	Vertex3f vTemp = vOut;
	vOut.x = vTemp.x*c + vTemp.z*-s;
//	vOut.y = vTemp.y;
	vOut.z = vTemp.x*s + vTemp.z*c;

	SinCos( DEG2RAD(roll), &s, &c );
	vTemp = vOut;
	vOut.x = vTemp.x*c + vTemp.y*s;
	vOut.y = vTemp.x*-s + vTemp.y*c;
//	vOut.z = vTemp.z;

	*v = vOut;
}

oliii
oliii
assuming as you say that the first time is correct, make sure you don't pass the modified v again into the function at the next SpreadProjectile() call. Else you'll just be adding the error time and time again.
Everything is better with Metal.
hplus0603
hplus0603
I'm surprised that compiles. You assign "v" to "vOut" but vOut is a Vertex3f, and v is a Vertex3f*.

Also, you don't assign to vOut.y before you assingn vOut to vTemp; then you read vTemp.y, so vTemp.y will take the old value (from v), assuming the assignment in question works.

I'd suggest stepping through the function line by line and verifying the operation of the math against what you'd expect it to do. Conditional breakpoints, or break-at-Nth-time breakpoints, will help with this.
enum Bool { True, False, FileNotFound };

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.