MarekKnows Discussion Forum
http://marekknows.com/phpBB3/

GameDev VMK 4 - Vertex and Triangle Classes
http://marekknows.com/phpBB3/viewtopic.php?f=3&t=24
Page 1 of 1

Author:  Marek [ Tue Feb 13, 2007 7:01 am ]
Post subject:  XML library

Tutorial showing how to create a vertex and triangle class. These two classes are used to render objects on the screen.

Author:  Jasper [ Tue Jun 19, 2007 12:26 am ]
Post subject:  Re: GameDev VMK 4 - Vertex and Triangle Classes

In the triangle class you have three vertices as member variables, but often triangles often share their vertices,so I wonder, wouldn't it save space to have vertex pointers instead?



Of course this does need some extra programming skill later on... but I do not like to use more memory than necessary :D

Author:  Marek [ Tue Jun 19, 2007 5:54 am ]
Post subject:  Re: GameDev VMK 4 - Vertex and Triangle Classes

Yes that is true. You will notice that we actually stop using the triangle class and delete it from the project a little later on in the video series. There is a far better way to handle 3D data by creating custom 3d objects (like the house) or by loading in 3d data from a modeling software package (like trueSpace).

Author:  BugHunter [ Sun Aug 24, 2008 5:16 am ]
Post subject: 

-- a general note: most of methods should be made inline, which give to comppiler an oportunity to incorporate their bodies just in the code from where they were called and not to spend CPU cycles on invocation. To inline a function its body must be placed in header file etc.
-- initialization to zero (in default ctor) is not to be always good. The reason is that you spend CPU time on initialization but most likely you will never use those default values. Besides, remember tempory objects issue. That's not my advice but what they say on MS GameDev conference.

class Vertex
{
public:
    Vertex() { }
    Vertex(float x_, float y_, float z_) : x(x_), y(y_), z(z_) { }
//  virtual ~Vertex() { }
public:
    float x, y, z;
};

class Triangle
{
public:
    Triangle(const Vertex & _1, const Vertex & _2, const Vertex & _3, float angle_)
    :   v1(_1), v2(_2), v3(_3), angle(angle_)
    { }

    // virtual ~Triangle() { }

    void Update(float angle_) { angle += angle_; }

public:
    Vertex v1, v2, v3;
    float angle;
};

:roll:

Page 1 of 1 All times are UTC - 5 hours
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/