help with rotating and scaling vertex 
Author Message
 help with rotating and scaling vertex

Tina Kirby (a user of this news group) sent me this code to help with moving objects around. is there a way to also scale and rotate
a vertex in a similar way to below. it's the easiest and only way i can see that i will be able to manipulate seperate objects
rather then all of them at once using matrix transform. would anyone be willing to write up 2 sub's which would do what i'm looking
for?

Public Sub Move(mesh As D3DXMesh, x As Single, y As Single, z As Single)
    Dim count, Size, i As Long
    Dim verts() As D3DVERTEX
    Dim vb As Direct3DVertexBuffer8

    Set vb = mesh.GetVertexBuffer
    Size = g_D3DX.GetFVFVertexSize(mesh.GetFVF())
    count = mesh.GetNumVertices()
    If mesh.GetFVF() = D3DFVF_VERTEX Then
        ReDim verts(count)
        D3DVertexBuffer8GetData vb, 0, Size * count, 0, verts(0)
        For i = 0 To count - 1
            verts(i).x = verts(i).x + x
            verts(i).y = verts(i).y + y
            verts(i).z = verts(i).z + z
        Next
        D3DVertexBuffer8SetData vb, 0, Size * count, 0, verts(0)
    End If
End Sub

Another problem i have is working out how to use the mouse in my program. i want the user to be able to move the mouse left n right,
up n down and thus moving the camera around a centre point which will be the character which u control while walking around in my
future game. atm i'm just trying to learn how to do anything and later i will start all over to make my code much more optimized.
i've tried following the help in the sdk but it crashes my program. is there a simple tutorial anyone knows of which i can look at?



Sat, 13 Nov 2004 14:07:36 GMT  
 help with rotating and scaling vertex
You could use D3DXMatrixScaling to scale the world matrix.

I wouldn't use this method as you'll have to update each vertex each frame.
Just use a world matrix for each object. The world matrix allows to convert
model coordinates to world coordinates. Usually you set the world matrix
multiple times per frames to place each group of objects in your world...

Patrice



Quote:
> Tina Kirby (a user of this news group) sent me this code to help with

moving objects around. is there a way to also scale and rotate
Quote:
> a vertex in a similar way to below. it's the easiest and only way i can

see that i will be able to manipulate seperate objects
Quote:
> rather then all of them at once using matrix transform. would anyone be

willing to write up 2 sub's which would do what i'm looking
Quote:
> for?

> Public Sub Move(mesh As D3DXMesh, x As Single, y As Single, z As Single)
>     Dim count, Size, i As Long
>     Dim verts() As D3DVERTEX
>     Dim vb As Direct3DVertexBuffer8

>     Set vb = mesh.GetVertexBuffer
>     Size = g_D3DX.GetFVFVertexSize(mesh.GetFVF())
>     count = mesh.GetNumVertices()
>     If mesh.GetFVF() = D3DFVF_VERTEX Then
>         ReDim verts(count)
>         D3DVertexBuffer8GetData vb, 0, Size * count, 0, verts(0)
>         For i = 0 To count - 1
>             verts(i).x = verts(i).x + x
>             verts(i).y = verts(i).y + y
>             verts(i).z = verts(i).z + z
>         Next
>         D3DVertexBuffer8SetData vb, 0, Size * count, 0, verts(0)
>     End If
> End Sub

> Another problem i have is working out how to use the mouse in my program.

i want the user to be able to move the mouse left n right,
Quote:
> up n down and thus moving the camera around a centre point which will be

the character which u control while walking around in my
Quote:
> future game. atm i'm just trying to learn how to do anything and later i

will start all over to make my code much more optimized.
Quote:
> i've tried following the help in the sdk but it crashes my program. is

there a simple tutorial anyone knows of which i can look at?

- Show quoted text -



Sat, 13 Nov 2004 15:25:02 GMT  
 help with rotating and scaling vertex

Thanks for this bit of info Patrice, I wasn't sure whether
that was possible. Definitely saves on some {*filter*} vertex
coding. However, after trying this I still can't get it to
both rotate and position more than 1 object.

I have an object class that contains its own Matrix now.  
I create an object belonging to that class and position
and initialise the mesh.

In the Render scene I have tried the following for each
objects matrix sub object.

D3DXMatrixRotationAxis dxMatrix, rotate, speed
d3ddev.SetTransform D3DTS_WORLD, dxMatrix
D3DXMatrixAffineTransformation dxMatrix, scalefactor,
rotation, qrotation, translation
d3ddev.SetTransform D3DTS_WORLD, dxMatrix

with..
rotate/rotation = (0,1,0)
speed = timer - methinks this is where the problem is
scalefactor = 0.5 - ooh this works.. great
qrotation = (1,0,0,0) - facing me (ah thats what that does)
translation = (10*i,0,0)
i = 0 to 5 for each object

all but the rotation seems to work unless I do this

D3DXMatrixRotationAxis dxMatrix, rotate, speed
d3ddev.SetTransform D3DTS_WORLD, dxMatrix

which then doesn't alter the position of the objects and
thus places them in the same location

any idea how to get both the rotation and the multiple
object position to work..?  Or is it qrotation that needs
to be adjusted each rendering to get the object to face in
another direction?

Thankee kindly for any help to us newbies ;-)

Boy DirectX is so much easier in VB than C++.  I've learnt
more in the last week than what I even did in C++ in the
month I tried it out in version 6.

Quote:
>-----Original Message-----
>You could use D3DXMatrixScaling to scale the world matrix.

>I wouldn't use this method as you'll have to update each
vertex each frame.
>Just use a world matrix for each object. The world matrix
allows to convert
>model coordinates to world coordinates. Usually you set
the world matrix
>multiple times per frames to place each group of objects
in your world...

>Patrice




>> Tina Kirby (a user of this news group) sent me this
code to help with
>moving objects around. is there a way to also scale and
rotate
>> a vertex in a similar way to below. it's the easiest
and only way i can
>see that i will be able to manipulate seperate objects
>> rather then all of them at once using matrix transform.
would anyone be
>willing to write up 2 sub's which would do what i'm
looking
>> for?

>> Public Sub Move(mesh As D3DXMesh, x As Single, y As

Single, z As Single)

- Show quoted text -

Quote:
>>     Dim count, Size, i As Long
>>     Dim verts() As D3DVERTEX
>>     Dim vb As Direct3DVertexBuffer8

>>     Set vb = mesh.GetVertexBuffer
>>     Size = g_D3DX.GetFVFVertexSize(mesh.GetFVF())
>>     count = mesh.GetNumVertices()
>>     If mesh.GetFVF() = D3DFVF_VERTEX Then
>>         ReDim verts(count)
>>         D3DVertexBuffer8GetData vb, 0, Size * count, 0,
verts(0)
>>         For i = 0 To count - 1
>>             verts(i).x = verts(i).x + x
>>             verts(i).y = verts(i).y + y
>>             verts(i).z = verts(i).z + z
>>         Next
>>         D3DVertexBuffer8SetData vb, 0, Size * count, 0,
verts(0)
>>     End If
>> End Sub

>> Another problem i have is working out how to use the

mouse in my program.
Quote:
>i want the user to be able to move the mouse left n right,
>> up n down and thus moving the camera around a centre
point which will be
>the character which u control while walking around in my
>> future game. atm i'm just trying to learn how to do

anything and later i

- Show quoted text -

Quote:
>will start all over to make my code much more optimized.
>> i've tried following the help in the sdk but it crashes
my program. is
>there a simple tutorial anyone knows of which i can look
at?

>.



Sat, 13 Nov 2004 18:01:57 GMT  
 help with rotating and scaling vertex

Yaay, sorted it :D  Each Object now rotates and positions
in a different place... :D

Matrix base class has the following routine.

Public Sub Transform(scalefactor As Single, _
                     rotation As D3DVECTOR, _
                     translation As D3DVECTOR, _
                     speed As Long)
    Dim quaternion As D3DQUATERNION
    D3DXMatrixRotationAxis dxMatrix, rotation, speed
    D3DXQuaternionRotationMatrix quaternion, dxMatrix
    D3DXMatrixAffineTransformation dxMatrix, _
                                   scalefactor, _
                                   rotation, _
                                   quaternion, _
                                   translation
    d3ddev.SetTransform D3DTS_WORLD, dxMatrix
End Sub

The Mesh Base Class has the following routine which works
on the matrix linked to it:

Public Sub OutputMesh(segment As Integer, _
                      scalefactor as single, _
                      rotation As D3DVECTOR, _
                      speed As Long, _
                      position as D3DVECTOR)
    dxMatrix.Transform scalefactor, _
                       rotation, _
                       position, _
                       Timer
    If segment = -1 Then
        For i = 0 To NumMaterials - 1
            d3ddev.SetMaterial dxMaterial(i)
            d3ddev.SetTexture 0, dxTexture(i)
            dxMesh.DrawSubset i
        Next i
    Else
        d3ddev.SetMaterial dxMaterial(segment)
        d3ddev.SetTexture 0, dxTexture(segment)
        dxMesh.DrawSubset segment
    End If
End Sub

The render routine then does the following to display all
objects:

    For i = 0 To UBound(dxMesh)
        dxMesh(i).OutputMesh -1, _
                             0.5, _
                             vec3(0, 1, 0), _
                             Timer, _
                             vec3(10*i,0,0)
    Next i

Now if only I can figure out how to speed this thing up..
5 objects is all and well but with a 100 its unbearable
and what about those animations, I still can't figure out
how they are utilised.

Quote:
>-----Original Message-----

>Thanks for this bit of info Patrice, I wasn't sure
whether
>that was possible. Definitely saves on some {*filter*} vertex
>coding. However, after trying this I still can't get it
to
>both rotate and position more than 1 object.

>I have an object class that contains its own Matrix now.  
>I create an object belonging to that class and position
>and initialise the mesh.

>In the Render scene I have tried the following for each
>objects matrix sub object.

>D3DXMatrixRotationAxis dxMatrix, rotate, speed
>d3ddev.SetTransform D3DTS_WORLD, dxMatrix
>D3DXMatrixAffineTransformation dxMatrix, scalefactor,
>rotation, qrotation, translation
>d3ddev.SetTransform D3DTS_WORLD, dxMatrix

>with..
>rotate/rotation = (0,1,0)
>speed = timer - methinks this is where the problem is
>scalefactor = 0.5 - ooh this works.. great
>qrotation = (1,0,0,0) - facing me (ah thats what that
does)
>translation = (10*i,0,0)
>i = 0 to 5 for each object

>all but the rotation seems to work unless I do this

>D3DXMatrixRotationAxis dxMatrix, rotate, speed
>d3ddev.SetTransform D3DTS_WORLD, dxMatrix

>which then doesn't alter the position of the objects and
>thus places them in the same location

>any idea how to get both the rotation and the multiple
>object position to work..?  Or is it qrotation that needs
>to be adjusted each rendering to get the object to face
in
>another direction?

>Thankee kindly for any help to us newbies ;-)

>Boy DirectX is so much easier in VB than C++.  I've
learnt
>more in the last week than what I even did in C++ in the
>month I tried it out in version 6.

>>-----Original Message-----
>>You could use D3DXMatrixScaling to scale the world
matrix.

>>I wouldn't use this method as you'll have to update each
>vertex each frame.
>>Just use a world matrix for each object. The world
matrix
>allows to convert
>>model coordinates to world coordinates. Usually you set
>the world matrix
>>multiple times per frames to place each group of objects
>in your world...

>>Patrice




>>> Tina Kirby (a user of this news group) sent me this
>code to help with
>>moving objects around. is there a way to also scale and
>rotate
>>> a vertex in a similar way to below. it's the easiest
>and only way i can
>>see that i will be able to manipulate seperate objects
>>> rather then all of them at once using matrix
transform.
>would anyone be
>>willing to write up 2 sub's which would do what i'm
>looking
>>> for?

>>> Public Sub Move(mesh As D3DXMesh, x As Single, y As
>Single, z As Single)
>>>     Dim count, Size, i As Long
>>>     Dim verts() As D3DVERTEX
>>>     Dim vb As Direct3DVertexBuffer8

>>>     Set vb = mesh.GetVertexBuffer
>>>     Size = g_D3DX.GetFVFVertexSize(mesh.GetFVF())
>>>     count = mesh.GetNumVertices()
>>>     If mesh.GetFVF() = D3DFVF_VERTEX Then
>>>         ReDim verts(count)
>>>         D3DVertexBuffer8GetData vb, 0, Size * count,
0,
>verts(0)
>>>         For i = 0 To count - 1
>>>             verts(i).x = verts(i).x + x
>>>             verts(i).y = vert{ w O ?<Z<lbV<L?
          # s(i).y + y
>>>             verts(i).z = verts(i).z + z
>>>         Next
>>>         D3DVertexBuffer8SetData vb, 0, Size * count,
0,
>verts(0)
>>>     End If
>>> End Sub

>>> Another problem i have is working out how to use the
>mouse in my program.
>>i want the user to be



Sat, 13 Nov 2004 18:38:02 GMT  
 help with rotating and scaling vertex
D3DXMatrixRotationAxis (as any other D3DXMatrix... method) doesn't update
the current matrix but creates a new one with only the corresponding
transformation.

You'll have to use D3DXMatrixMultiply to combine the new matrix with an
existing matrix (possibly the same variable)

Patrice



Thanks for this bit of info Patrice, I wasn't sure whether
that was possible. Definitely saves on some {*filter*} vertex
coding. However, after trying this I still can't get it to
both rotate and position more than 1 object.

I have an object class that contains its own Matrix now.
I create an object belonging to that class and position
and initialise the mesh.

In the Render scene I have tried the following for each
objects matrix sub object.

D3DXMatrixRotationAxis dxMatrix, rotate, speed
d3ddev.SetTransform D3DTS_WORLD, dxMatrix
D3DXMatrixAffineTransformation dxMatrix, scalefactor,
rotation, qrotation, translation
d3ddev.SetTransform D3DTS_WORLD, dxMatrix

with..
rotate/rotation = (0,1,0)
speed = timer - methinks this is where the problem is
scalefactor = 0.5 - ooh this works.. great
qrotation = (1,0,0,0) - facing me (ah thats what that does)
translation = (10*i,0,0)
i = 0 to 5 for each object

all but the rotation seems to work unless I do this

D3DXMatrixRotationAxis dxMatrix, rotate, speed
d3ddev.SetTransform D3DTS_WORLD, dxMatrix

which then doesn't alter the position of the objects and
thus places them in the same location

any idea how to get both the rotation and the multiple
object position to work..?  Or is it qrotation that needs
to be adjusted each rendering to get the object to face in
another direction?

Thankee kindly for any help to us newbies ;-)

Boy DirectX is so much easier in VB than C++.  I've learnt
more in the last week than what I even did in C++ in the
month I tried it out in version 6.

[cut]



Sat, 13 Nov 2004 19:46:40 GMT  
 help with rotating and scaling vertex


Fri, 19 Jun 1992 00:00:00 GMT  
 help with rotating and scaling vertex
Thanks, I'll keep a look out for that but seems to be
working fine now.

Quote:
>-----Original Message-----
>D3DXMatrixRotationAxis (as any other D3DXMatrix...

method) doesn't update
Quote:
>the current matrix but creates a new one with only the
corresponding
>transformation.

>You'll have to use D3DXMatrixMultiply to combine the new
matrix with an
>existing matrix (possibly the same variable)

>Patrice




>Thanks for this bit of info Patrice, I wasn't sure whether
>that was possible. Definitely saves on some {*filter*} vertex
>coding. However, after trying this I still can't get it to
>both rotate and position more than 1 object.

>I have an object class that contains its own Matrix now.
>I create an object belonging to that class and position
>and initialise the mesh.

>In the Render scene I have tried the following for each
>objects matrix sub object.

>D3DXMatrixRotationAxis dxMatrix, rotate, speed
>d3ddev.SetTransform D3DTS_WORLD, dxMatrix
>D3DXMatrixAffineTransformation dxMatrix, scalefactor,
>rotation, qrotation, translation
>d3ddev.SetTransform D3DTS_WORLD, dxMatrix

>with..
>rotate/rotation = (0,1,0)
>speed = timer - methinks this is where the problem is
>scalefactor = 0.5 - ooh this works.. great
>qrotation = (1,0,0,0) - facing me (ah thats what that
does)
>translation = (10*i,0,0)
>i = 0 to 5 for each object

>all but the rotation seems to work unless I do this

>D3DXMatrixRotationAxis dxMatrix, rotate, speed
>d3ddev.SetTransform D3DTS_WORLD, dxMatrix

>which then doesn't alter the position of the objects and
>thus places them in the same location

>any idea how to get both the rotation and the multiple
>object position to work..?  Or is it qrotation that needs
>to be adjusted each rendering to get the object to face in
>another direction?

>Thankee kindly for any help to us newbies ;-)

>Boy DirectX is so much easier in VB than C++.  I've learnt
>more in the last week than what I even did in C++ in the
>month I tried it out in version 6.

>[cut]

>.



Sat, 13 Nov 2004 21:12:22 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. Rotating Vertices

2. Scaling, rotating BMPs

3. HW vertex processing vs. SW vertex processing optimizations...

4. vertices property

5. resizing mesh's Vertex buffer

6. L-Vertices for screen space?

7. Modify vertex data during rendering

8. Multitexturing + Vertex-colors

9. D3D-Vertex-Stream problem

10. Wondering about speed issues with LitVertices vs. Vertices

11. Vertex-Buffers

12. vertex transform

 

 
Powered by phpBB® Forum Software