Direct3D translating and scaling

This is a discussion on Direct3D translating and scaling within the Game Programming forums, part of the General Programming Boards category; My Direct3D scene has two cubes, defined by the same vertex array. The first cube centers around the origin and ...

  1. #1
    mustang benny bennyandthejets's Avatar
    Join Date
    Jul 2002
    Posts
    1,401

    Direct3D translating and scaling

    My Direct3D scene has two cubes, defined by the same vertex array. The first cube centers around the origin and has side lengths of 2 units, ie, it is bordered in each dimension by -1.0 and 1.0. I then translate 4.0 units in the X direction, scale by 0.5 in the X direction, and draw the cube again. I would have thought the two cubes should be touching, but they don't, there is a little gap between them. Is there some geometric flaw I am not seeing here?

    Code:
    device.DrawUserPrimitives(PrimitiveType.TriangleList,10,CubeVerts);
    device.Transform.World=Matrix.Translation(4.0f,0.0f,0.0f)*Matrix.Scaling(0.5f,1.0f,1.0f);
    device.DrawUserPrimitives(PrimitiveType.TriangleList,10,CubeVerts);
    benforbes@optusnet.com.au
    Microsoft Visual Studio .NET 2003 Enterprise Architect
    Windows XP Pro

    Code Tags
    Programming FAQ
    Tutorials

  2. #2
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,590
    Code:
    device.DrawUserPrimitives(PrimitiveType.TriangleLi  st,10,CubeVerts);
    device.Transform.World=Matrix.Translation(4.0f,0.0  f,0.0f)*Matrix.Scaling(0.5f,1.0f,1.0f);
    device.DrawUserPrimitives(PrimitiveType.TriangleLi  st,10,CubeVerts);
    Not familiar with any of those functions in DX9 under C++.

  3. #3
    mustang benny bennyandthejets's Avatar
    Join Date
    Jul 2002
    Posts
    1,401
    It's C#, but that doesn't matter. Translating and scaling works the same no matter what language you use. But don't worry about it, I worked it out. The translation should have been 3.0 units not 4.0.
    benforbes@optusnet.com.au
    Microsoft Visual Studio .NET 2003 Enterprise Architect
    Windows XP Pro

    Code Tags
    Programming FAQ
    Tutorials

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21