Rotate an object using a vertex shader

Is it possible to rotate an object using vertex shader code. I know you can position and scale it but cant work out how to rotate it.


Thanks


Bilbob


Answer this question

Rotate an object using a vertex shader

  • Jonas Bergman

    I must confess that I am not a RenderMonkey expert. But if you want to move your object in the preview window around with the mouse you should use ViewProjection or WorldViewProjection as semantic.

  • Jaypee

    Thanks Ralf.

    I have got it to rotate which is excellent.

    But what ive done is, im using rendermonkey and have created a new 4x4 matrix but not given it a semantic, and have hard coded in the values to rotate it 45 degrees.

    This works but is there a semantic i can apply to the matrix so i dont need to hard code in the variables or is there generally a better more flexible way of doing it

    Thank you

    stuart

  • Luke Waters

    To rotate an object you will need a rotation transform matrix. Set this matrix as constant value for the vertex shader. In the vertex shader you have to multiply your vertex position with this matrix. You can do all your translation and scaling with a matrix, too. If you multiply all your matrixes with the CPU and then send only the result to the vertex shader you can translate, scale and rotate with only one vector matrix multiplication.

    You can read more about transform matrixes in the Direct3D documentation: http://msdn.microsoft.com/library/en-us/directx9_c/Transforms.asp frame=true


  • Rotate an object using a vertex shader