
Rotate Model in RenderMonkey
bpurnomo Dec 17, 2008 2:28 PM (in response to latheesan)Hi,
Please keep in mind RenderMonkey is not designed to perform the tasks you outlined above (you would need a modeling tool). To place an object in your environment, you would have to add a transformation matrix to the rendering pass and perform the transformation in the vertex shader. The alternative would be to pretransform your object before you load it to RenderMonkey (this would be better).

Rotate Model in RenderMonkey
jhejl Jan 31, 2009 5:20 AM (in response to bpurnomo)Hi latheesan,
It's been a month  probably too late on this answer. Sorry, I don't visit often enough.
The model you got was created with the art package configred "Z up". Rendermonkey is a "Y up" space. The correct thing to do is to use Max, and rotate the 3ds by 90 degrees about X  transforming it into Yupspace.
You said you downloaded the mesh, so I'm assuming you might not have access to the art package itself. In the vertex shader, you need to do the same thing: a rotation of 90 degrees about X
So, a new func for you
inline float3 Rotate90x(float3 v)
{
const float rTheta = Degree2Radian(90.0);float cosTheta = cos(rTheta);
float sinTheta = sin(rTheta);// build 90 degree rotation about X "by hand"
float3x3 M = float3x3( 1, 0, 0,
0, cosTheta, sinTheta,
0, sinTheta, cosTheta );
return (mul(v,M));
}Just FYI on the matrix math above:
The default compiler settings in RM will convert this matrix to rowmajor for us.
This allows mul() the correct way (vector * Matrix), and the codegen of
dp4 dp4 dp4. Without this behindthescenes transpose, the code would need to be written
as mul(M,v), (and the codegen would be mad mad mad). Not terribly important to this topic;
but it's always good to know when automatic "help" is being applied on the backendAnyway, we know that we want a constant 90 degree rotation (never more, never less).
So, let's bake out the trig results:inline float3 Rotate90x(float3 v)
{
float cosTheta = 0; //cos((PI/180.0)*90.0)==0
float sinTheta = 1; // sin((PI/180.0)*90.0)==1// plugging knowns into our rotation:
float3x3 M = float3x3( 1, 0, 0,
0, 0, 1,
0, 1, 0 );
return (mul(v,M));
}With the trig gone, we just have those dot products.
The dots simplify out to:inline float3 Rotate90x(float3 v) { return (float3(v.x,v.z,v.y)); }
So, that's it. A swizzle.
You want to do this rotation with the model in local space (BEFORE any other transforms).
The same rotation also needs to be applied to the vertex normal, and other data that you have in the Zup space, if any.Your final shader code would look something like,
inline float3 Rotate90x(float3 v) { return (float3(v.x,v.z,v.y)); }
VS_OUT main(float4 P : POSITION, float3 N : NORMAL, float2 uv :TEXCOORD0)
{
// Our mesh is Zup, Rendermonkey is Yup
// Rotate mesh into Yup localspace
Pos.xyz=Rotate90x(Pos.xyz);
N.xyz=Rotate90x(N.xyz);... proceed with shader as normal ...
With this, you can use Zup models in Rendermonkey. Done and done.
Cheers,
Jim Hejl (jim AT hejl DOT com)
EA
