Click here to Skip to main content
15,897,371 members
Articles / Programming Languages / C#

Managed DirectX Tutorials: Part 4 - The Transformation Pipeline

Rate me:
Please Sign up or sign in to vote.
3.73/5 (8 votes)
24 May 2006CPOL9 min read 83.2K   404   38  
Set up a robust framework for creating manipulatable 3D objects
using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using Microsoft.DirectX.Direct3D;
using Microsoft.DirectX;

namespace DXCore_1
{
    public class cObject
    {     
        public CustomVertex.PositionColored[] itsVerts;
        public Texture itsTexture;
        public Matrix itsTransform;
        public bool isActive;
    }

    public class cTriangle : cObject
    {
        public cTriangle(bool ac, Vector3 Translation, Vector3 Scale, Vector3 Rotation,Color pColor)
        {
            itsVerts = new CustomVertex.PositionColored[3];
            Matrix T = Matrix.Translation(Translation);
            Matrix S = Matrix.Scaling(Scale);
            Matrix Rx = Matrix.RotationX(Rotation.X);
            Matrix Ry = Matrix.RotationY(Rotation.Y);
            Matrix Rz = Matrix.RotationZ(Rotation.Z);
            itsTransform = Rx * Ry * Rz * T * S;
            isActive = ac;
           
            itsVerts[0] = new CustomVertex.PositionColored(new Vector3(0, 0, 0), pColor.ToArgb());
            itsVerts[1] = new CustomVertex.PositionColored(new Vector3(2, 0, 0), pColor.ToArgb());
            itsVerts[2] = new CustomVertex.PositionColored(new Vector3(1, 2, 0), pColor.ToArgb());
        }

        public void Render(Device device)
        {
            device.Transform.World = itsTransform;
            device.DrawUserPrimitives(PrimitiveType.TriangleList, 1, itsVerts);
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
CEO Synap
United Kingdom United Kingdom
Founder & CEO of Synap, an online education platform that uses machine learning to help people learn more in less time.

Software developer, main languages currently are Objective-C, MySQL and Javascript, though I got started on C++, C# and PHP.

Comments and Discussions