cancel
Showing results for 
Search instead for 
Did you mean: 

Archives Discussions

latheesan
Journeyman III

Rotate Model in RenderMonkey

How do i rotate a model in RenderMonkey

Hello,

I was given an assignment to create a 3D complete Kitchen in RenderMonkey and i am stuck with a very simple problem.

I imported a Fridge model i downloaded (3ds format) from some website and i tried everything I knew to make it stand up. I have failed. Take a look at this screenshot :

http://i33.tinypic.com/2laes95.png

How do you make rotate the model upwards, so i can position/scale it in the corner somewhere in my kitchen?

Thanks in advance for any help.

 

0 Likes
2 Replies
bpurnomo
Staff

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).

 

0 Likes

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 Y-up-space.

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 row-major for us.
This allows mul() the correct way (vector * Matrix), and the codegen of
dp4 dp4 dp4. Without this behind-the-scenes 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 backend

Anyway, 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 Z-up 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 Z-up, Rendermonkey is Y-up
    // Rotate mesh into Y-up local-space

   Pos.xyz=Rotate90x(Pos.xyz);
   N.xyz=Rotate90x(N.xyz);

    ... proceed with shader as normal ...

With this, you can use Z-up models in Rendermonkey. Done and done.

Cheers,
Jim Hejl (jim AT hejl DOT com)
EA

0 Likes