Calculating object rotation on a slope
#1

I'm writing some code that will calculate the RX, RY of a slope then apply those values to an object so that it will have the same rotation based on the slope. So here is the deal it works perfectly when the object has a Z Rotation at 0.0 but i'm looking for a way to get the correct RX, RY values when the Z Rotation is set to some other value. I'm not the greatest of math guys so I'm hoping someone might have a solution here is the code so far it uses MapAndreas to find the ZHeight to the north, south, east, west of the object center then uses some basic trig to get the slope angle.

Код:
		new Float:North[3], Float:South[3], Float:East[3], Float:West[3], Float:RXAngle, Float:RYAngle, Float:opposite, Float:hypotenuse;

		// Set slope positions
		North[0] = objects[ox];
		North[1] = objects[oy] + 1;

		South[0] = objects[ox];
		South[1] = objects[oy] - 1;

		East[0] = objects[ox] + 1;
		East[1] = objects[oy];

		West[0] = objects[ox] - 1;
		West[1] = objects[oy];

		// Use map andreas to get Z Values
		MapAndreas_FindZ_For2DCoord(North[0], North[1], North[2]);
		MapAndreas_FindZ_For2DCoord(South[0], South[1], South[2]);
		MapAndreas_FindZ_For2DCoord(East[0], East[1], East[2]);
		MapAndreas_FindZ_For2DCoord(West[0], West[1], West[2]);

		// Calculate Slope angles
		// North South RX
		hypotenuse = getdist3d(North[0], North[1], North[2], South[0], South[1], South[2]);
		opposite = getdist3d(North[0], North[1], North[2], North[0], North[1], South[2]);

		RXAngle = asin(floatdiv(opposite, hypotenuse));
		if(South[2] > North[2]) RXAngle *= -1;

		// West East RY
		hypotenuse = getdist3d(West[0], West[1], West[2], East[0], East[1], East[2]);
		opposite = getdist3d(West[0], West[1], West[2], West[0], West[1], East[2]);

		RYAngle = asin(floatdiv(opposite, hypotenuse));
		if(East[2] > West[2]) RYAngle *= -1;

		// Set object rotation
		objects[rx] = RXAngle;
		objects[ry] = RYAngle;
		
		SetObjectRot(objects[object_id], objects[rx], objects[ry], objects[rz]);
As can be seen there is no code for generating the correct rotation based on RZ rotation any ideas here?
Reply


Messages In This Thread
Calculating object rotation on a slope (SOLVED) - Thank-you YJIET - by Pottus - 13.03.2013, 03:49
Re: Calculating object rotation on a slope - by mastermax7777 - 13.03.2013, 03:57
Re: Calculating object rotation on a slope - by Pottus - 13.03.2013, 04:09
Re: Calculating object rotation on a slope - by Threshold - 13.03.2013, 08:10
Re: Calculating object rotation on a slope - by RajatPawar - 13.03.2013, 08:13
Re: Calculating object rotation on a slope - by MP2 - 13.03.2013, 08:33
Re: Calculating object rotation on a slope - by Pottus - 13.03.2013, 13:59
Re: Calculating object rotation on a slope - by Pottus - 13.03.2013, 14:17
Re: Calculating object rotation on a slope - by Stylock - 13.03.2013, 16:25
Re: Calculating object rotation on a slope - by Pottus - 13.03.2013, 16:35

Forum Jump:


Users browsing this thread: 1 Guest(s)