Moving Meshes 
Author Message
 Moving Meshes

I know this question probably gets asked a lot but I haven't seen it
recently and really want to know the answer. So if there is a web site
that has an example or there is some code someone can attach or paste
that would be great.

Question:
Within my worldview how do I make a loaded mesh (or many loaded meshes)
move within the world?

Specifics:
I know how to make the actual world view move. And I know I can find
enough examples on actual animation (which I am not to this procedure in
my learning yet). I don't want the actual world itself to move. I don't
necessarily want the object to be animated (yet).

Example:
I have a world with a square mesh (not a primative created in the code
but an actual loaded mesh with texture) and a sphere mesh (same) right
next to it. How do I get (for example) the square mesh to go up and down
while the sphere mesh doesn't move at all.

Note:
The direction of the movement of the square mesh does not have to be up
and down. I'd like it to be able to turn on it's axis and go in any
direction. However, I do not want the world view to change nor the
sphere mesh to move.

Help is appreciated.

Wayne



Sun, 25 Apr 2004 21:22:05 GMT  
 Moving Meshes
Each time you draw your meshes, you translate your world view. So all you
really have to do is to transform your world view differently each time you
draw each mesh. After you draw each mesh you can restore the world view to
its default location and transform it again for the next mesh.

       ........Wayne

--

Recycling electrons into words since 1996.
Visit www.JustPC.com for details about my Visual Basic books, including
my newest: Windows Game Programming With Visual Basic and DirectX,
and the ASP.NET Database Programming Bible.


Quote:
> I know this question probably gets asked a lot but I haven't seen it
> recently and really want to know the answer. So if there is a web site
> that has an example or there is some code someone can attach or paste
> that would be great.

> Question:
> Within my worldview how do I make a loaded mesh (or many loaded meshes)
> move within the world?

> Specifics:
> I know how to make the actual world view move. And I know I can find
> enough examples on actual animation (which I am not to this procedure in
> my learning yet). I don't want the actual world itself to move. I don't
> necessarily want the object to be animated (yet).

> Example:
> I have a world with a square mesh (not a primative created in the code
> but an actual loaded mesh with texture) and a sphere mesh (same) right
> next to it. How do I get (for example) the square mesh to go up and down
> while the sphere mesh doesn't move at all.

> Note:
> The direction of the movement of the square mesh does not have to be up
> and down. I'd like it to be able to turn on it's axis and go in any
> direction. However, I do not want the world view to change nor the
> sphere mesh to move.

> Help is appreciated.

> Wayne



Sun, 25 Apr 2004 23:31:06 GMT  
 Moving Meshes
http://64.23.12.52/ =)



Quote:
> Each time you draw your meshes, you translate your world view. So all you
> really have to do is to transform your world view differently each time
you
> draw each mesh. After you draw each mesh you can restore the world view to
> its default location and transform it again for the next mesh.

>        ........Wayne

> --

> Recycling electrons into words since 1996.
> Visit www.JustPC.com for details about my Visual Basic books, including
> my newest: Windows Game Programming With Visual Basic and DirectX,
> and the ASP.NET Database Programming Bible.



> > I know this question probably gets asked a lot but I haven't seen it
> > recently and really want to know the answer. So if there is a web site
> > that has an example or there is some code someone can attach or paste
> > that would be great.

> > Question:
> > Within my worldview how do I make a loaded mesh (or many loaded meshes)
> > move within the world?

> > Specifics:
> > I know how to make the actual world view move. And I know I can find
> > enough examples on actual animation (which I am not to this procedure in
> > my learning yet). I don't want the actual world itself to move. I don't
> > necessarily want the object to be animated (yet).

> > Example:
> > I have a world with a square mesh (not a primative created in the code
> > but an actual loaded mesh with texture) and a sphere mesh (same) right
> > next to it. How do I get (for example) the square mesh to go up and down
> > while the sphere mesh doesn't move at all.

> > Note:
> > The direction of the movement of the square mesh does not have to be up
> > and down. I'd like it to be able to turn on it's axis and go in any
> > direction. However, I do not want the world view to change nor the
> > sphere mesh to move.

> > Help is appreciated.

> > Wayne



Mon, 26 Apr 2004 02:25:11 GMT  
 Moving Meshes

Quote:
>Each time you draw your meshes, you translate your world view. So all you
>really have to do is to transform your world view differently each time you
>draw each mesh. After you draw each mesh you can restore the world view to
>its default location and transform it again for the next mesh.

Do you know where there are any code examples of this? I am using
directx8. When I set the world view to its final view it seems to reset
everything. I am also unsure how to determine which view goes with which
mesh.

Did I mention I'm a complete newbie? How do I draw more than one mesh
without having to reload these meshes over and over. All I need are
examples that I can follow. None of the examples in the SDK do this. I
really thought it would be easier.

Wayne



Tue, 27 Apr 2004 06:52:41 GMT  
 Moving Meshes
That seems odd having to translate the world matrix in
order to translate a mesh... If I had a sphere mesh, and I
had its center coordinates (x,y,z), it would seem more
logical to translate the mesh by adding a 3D Vector to it
its coordinates. I'm just starting to program in DX8 for
VB, and I would like to find out how to move meshes in 3D
as well.

Going by JCastro's logic, in order to move the sphere
forward, I would have to translate the world backwards
while maintaining the original mesh location? Seems
slightly awkward when dealing with more than one mesh to
render... If you were dealing with lets say, 2 sphere
meshes, then how would you get them to move towards each
other?

I really need help with this, and I'm sure Wayne does too,
please help anyone!

Quote:
>-----Original Message-----
>http://64.23.12.52/ =)


mensaje

>> Each time you draw your meshes, you translate your

world view. So all you
Quote:
>> really have to do is to transform your world view

differently each time
Quote:
>you
>> draw each mesh. After you draw each mesh you can

restore the world view to
Quote:
>> its default location and transform it again for the
next mesh.

>>        ........Wayne

>> --

>> Recycling electrons into words since 1996.
>> Visit www.JustPC.com for details about my Visual Basic
books, including
>> my newest: Windows Game Programming With Visual Basic
and DirectX,
>> and the ASP.NET Database Programming Bible.



>> > I know this question probably gets asked a lot but I
haven't seen it
>> > recently and really want to know the answer. So if
there is a web site
>> > that has an example or there is some code someone can
attach or paste
>> > that would be great.

>> > Question:
>> > Within my worldview how do I make a loaded mesh (or
many loaded meshes)
>> > move within the world?

>> > Specifics:
>> > I know how to make the actual world view move. And I
know I can find
>> > enough examples on actual animation (which I am not

to this procedure in
Quote:
>> > my learning yet). I don't want the actual world

itself to move. I don't
Quote:
>> > necessarily want the object to be animated (yet).

>> > Example:
>> > I have a world with a square mesh (not a primative
created in the code
>> > but an actual loaded mesh with texture) and a sphere
mesh (same) right
>> > next to it. How do I get (for example) the square

mesh to go up and down

- Show quoted text -

Quote:
>> > while the sphere mesh doesn't move at all.

>> > Note:
>> > The direction of the movement of the square mesh does
not have to be up
>> > and down. I'd like it to be able to turn on it's axis
and go in any
>> > direction. However, I do not want the world view to
change nor the
>> > sphere mesh to move.

>> > Help is appreciated.

>> > Wayne

>.



Tue, 27 Apr 2004 08:43:40 GMT  
 Moving Meshes
That seems odd having to translate the world matrix in
order to translate a mesh... If I had a sphere mesh, and I
had its center coordinates (x,y,z), it would seem more
logical to translate the mesh by adding a 3D Vector to it
its coordinates. I'm just starting to program in DX8 for
VB, and I would like to find out how to move meshes in 3D
as well.

Going by JCastro's logic, in order to move the sphere
forward, I would have to translate the world backwards
while maintaining the original mesh location? Seems
slightly awkward when dealing with more than one mesh to
render... If you were dealing with lets say, 2 sphere
meshes, then how would you get them to move towards each
other?

I really need help with this, and I'm sure Wayne does too,
please help anyone!

Quote:
>-----Original Message-----
>http://64.23.12.52/ =)


mensaje

>> Each time you draw your meshes, you translate your

world view. So all you
Quote:
>> really have to do is to transform your world view

differently each time
Quote:
>you
>> draw each mesh. After you draw each mesh you can

restore the world view to
Quote:
>> its default location and transform it again for the
next mesh.

>>        ........Wayne

>> --

>> Recycling electrons into words since 1996.
>> Visit www.JustPC.com for details about my Visual Basic
books, including
>> my newest: Windows Game Programming With Visual Basic
and DirectX,
>> and the ASP.NET Database Programming Bible.



>> > I know this question probably gets asked a lot but I
haven't seen it
>> > recently and really want to know the answer. So if
there is a web site
>> > that has an example or there is some code someone can
attach or paste
>> > that would be great.

>> > Question:
>> > Within my worldview how do I make a loaded mesh (or
many loaded meshes)
>> > move within the world?

>> > Specifics:
>> > I know how to make the actual world view move. And I
know I can find
>> > enough examples on actual animation (which I am not

to this procedure in
Quote:
>> > my learning yet). I don't want the actual world

itself to move. I don't
Quote:
>> > necessarily want the object to be animated (yet).

>> > Example:
>> > I have a world with a square mesh (not a primative
created in the code
>> > but an actual loaded mesh with texture) and a sphere
mesh (same) right
>> > next to it. How do I get (for example) the square

mesh to go up and down

- Show quoted text -

Quote:
>> > while the sphere mesh doesn't move at all.

>> > Note:
>> > The direction of the movement of the square mesh does
not have to be up
>> > and down. I'd like it to be able to turn on it's axis
and go in any
>> > direction. However, I do not want the world view to
change nor the
>> > sphere mesh to move.

>> > Help is appreciated.

>> > Wayne

>.



Tue, 27 Apr 2004 08:43:35 GMT  
 Moving Meshes
I have some code samples, but they're too complex to post here. But let me
try to explain the basic idea.

Suppose you create a mesh using a tool like 3DS Max or trueSpace. All of the
triangles are drawn relative to the mesh's local coordinate system, whose
origin is (0,0,0). Now when you draw this object in DirectX, you use the
world's coordinate system to draw the object. Since the object's origin is
(0,0,0), the object will be drawn at the world's origin (0,0,0). So you have
a choice, do you translate all of the object's coordinates or do you
translate the world's origin? I find it easier to translate the world's
origin just before I draw the mesh. Then it's drawn at the appropriate
location. When I've finished drawing all of the meshes in my program, I
reset the world's origin to (0,0,0).

Now this may not be the optimal solution, but it's pretty easy to implement
and it will make more sense after you work with it for a while.

     ...........Wayne

--

Recycling electrons into words since 1996.
Visit www.JustPC.com for details about my Visual Basic books, including
my newest: Windows Game Programming With Visual Basic and DirectX,
and the ASP.NET Database Programming Bible.


Quote:

> >Each time you draw your meshes, you translate your world view. So all you
> >really have to do is to transform your world view differently each time
you
> >draw each mesh. After you draw each mesh you can restore the world view
to
> >its default location and transform it again for the next mesh.

> Do you know where there are any code examples of this? I am using
> directx8. When I set the world view to its final view it seems to reset
> everything. I am also unsure how to determine which view goes with which
> mesh.

> Did I mention I'm a complete newbie? How do I draw more than one mesh
> without having to reload these meshes over and over. All I need are
> examples that I can follow. None of the examples in the SDK do this. I
> really thought it would be easier.

> Wayne



Tue, 27 Apr 2004 11:09:24 GMT  
 Moving Meshes
It looks like you understand what I'm trying to do. However, you do this
translation for each mesh you want to display. The way I deal with this is I
define a class to store objects in my 3D world. Each object has its own
location relative to the world's origin (0,0,0). Also, each object has a
pointer to the mesh associated with it. This allows me to load a mesh once,
but display it as many times as needed (like the customers in a shopping
mall) in multiple places in the 3D world. Since you redraw all of the
objects (and thus their meshes) in the 3D world for each frame, you can
animate your objects by simply adjusting the world coordinates associated
with each object in between each frame.

I know this sounds weird - it took me a while to get comfortable with the
idea - but give it some thought.

      .........Wayne

--

Recycling electrons into words since 1996.
Visit www.JustPC.com for details about my Visual Basic books, including
my newest: Windows Game Programming With Visual Basic and DirectX,
and the ASP.NET Database Programming Bible.


That seems odd having to translate the world matrix in
order to translate a mesh... If I had a sphere mesh, and I
had its center coordinates (x,y,z), it would seem more
logical to translate the mesh by adding a 3D Vector to it
its coordinates. I'm just starting to program in DX8 for
VB, and I would like to find out how to move meshes in 3D
as well.

Going by JCastro's logic, in order to move the sphere
forward, I would have to translate the world backwards
while maintaining the original mesh location? Seems
slightly awkward when dealing with more than one mesh to
render... If you were dealing with lets say, 2 sphere
meshes, then how would you get them to move towards each
other?

I really need help with this, and I'm sure Wayne does too,
please help anyone!

Quote:
>-----Original Message-----
>http://64.23.12.52/ =)


mensaje

>> Each time you draw your meshes, you translate your

world view. So all you
Quote:
>> really have to do is to transform your world view

differently each time
Quote:
>you
>> draw each mesh. After you draw each mesh you can

restore the world view to
Quote:
>> its default location and transform it again for the
next mesh.

>>        ........Wayne

>> --

>> Recycling electrons into words since 1996.
>> Visit www.JustPC.com for details about my Visual Basic
books, including
>> my newest: Windows Game Programming With Visual Basic
and DirectX,
>> and the ASP.NET Database Programming Bible.



>> > I know this question probably gets asked a lot but I
haven't seen it
>> > recently and really want to know the answer. So if
there is a web site
>> > that has an example or there is some code someone can
attach or paste
>> > that would be great.

>> > Question:
>> > Within my worldview how do I make a loaded mesh (or
many loaded meshes)
>> > move within the world?

>> > Specifics:
>> > I know how to make the actual world view move. And I
know I can find
>> > enough examples on actual animation (which I am not

to this procedure in
Quote:
>> > my learning yet). I don't want the actual world

itself to move. I don't
Quote:
>> > necessarily want the object to be animated (yet).

>> > Example:
>> > I have a world with a square mesh (not a primative
created in the code
>> > but an actual loaded mesh with texture) and a sphere
mesh (same) right
>> > next to it. How do I get (for example) the square

mesh to go up and down

- Show quoted text -

Quote:
>> > while the sphere mesh doesn't move at all.

>> > Note:
>> > The direction of the movement of the square mesh does
not have to be up
>> > and down. I'd like it to be able to turn on it's axis
and go in any
>> > direction. However, I do not want the world view to
change nor the
>> > sphere mesh to move.

>> > Help is appreciated.

>> > Wayne

>.



Tue, 27 Apr 2004 11:22:59 GMT  
 Moving Meshes
See just this matrix as a mean to transform model coordinates to "world"
coordinates.
It's much more costly to update each vertex each frame rather than updating
a single matrix and drawing the mesh again (you could even draw multiople
objects with the same mesh at different locations).

IMO this is the "world" word that leads to this understanding. Keep in mind
that it doesn't define something special for the "world" as a whole, it just
allows to transform local coordinates *to* world coordinates and this can be
change for each model (allowing to place each of them at a distinct
location).

Patrice



That seems odd having to translate the world matrix in
order to translate a mesh... If I had a sphere mesh, and I
had its center coordinates (x,y,z), it would seem more
logical to translate the mesh by adding a 3D Vector to it
its coordinates. I'm just starting to program in DX8 for
VB, and I would like to find out how to move meshes in 3D
as well.

Going by JCastro's logic, in order to move the sphere
forward, I would have to translate the world backwards
while maintaining the original mesh location? Seems
slightly awkward when dealing with more than one mesh to
render... If you were dealing with lets say, 2 sphere
meshes, then how would you get them to move towards each
other?

I really need help with this, and I'm sure Wayne does too,
please help anyone!



Tue, 27 Apr 2004 17:02:07 GMT  
 Moving Meshes

Quote:
>I have some code samples, but they're too complex to post here. But let me
>try to explain the basic idea.

I played around with it and finally got it. My original problem was that
I set up a view and drew both meshes and then setup the final view. I
forgot to setup a view between the subset drawing of the two meshes.

Wayne



Wed, 28 Apr 2004 07:57:09 GMT  
 Moving Meshes

Quote:

>That seems odd having to translate the world matrix in
>order to translate a mesh... If I had a sphere mesh, and I
>had its center coordinates (x,y,z), it would seem more
>logical to translate the mesh by adding a 3D Vector to it
>its coordinates. I'm just starting to program in DX8 for
>VB, and I would like to find out how to move meshes in 3D
>as well.

>Going by JCastro's logic, in order to move the sphere
>forward, I would have to translate the world backwards
>while maintaining the original mesh location? Seems
>slightly awkward when dealing with more than one mesh to
>render... If you were dealing with lets say, 2 sphere
>meshes, then how would you get them to move towards each
>other?

>I really need help with this, and I'm sure Wayne does too,
>please help anyone!

The original solution was the winner. Once I saw my mistake I made a
simple view with 4 separate textured meshes all rotating in various
directions. What you do is set up your world view matrix and then draw
the mesh. Then change the world view for the x,y,z location of the next
mesh and draw it. You can then reset your world view back to the
original view (although I didn't) and you will see your objects in their
various locations or (in my case) moving in different directions or
along different axis.

The render code looked like this:

        For b = 0 To 3
                  'Set our view
            SetupMatrices (b + 1)
                  'Draw the mesh w/textures
            For i = 0 To g_NumMaterialsx(b) - 1
                g_D3DDevice.SetMaterial g_MeshMaterialsx(b, i)
                g_D3DDevice.SetTexture 0, g_MeshTexturesx(b, i)
                g_Meshx(b).DrawSubset i
            Next i
        Next b

My SetupMatrices function is the standard sub you find in the SDK
examples except I added a variable to alter the x,y,z according to the
number I fed to the function.

Wayne



Wed, 28 Apr 2004 09:00:40 GMT  
 
 [ 11 post ] 

 Relevant Pages 

1. Moving mesh?

2. NewbieQ - Moving a loaded mesh

3. Move a mesh

4. Mesh Names or Mesh Subset Names

5. Mesh Picking, Boned Animation, Faked Meshes

6. Progressive meshes / Simplifying meshes

7. Mesh generation

8. Shaded Mesh over VB5 forms?

9. How to get the W component from a Mesh

10. Rotate A Mesh : Precudure

11. Transform Vector or Mesh(Not addressed here)

12. resizing mesh's Vertex buffer

 

 
Powered by phpBB® Forum Software