well first of all i'm new in this forum and i think is great!.

now, i'm trying to do a DirectX program that moves a plane in a 3D scene, it's very basic what i wanna do but i'm having some problems: i don't know how to make coherent the plane rotation (or direction) with its movement, actually i made a procedure that rotates the x, y and z axis of a vertex buffer by trigonometry, but my problem is, for example, if i have PI radians of rotation in the x axis the plane is supposed to go backwards but i have to count the y axis rotation too which changes the z position as well, and suppose it's zero (the y rotation) then it'd counteract with the x rotation and the plane will stand still, so that's my first and main problem and my other little problem is how to create a light bulb-like light, i tried to create a point light but it looks very fake!

well if someone can help me or tell me an other way to do those things i'd be very grateful :alright:

thanks

now, i'm trying to do a DirectX program that moves a plane in a 3D scene, it's very basic what i wanna do but i'm having some problems: i don't know how to make coherent the plane rotation (or direction) with its movement, actually i made a procedure that rotates the x, y and z axis of a vertex buffer by trigonometry, but my problem is, for example, if i have PI radians of rotation in the x axis the plane is supposed to go backwards but i have to count the y axis rotation too which changes the z position as well, and suppose it's zero (the y rotation) then it'd counteract with the x rotation and the plane will stand still, so that's my first and main problem and my other little problem is how to create a light bulb-like light, i tried to create a point light but it looks very fake!

well if someone can help me or tell me an other way to do those things i'd be very grateful :alright:

thanks

You like to do things the hard way :)

Why not use a Mesh object and let DX handle the dirty work?

Why not use a Mesh object and let DX handle the dirty work?

for rotating you'll need quaternions. i have a copy of a webpage that went down, see attachment.

for the lightbulb: well, just play with the properties of the pointlight (attenuation0 and such).

good luck!

for the lightbulb: well, just play with the properties of the pointlight (attenuation0 and such).

good luck!

thank you guys for the replies :)

thanks :alright:

Why not use a Mesh object and let DX handle the dirty work?

well actually i'm loading a mesh from a *.x file, first i call the D3DXLoadMeshFromX function and then i load each material and each texture, and finally i get the vertex buffer from the D3DXMesh obj, so i guess i can use the method you said....but i dunno how nor which is, would you please show me how??
for rotating you'll need quaternions.

well i didn't understand very well how to use "quaternions"...
for the lightbulb: well, just play with the properties of the pointlight (attenuation0 and such).

well i guess that's what i have to do with lights, so thanks for the advice
thanks :alright:

hey why don't u just rotate the whole matrix and then advance the vector ViewFrom (camera position)??

hello,

well it could be a good idea to rotate and to advance the world matrix, but i'm trying to rotate a single vertex buffer and to advance it, not to rotate the whole "world" and then to advance it, but anyway thanks for the advice....and by the way i'd like EvilHomer2k to answer me.... :oops:

well it could be a good idea to rotate and to advance the world matrix, but i'm trying to rotate a single vertex buffer and to advance it, not to rotate the whole "world" and then to advance it, but anyway thanks for the advice....and by the way i'd like EvilHomer2k to answer me.... :oops:

You have two choices, quaternions or matrices.

Using them is similar, so I won't get into the details of the difference.

First you need to create either a quaternion or a matrix that contains "your rotation values".

You can use DX functions to do this.

Then you apply the resulting matrix (or quat) to the mesh, again using DX functions.

Now your object is rotated, you can Render it.

Simple, aint it?

You don't need to rotate all the vertices yourself :)

Using them is similar, so I won't get into the details of the difference.

First you need to create either a quaternion or a matrix that contains "your rotation values".

You can use DX functions to do this.

Then you apply the resulting matrix (or quat) to the mesh, again using DX functions.

Now your object is rotated, you can Render it.

Simple, aint it?

You don't need to rotate all the vertices yourself :)

I just wanted to add that you can use the same notion to rotate THE WORLD AROUND YOUR VIEWPOINT by creating a matrix or quat that contains "the camera orientation as rotations" and applying the resulting matrix as the "World Transformation".

I also wanted to add that is possible to create matrices that (rather than rotate) can Translate (move in +/- XYZ) and Scale (also in XYZ but as a multiplier) your objects and/or camera, and that these matrices can be "CONCATENATED" to produce a single matrix that can rotate, scale and position an object in the world, etc etc, lots of possibilities :)

It makes you start thinking in terms of object INSTANCES, doesn't it?

You can redraw the same object at different locations, scales and orientations ;)

It makes you start thinking in terms of object INSTANCES, doesn't it?

You can redraw the same object at different locations, scales and orientations ;)

hi EvilHomer2k,

first of all thank you for you help! :alright:

well that was exactly what i need for my test app, i think (please correct me if i'm wrong) that i have to use D3DXMatrixRotaion? to rotate in ? axis but how can i use the function D3DXMatrixTranslation to make movement coherent with the rotation?, and something more: how do i say to the vertex buffer that it has to rotate and move according to a matrix?

i would really love some sample code :oops:

thanks

first of all thank you for you help! :alright:

well that was exactly what i need for my test app, i think (please correct me if i'm wrong) that i have to use D3DXMatrixRotaion? to rotate in ? axis but how can i use the function D3DXMatrixTranslation to make movement coherent with the rotation?, and something more: how do i say to the vertex buffer that it has to rotate and move according to a matrix?

i would really love some sample code :oops:

thanks

What about this one http://historical.library.cornell.edu/cgi-bin/cul.math/docviewer?did=01140002&view=50&frames=0&seq=11 the section of rotation.. or all...

Altought you should find information about operations on matrices :) (normally only multiplication of a transition matrix by the points that you whant to translate...)

Altought you should find information about operations on matrices :) (normally only multiplication of a transition matrix by the points that you whant to translate...)

I think yes, it would be best to start with Matrices.

You can try Quaternions later on (they can be faster).

Let's talk first about Translation of objects and the World Transformation.

I want you to start thinking in terms of a 3D pen or cursor that you will move to a place in your world to draw the object.

Let's say for example that we want to draw an object at World Location (10, -20, 5)

In order to do this we need to move THE WORLD by the opposite amount.

Yes, in order to move the object to +10 in X, we need to MOVE THE WORLD by -10 in X, Draw the object, THEN MOVE BACK WHERE WE WERE.

How do we do this?

First, we need to make a note of the CURRENT WORLD TRANSFORM so we can put it back when we are done. Now we make a Translation Matrix for moving the object. We apply it not to the object, but to the WORLD !!

Now we Render our object, then we set the World Transform back to its original matrix that we stored earlier.

Now we can use that logic to place all our objects RELATIVE TO THE ORIGIN OF THE WORLD.

Matrices are about nothing if not relativity.

How do we rotate AND place our objects?

First we need to define what rotation is. Are we rotating each object around its OWN origin, or are they orbiting some fixed point in space?

(Note - again, rotations should be made negative, and applied as the World Transformation, rotating the World around the Object by minus the desired angles)

Let's assume we want to rotate each object around its OWN origin, as well as place it in world space.

To do this, we need to rotate the object BEFORE we translate it.

We need to create TWO matrices for each object, one Translation and one Rotation matrix. Then we need to CONCATENATE them into a single matrix, apply it to the world, draw the object, then unapply it.

How do we know if we are rotating then translating, or translating then rotating? Simple - when we concatenate the matrices, THE ORDER IS VERY IMPORTANT. Experimentation here will make this clear.

Source can be found on Scronty's site.

You can try Quaternions later on (they can be faster).

Let's talk first about Translation of objects and the World Transformation.

I want you to start thinking in terms of a 3D pen or cursor that you will move to a place in your world to draw the object.

Let's say for example that we want to draw an object at World Location (10, -20, 5)

In order to do this we need to move THE WORLD by the opposite amount.

Yes, in order to move the object to +10 in X, we need to MOVE THE WORLD by -10 in X, Draw the object, THEN MOVE BACK WHERE WE WERE.

How do we do this?

First, we need to make a note of the CURRENT WORLD TRANSFORM so we can put it back when we are done. Now we make a Translation Matrix for moving the object. We apply it not to the object, but to the WORLD !!

Now we Render our object, then we set the World Transform back to its original matrix that we stored earlier.

Now we can use that logic to place all our objects RELATIVE TO THE ORIGIN OF THE WORLD.

Matrices are about nothing if not relativity.

How do we rotate AND place our objects?

First we need to define what rotation is. Are we rotating each object around its OWN origin, or are they orbiting some fixed point in space?

(Note - again, rotations should be made negative, and applied as the World Transformation, rotating the World around the Object by minus the desired angles)

Let's assume we want to rotate each object around its OWN origin, as well as place it in world space.

To do this, we need to rotate the object BEFORE we translate it.

We need to create TWO matrices for each object, one Translation and one Rotation matrix. Then we need to CONCATENATE them into a single matrix, apply it to the world, draw the object, then unapply it.

How do we know if we are rotating then translating, or translating then rotating? Simple - when we concatenate the matrices, THE ORDER IS VERY IMPORTANT. Experimentation here will make this clear.

Source can be found on Scronty's site.

What happens if we don't reapply the old world transform inbetween processing each object?

The next object will be translated and rotated WITH RESPECT TO THE LAST ONE.

COOL, HUH?

This is called Relative Rotation and Translation.

We can use this to make things orbit each other and other coolness.

The next object will be translated and rotated WITH RESPECT TO THE LAST ONE.

COOL, HUH?

This is called Relative Rotation and Translation.

We can use this to make things orbit each other and other coolness.

The greatest use for relative rotation and translation is when it comes to Articulated objects like Skinned Meshes.

Think about something with moving joints, the joints are rotation origins.

Think about something with moving joints, the joints are rotation origins.

It's pretty easy to come up with a DrawObject procedure that

A) saves the current world xform

B) applies the object xform to the world

C) renders the object

D) applies the saved world xform

Now you can call that for each object, make life easy :)

A) saves the current world xform

B) applies the object xform to the world

C) renders the object

D) applies the saved world xform

Now you can call that for each object, make life easy :)

I should point out that when we manipulate "The World", nothing is really being manipulated that already is rendered - the manipulation only applies to what is yet to be rendered, ok?

We are not physically rotating every vertex in the known universe around one origin each time we draw stuff using the method provided, so don't panic when I talk in those terms.

We are not physically rotating every vertex in the known universe around one origin each time we draw stuff using the method provided, so don't panic when I talk in those terms.

The composition of a matrix :), you know composition of functions??

g(x) = x^2

f(x) = 2*x+2

f(g(x)) = 2*g(x)+2 = 2*x^2+2

Is nearly the same with matrices.. You have your translation matris T and your rotation matrix R

TR = M

RT = M^(-1)

You get the the rotation oand translation in only one matrix and the inverse if you do the multiplication in the other order... you aply first one transformation for move the objet and aply the inverse for undo the transformation, and because they are square matriz the multiplition (or transformation) will always have a inverse. Mean that.

MM^(-1) = I

You get the identity matrix or no modifications.

g(x) = x^2

f(x) = 2*x+2

f(g(x)) = 2*g(x)+2 = 2*x^2+2

Is nearly the same with matrices.. You have your translation matris T and your rotation matrix R

TR = M

RT = M^(-1)

You get the the rotation oand translation in only one matrix and the inverse if you do the multiplication in the other order... you aply first one transformation for move the objet and aply the inverse for undo the transformation, and because they are square matriz the multiplition (or transformation) will always have a inverse. Mean that.

MM^(-1) = I

You get the identity matrix or no modifications.

hello hgb,

thanks for your explanation and the web site, now i understand mathematically how to rotate a solid object :alright:

hello EvilHomer2k,

that's awesome!!, thank you very much :alright:

now, i have noticed one thing: you said that if i want to move an object for example to (10,0,0) i have to move the world matrix to (-10,0,0) then i render the object and finally i move the matrix again to (0,0,0) but when i do this the object appears in (-10,0,0) is this correct? or am i doing somethig wrong???

and something more: i have made tests with rotation and translation, as you taught me, and they worked exacly how i expected, but i don't know how to apply both movements, i mean, i don't know which function "concatenates" the both matrices (rotation and movement), would you please tell me which is???

thanks

thanks for your explanation and the web site, now i understand mathematically how to rotate a solid object :alright:

hello EvilHomer2k,

that's awesome!!, thank you very much :alright:

now, i have noticed one thing: you said that if i want to move an object for example to (10,0,0) i have to move the world matrix to (-10,0,0) then i render the object and finally i move the matrix again to (0,0,0) but when i do this the object appears in (-10,0,0) is this correct? or am i doing somethig wrong???

and something more: i have made tests with rotation and translation, as you taught me, and they worked exacly how i expected, but i don't know how to apply both movements, i mean, i don't know which function "concatenates" the both matrices (rotation and movement), would you please tell me which is???

thanks

Simple.

D3DXMatrixMultiply is the one you are looking for.

When we "multiply" two input matrices, we get one "concatenated" output matrix.

The params for the function are from memory,

param1= ptr to output matrix

param2= ptr to input matrix#1

param3= ptr to input matrix#2

The order of the input matrices is very important, especially when we begin concatenating MORE than just two matrices.

If my memory serves me correctly, the last matrix operation applied to a concatenated matrix can be considered the first one applied when we apply the matrix to an object (via applying it to the worldtransform).

So if input1 is translationmatrix and input2 is rotationmatrix , we can imagine we are first rotating the object (about the world origin, which just happens to coincide with the objects origin when its at 0,0,0), then translating it in XYZ. This is most often going to be what you want.

As for why its moving in -X when you build the worldtransform as I stipulated, that depends on whether you built a right or left handed viewmatrix :)

D3DXMatrixMultiply is the one you are looking for.

When we "multiply" two input matrices, we get one "concatenated" output matrix.

The params for the function are from memory,

param1= ptr to output matrix

param2= ptr to input matrix#1

param3= ptr to input matrix#2

The order of the input matrices is very important, especially when we begin concatenating MORE than just two matrices.

If my memory serves me correctly, the last matrix operation applied to a concatenated matrix can be considered the first one applied when we apply the matrix to an object (via applying it to the worldtransform).

So if input1 is translationmatrix and input2 is rotationmatrix , we can imagine we are first rotating the object (about the world origin, which just happens to coincide with the objects origin when its at 0,0,0), then translating it in XYZ. This is most often going to be what you want.

As for why its moving in -X when you build the worldtransform as I stipulated, that depends on whether you built a right or left handed viewmatrix :)

Also, you don't "move" the world back to 0,0,0

What you do is "get the current world transform and store it"

then "set the world transform to a matrix which represents MINUS the objectposition and rotation, and draw the object"

and finally "set the worldtransform to whatever it was before (since we saved it)"

What you do is "get the current world transform and store it"

then "set the world transform to a matrix which represents MINUS the objectposition and rotation, and draw the object"

and finally "set the worldtransform to whatever it was before (since we saved it)"