Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

sabotask8

scaling a mesh

This topic is 5182 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Advertisement
Just set the mesh''s world transform to have a scaling in it as well. That should do the trick. The following is an example of how to scale a mesh to be twice as big as it is originally and to render it at position (x,y,z):

D3DMATRIXA16 matWorld, matTranslate, matScale;
D3DXMatrixScaling( &matScale, 2.0f, 2.0f, 2.0f );
D3DXMatrixTranslation( &matTranslate, x, y, z );
matWorld = matScale * matTranslate;
m_pd3dDevice->SetTransform( D3DTS_WORLD, &matWorld );
model->Render();

Hope this helps,
neneboricua

Share this post


Link to post
Share on other sites
Scale Mesh for:
Visual Basic .NET (VB.NET) language.

' HOWTO Use:
' Create object from class to manipulate our mesh.
Dim objMeshUtilities As New DxUtilities.Mesh
' Scale mesh 2.5 times.
objMeshUtilities.MeshScale(objMyMesh, 2.5)
' Scale mesh 0.3 times.
objMeshUtilities.MeshScale(objMyOtherMesh, 0.3)

Create Class: DxEnumerations

Imports DirectX = Microsoft.DirectX
Imports Direct3D = Microsoft.DirectX.Direct3D
Public Class DxEnumerations

' Custom D3D vertex format used by the vertex buffer
Public Structure MeshVertex
' Vertex position.
Public p As DirectX.Vector3
' Vertex Normal.
Public n As DirectX.Vector3
' Texture (u,v) co-ordinates.
Public tu, tv As Single
Public Const Format As Direct3D.VertexFormats = Direct3D.VertexFormats.Position Or Direct3D.VertexFormats.Normal Or Direct3D.VertexFormats.Texture1
End Structure 'MeshVertex

End Class

Create class: DxUtilities.Mesh
    
Imports DirectX = Microsoft.DirectX
Imports Direct3D = Microsoft.DirectX.Direct3D
Namespace DxUtilities
Public Class Mesh

' Function to rescale mesh.
Public Sub MeshScale(ByRef objValMesh As Direct3D.Mesh, ByVal sngValScale As Single)
' Get access to the mesh vertices.
Dim objVertexBuffer As Direct3D.VertexBuffer
objVertexBuffer = objValMesh.VertexBuffer
' Get number of Vertices inside mesh.
Dim intVertices As Integer = objValMesh.NumberVertices
' Declare array to store mesh verticles.
Dim arrMeshVertices() As DxEnumerations.MeshVertex
' Get verticles from the mesh.
Dim typMeshVertex As Type = GetType(DxEnumerations.MeshVertex)
arrMeshVertices = objVertexBuffer.Lock(0, typMeshVertex, 0, intVertices)
' Route thru verticles and scale them (ajust coordinates).
Dim intIndex As Integer
For intIndex = 0 To intVertices - 1
' ReScale Vertex position.
arrMeshVertices(intIndex).p.X *= sngValScale
arrMeshVertices(intIndex).p.Y *= sngValScale
arrMeshVertices(intIndex).p.Z *= sngValScale
' ReScale Vertex normal.
arrMeshVertices(intIndex).n.X *= sngValScale
arrMeshVertices(intIndex).n.Y *= sngValScale
arrMeshVertices(intIndex).n.Z *= sngValScale
Next intIndex
objVertexBuffer.Unlock()
objVertexBuffer.Dispose()
End Sub

End Class
End Namespace


[edited by - EJocys on April 13, 2004 2:46:38 PM]

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!