 |
 |
Member Community Game Development, 3D Modeling, Art, Sound Effects and more
|
 |
 |
 |
 |
|
 |
 |
 |
 |
 |
skilz80

Joined: 16 Aug 2008 Posts: 58
 |
Posted: Wed Dec 23, 2009 7:29 pm Post subject: Vector4 instead of Vector3 and Vertex3 ? |
 |
|
Here I wrote this class and I am looking for feed back on its implementation. I do have a few questions about it which I will ask after I show the code below.
----------------------------------------------------------- Vector4.h -----------------------------------------------------------
| Code: |
#ifndef VECTOR4_H
#define VECTOR4_H
enum VEC4_Type
{
VEC4_VECTOR = 0,
VEC4_POINT = 1,
VEC4_TRANSFORM
};
class Vector4
{
public:
// Constructors And Destructors //
// ---------------------------------------------------------------------------- //
// Name: Vector4()
// Desc: Default Constructor: Set Vector To Default Zero Values
// Set Type To Either Vector, Point Or Transformation
// ---------------------------------------------------------------------------- //
inline Vector4( VEC4_Type v4Type )
{
m_V4_Type = v4Type;
m_f4[0] = 0.0f;
m_f4[1] = 0.0f;
m_f4[2] = 0.0f;
m_f4[3] = (float)m_V4_Type;
} // Vector4
// ---------------------------------------------------------------------------- //
// Name: Vector4()
// Desc: Default Constructor: Set Vector To Desired Values From User
// Set Type To Either Vector, Point or Transformation
// ---------------------------------------------------------------------------- //
inline Vector4( float f4[4], VEC4_Type v4Type )
{
m_V4_Type = v4Type;
switch ( m_V4_Type )
{
case VEC4_VECTOR:
{
m_f4[3] = 0.0f;
break;
}
case VEC4_POINT:
{
m_f4[3] = 1.0f;
break;
}
case VEC4_TRANSFORM:
{
if ( (VEC4_VECTOR != 1) && (VEC4_POINT != 0) )
{
// Do Some Work Here: Transformations To
// Vectors Or Points Use Either Switch Or If Statesments
// Depending On The Type[/color]
break;
}
}
}
// Set Each Parameter Of The Vector Array To Desired Values,
// Parameter 4 Is Already Set From Constructor[/color]
for ( int i = 0; i <= 2; ++i )
{
if ( f4[i] <= 0 )
{
m_f4[i] = 0;
return;
}
else
{
m_f4[i] = f4[i];
return;
}
}
} // Vector4
// Default Destructor //
virtual ~Vector4();
// Inline Function : Uncomment For Its Use //
// ---------------------------------------------------------------------------- //
// Name: GetType()
// Desc: Return The Type Should It Be Vector Point Or Transform
// ---------------------------------------------------------------------------- //
/* inline VEC4_Type GetType()
{
return m_V4_type;
} // GetType */
private:
// Private Member Variables
float m_f4[4];
VEC4_Type m_V4_Type;
};
#endif // VECTOR4_H
|
The cpp file has an empty destructor
A few questions:
1. The way this is implemented, once the user sets the type, will this class prevent the fourth parameter of m_f4[3] (being the Type) from changing?
2. In the second constructor when you create an instance of this class and create a Vector or Point by calling its constructor, can you set it such as Vector4( m_f4[] = { 1.0f, 1.0f, 1.0f }, TYPE ); where TYPE is synomous, or
would it be Vector4( m_f4[] = "1.0f, 1.0f, 1.0f ", TYPE ); or how Would you initialize it ?
My main purpose here is to contain both Vectors and Points(Vertexes) in a single class using a 4-tuplet for better memory management with the ability to do transformations to both the vector and point within the class's member variable array. Now I may have to create a member function to get the values so outside classes can use them, this is no problem. I should be able to implement this with no problem, but i may limit it to get only m_f4[0] - [2]
and omit the [3] and use a seperate function for this such as the one commented so that each time im doing transformations i don't have to worry about the type unless it is need to distinguish between a point and a vector. |
|
| |
|
|
|
 |
 |
 |
 |
 |
wolfscaptain
Joined: 15 Dec 2009 Posts: 2
 |
Posted: Fri Dec 25, 2009 8:36 pm Post subject: |
 |
|
You do realize that vectors and vertices are essentially represented in the same way, by 3 floats?
There's no point to start getting a headace just to seperate them (which goes to Marek too).
I just use vec2/3/4 for anything related (vectors, vertices, texture vertices, normals, etc.), since they are all the same. Just for convenience I like to typedef them with the fitting names.
And just to strengthen my point, once you start putting transformations, you'll need vector functions anyway. Scalar product and vector product are just too awesome  |
|
| |
|
|
|
 |
 |
 |
 |
 |
skilz80

Joined: 16 Aug 2008 Posts: 58
 |
Posted: Sun Dec 27, 2009 12:59 am Post subject: About Vectors And Vertexes Being The Same! |
 |
|
Yes I can see what you are saying, But what im trying to do here is create a 4-tuplet. After I did some research I found out that most CPUs prefer to read in floats of multiples of 4 not 3. I have 3 or 4 books that cover 3D Graphics And Physics engines and all of these authors prefer the 4-tuple instead of 3-tuple. "Given current CPUs and game consoles, it is better, though, to have 16-byte (4-float) alignment of data becuse the hardware expects it in order to perform well." (3D GameDesign SE, Eberly, p.17) "/** Padding to ensure 4-word alignment. */." (Game Physics Engine Development, Ian Millington, pg.17) Where the w-component must not be changed by an outside class or function. for example we have the 4 tuplet as being ( x,y,z,w ) now when we use this as a matrix to multiply by another matrix we can use a 4x4 matrix and this here will allow for quicker computation of doing transformations. This is where I am distinguishing between a point and a vector. With in the limits of Linear Algebra using Transformations Matrices and Affine Transformations we need this distinction. so for vectors the w-component must be 0, and for vertexes(points) the w-component must be 1. For higher-end calculations if the w-component is not 0 or 1, It usually implies a transformation of some type that deals with the clipping and back face culling processes.
This took a lot of work, and I still haven't implemented the operators, and calculation functions, but I will update this class as i go, once i reach a certain goal and made sure there are no bugs in the code. If you say any weak spots in this or things I can do to improve this please let me know.
This Is One Class That Represents Both Vertexes And Points For 2D, 3D And 4D Matrix Calculations and 2D,3D, And 4D Graphical Representation!
The code I originally posted above has been modified. I will supply the new class below along with a main.cpp file that you can copy and check out all the possible situations  |
|
| |
|
|
|
 |
 |
 |
 |
 |
skilz80

Joined: 16 Aug 2008 Posts: 58
 |
Posted: Sun Dec 27, 2009 2:20 am Post subject: Vector4 Revised! |
 |
|
Here Is The New Code! Hope You Enjoy!
I Have Added In Extra Functionallity As To Show You How The Class Works Even Though It Is Not Needed. For Example:
I Added In A Display Text Function And The 2 Enumerations To Work With The Function. They Are Not Really Needed. They Are Only Needed To Print The Correct Text With The Appropriate Types. It Will Not Hurt To Leave The Enumerations In The Class When Using In Your Own Game Engine As It Can Be Usefull With The Get And Set Functions For The TYPES, But You Should Remove The Display Text Function Calls In The Constructors. I Added Them To The Constructors To Make The main.cpp File A Little Less Combersome wtih Function Calls. If I Didn't Have This In The Constructors, I Would Of Had To Use This Function With Each "New" Instance Of The Vector4 Class.
As A Note: I Use The Term Transformation For The W-Component, This Is Mainly For The Use With Clipping And Culling Before Rasterizing To The Screen And Is Usefull With Vertex-Pixel Shaders And Some Other Functionalities Where The W-Component Does Not Equal 0 Or 1 In The 4-th Componet Of The Array(Vector or Point) Or In Very Last Element In The 4x4 Matrix.
The Header File
| Code: |
#ifndef VECTOR4_H
#define VECTOR4_H
// ================================================================================================
// FileName: Vector4.h
// Version: 2.0
// Copyright (c) 2010 by Franics R. Cugler Jr.
// http://souls-of-light.game-server.cc
// ================================================================================================
#include "stdio.h"
#include "windows.h"
enum VECTOR4_Type
{
VEC4_2D = 0,
VEC4_3D,
VEC4_4D
};
enum VECTOR4_VPT
{
VEC4_VECTOR = 0,
VEC4_POINT = 1,
VEC4_TRANSFORM
};
class Vector4
{
public:
// Constructors And Destructors //
// ------------------------------------------------------------------------------------------ //
// Name: Vector4()
// Desc: Default Constructor: Constructor A 2D, 3D, Or 4D Zero Vector (X,Y),(X,Y,Z),(X,Y,Z,W)
// Or A 2D Point Origin (X,Y) = (0,0),(0,0,0),(0,0,0,VPT) Where VPT Is VECTOR4_VPT Type.
// ------------------------------------------------------------------------------------------ //
inline Vector4( VECTOR4_Type V4_Type, VECTOR4_VPT V4_VPT )
{
m_V4_Type = V4_Type;
m_V4_VPT = V4_VPT;
switch ( m_V4_Type )
{
case VEC4_2D:
{
SetType( VEC4_2D );
m_fX = 0.0f;
m_fY = 0.0f;
if ( m_fZ )
{
m_fZ = NULL;
}
m_fW = (float)GetVPT();
//DisplayText();
break;
}
case VEC4_3D:
{
SetType( VEC4_3D );
m_fX = 0.0f;
m_fY = 0.0f;
m_fZ = 0.0f;
m_fW = (float)GetVPT();
//DisplayText();
break;
}
case VEC4_4D:
{
SetType( VEC4_4D );
m_fX = 0.0f;
m_fY = 0.0f;
m_fZ = 0.0f;
m_fW = (float)GetVPT();
//DisplayText();
break;
}
}
if ( m_V4_VPT == VEC4_VECTOR )
{
SetVPT( VEC4_VECTOR );
m_fW = 0.0f;
DisplayText();
}
if ( m_V4_VPT == VEC4_POINT )
{
SetVPT( VEC4_POINT );
m_fW = 1.0f;
DisplayText();
}
if ( m_V4_VPT == VEC4_TRANSFORM )
{
// More Code Here For Doing Transforms
SetVPT( VEC4_TRANSFORM );
DisplayText();
}
} // Vector4
// ------------------------------------------------------------------------------------------ //
// Name: Vector4()
// Desc: Default Constructor: Construct A 2D Vector Or Point Giving Two Values
// ------------------------------------------------------------------------------------------ //
inline Vector4( VECTOR4_VPT V4_VPT, float fX, float fY)
{
SetType( VEC4_2D );
m_V4_VPT = V4_VPT;
m_fX = fX;
m_fY = fY;
m_fZ = NULL;
m_fW = m_fW = (float)m_V4_VPT;
if ( m_V4_VPT == VEC4_VECTOR )
{
SetVPT( VEC4_VECTOR );
DisplayText();
}
if ( m_V4_VPT == VEC4_POINT )
{
SetVPT( VEC4_POINT );
DisplayText();
}
if ( m_V4_VPT == VEC4_TRANSFORM )
{
SetVPT( VEC4_TRANSFORM );
// More Code Here For Doing Transforms
DisplayText();
}
} // Vector4
// ------------------------------------------------------------------------------------------ //
// Name: Vector4()
// Desc: Default Constructor: Construct A 3D Vector Or Point Giving 3 Values
// ------------------------------------------------------------------------------------------ //
inline Vector4( VECTOR4_VPT V4_VPT, float fX, float fY, float fZ )
{
SetType( VEC4_3D );
m_V4_VPT = V4_VPT;
m_fX = fX;
m_fY = fY;
m_fZ = fZ;
m_fW = (float)m_V4_VPT;
if ( m_V4_VPT == VEC4_VECTOR )
{
SetVPT( VEC4_VECTOR );
DisplayText();
}
if ( m_V4_VPT == VEC4_POINT )
{
SetVPT( VEC4_POINT );
DisplayText();
}
if ( m_V4_VPT == VEC4_TRANSFORM )
{
SetVPT( VEC4_TRANSFORM );
// More Code Here For Doing Transforms
DisplayText();
}
} // Vector4
// ------------------------------------------------------------------------------------------ //
// Name: Vector4()
// Desc: Default Constructor: Construct A 3D Vector Or Point
// Giving 3 Values And A Transformation
// ------------------------------------------------------------------------------------------ //
inline Vector4( VECTOR4_VPT V4_VPT, float fX, float fY, float fZ, float fW )
{
SetType( VEC4_4D );
m_V4_VPT = V4_VPT;
m_fX = fX;
m_fY = fY;
m_fZ = fZ;
m_fW = fW;
if ( ((int)(m_fW)) == VEC4_VECTOR )
{
SetVPT( VEC4_VECTOR );
DisplayText();
}
else if ( ((int)(m_fW)) == VEC4_POINT )
{
SetVPT( VEC4_POINT );
DisplayText();
}
else
{
SetVPT( VEC4_TRANSFORM );
// More Code Here For Doing Transforms
DisplayText();
}
} // Vector4
// Defaualt Destructor //
virtual ~Vector4();
// ------------------------------------------------------------------------------------------ //
// Name: GetType()
// Desc: Return The Type Should It Be Vector2 Vector3 Or Vector4
// ------------------------------------------------------------------------------------------ //
inline VECTOR4_Type GetType()
{
return m_V4_Type;
} // GetType
// ------------------------------------------------------------------------------------------- //
// Name: SetType()
// Desc: Set The Type To Either A Vector2 Vector3 Or Vector4
// ------------------------------------------------------------------------------------------- //
inline void SetType( VECTOR4_Type V4_Type )
{
m_V4_Type = V4_Type;
} // Set Type
// ------------------------------------------------------------------------------------------ //
// Name: GetVPT()
// Desc: Return If Vector Point Or Transform
// ------------------------------------------------------------------------------------------ //
inline VECTOR4_VPT GetVPT( )
{
return m_V4_VPT;
} // GetVPT
// ------------------------------------------------------------------------------------------- //
// Name: SetVTP()
// Desc: Set VTP To Either Vector Point Or Transform
// ------------------------------------------------------------------------------------------- //
inline void SetVPT( VECTOR4_VPT V4_VPT )
{
m_V4_VPT = V4_VPT;
} // SetVPT
// ------------------------------------------------------------------------------------------- //
// Name: GetW()
// Desc: Get The Component Value
// ------------------------------------------------------------------------------------------- //
inline float GetW( )
{
return m_fW;
} // GetW
// ------------------------------------------------------------------------------------------- //
// Name: SetW()
// Desc: Set The W Component Value: Use This Function With Caution
// Use Only When You Want To Do A Transformation, Not When
// Creating A Vector Or Point(Vertex)
// ------------------------------------------------------------------------------------------- //
inline void SetW( float fW )
{
SetType( m_V4_Type );
m_fW = fW;
if ( (m_fW == 0.0f) || (m_fW == 0) )
{
m_V4_VPT = VEC4_VECTOR;
}
else if ( (m_fW == 1.0f) || (m_fW == 1) )
{
m_V4_VPT = VEC4_POINT;
}
else
{
m_V4_VPT = VEC4_TRANSFORM;
}
SetVPT( m_V4_VPT );
} // SetW
// ------------------------------------------------------------------------------------------- //
// Name: GetValue()
// Desc: Get A Floating Point Number
// ------------------------------------------------------------------------------------------- //
inline float GetValue( float fValue )
{
m_fValue = fValue;
return m_fValue;
} // GetValue
void DisplayText();
// Public Member Variables
union
{
m_f3[3];
struct
{
float m_fX;
float m_fY;
float m_fZ;
};
};
float m_fValue;
private:
// Private Member Variables
VECTOR4_Type m_V4_Type;
VECTOR4_VPT m_V4_VPT;
float m_fW;
};
#endif // VECTOR4_H
|
The CPP File
| Code: |
// ================================================================================================
// FileName: Vector4.cpp
// Version: 2.0
// Copyright (c) 2010 by Francis R. Cugler Jr.
// http://souls-of-light.game-server.cc
// ================================================================================================
#include "Vector4.h"
// ---------------------------------------------------------------------------------------------- //
// Name: ~Vector4()
// Desc: Default Destructor
// ---------------------------------------------------------------------------------------------- //
Vector4::~Vector4()
{
} // ~Vector4
// ---------------------------------------------------------------------------------------------- //
// Name: DisplayText()
// Desc: Display The Type As 2D,3D,4D and Display If It Is A Vector, Point Or Transform
// ---------------------------------------------------------------------------------------------- //
void Vector4::DisplayText()
{
m_V4_Type = GetType();
m_V4_VPT = GetVPT();
if ( m_V4_VPT == VEC4_TRANSFORM )
{
m_V4_Type = VEC4_4D;
}
switch ( m_V4_Type )
{
case VEC4_2D:
{
if ( (m_V4_Type == VEC4_2D) && (m_fZ == NULL) )
{
printf( "\nThis Is A 2D " );
}
else
{
printf( "\nThis Is Now A 3D Or 4D " );
}
}
case VEC4_3D:
{
if ( m_V4_Type == VEC4_3D )
{
printf ( "\nThis Is A 3D " );
}
}
case VEC4_4D:
{
if ( m_V4_Type == VEC4_4D )
{
printf( "\nThis Is A 4D " );
}
}
}
switch ( m_V4_VPT )
{
case VEC4_VECTOR:
{
if ( m_V4_VPT == VEC4_VECTOR )
{
printf( "Vector.\n" );
}
}
case VEC4_POINT:
{
if ( m_V4_VPT == VEC4_POINT )
{
printf( "Point.\n" );
}
}
case VEC4_TRANSFORM:
{
if ( m_V4_VPT == VEC4_TRANSFORM )
{
printf( "Transformation.\n" );
}
}
}
if ( (m_V4_Type == VEC4_2D) && (m_fZ == NULL) )
{
printf( "There Is No Z-Component In 2D.\n" );
printf( "If You Use The Z-Component By Default\nIt Is Set To NULL or 0.\n" );
}
} // DisplayText
|
The main.cpp File
| Code: |
// ============================================================================================== //
// FileName: main.cpp
// Version 2.0
// Copyright (c) 2010 by Francis R. Cugler Jr.
// http://souls-of-light.game-server.cc
// ============================================================================================== //
#include "Vector4.h"
Vector4 *m_pVector4;
int main()
{
// These Are Using The Zero Constructor
Vector4 *VecZero2D, *VecZero3D, *VecZero4D;
Vector4 *PointZero2D, *PointZero3D, *PointZero4D;
Vector4 *TransZero2D, *TransZero3D, *TransZero4D;
printf( "\nNOTE: I Use The Term Transformation Which Represents\nThe Clipping And Culling Process\nWhere The Calculations Are Done In the Transformation\nFrom World Space To Screen Space.\n" );
printf( "\nDISPLAY LIST FOR ZERO CONSTRUCTORS\n" );
// Vectors //
printf( "\nThese Are Vectors.\n" );
printf( "================================================================================" );
// 2D Vector
VecZero2D = new Vector4( VEC4_2D, VEC4_VECTOR );
printf( "The Parameters For Vector2D.\n" );
printf( "-----------------------------\n" );
printf( "( %.2f, %.2f ), W: %.2f\n", VecZero2D->m_fX, VecZero2D->m_fY, VecZero2D->GetW() );
printf( "Here I Will Show What Happens When You Display The Z-Component For A 2D Object.\n" );
printf( "For Example: (Im Only Showing This Once!)\n" );
printf( "VecZero2D->m_FZ = Z: %.2f\n\n", VecZero2D->m_fZ );
// 3D Vector
VecZero3D = new Vector4( VEC4_3D, VEC4_VECTOR );
printf( "The Parameters For Vector3D.\n" );
printf( "-----------------------------\n" );
printf( "( %.2f, %.2f, %.2f, %.2f )\n\n", VecZero3D->m_fX, VecZero3D->m_fY, VecZero3D->m_fZ, VecZero3D->GetW() );
// 4D Vector
VecZero4D = new Vector4( VEC4_4D, VEC4_VECTOR );
printf( "The Parameters For Vector4D.\n" );
printf( "-----------------------------\n" );
printf( "( %.2f, %.2f, %.2f, %.2f )\n\n", VecZero4D->m_fX, VecZero4D->m_fY, VecZero4D->m_fZ, VecZero4D->GetW() );
// Points //
printf( "\n\nThese Are Points.\n" );
printf( "================================================================================" );
// 2D Point
PointZero2D = new Vector4( VEC4_2D, VEC4_POINT );
printf( "The Parameters For Point2D.\n" );
printf( "-----------------------------\n" );
printf( "( %.2f, %.2f ), W: %.2f\n\n", PointZero2D->m_fX, PointZero2D->m_fY, PointZero2D->GetW() );
// 3D Point
PointZero3D = new Vector4( VEC4_3D, VEC4_POINT );
printf( "The Parameters For Point3D.\n" );
printf( "-----------------------------\n" );
printf( "( %.2f, %.2f, %.2f, %.2f )\n\n", PointZero3D->m_fX, PointZero3D->m_fY, PointZero3D->m_fZ, PointZero3D->GetW() );
// 4D Point
PointZero4D = new Vector4( VEC4_4D, VEC4_POINT );
printf( "The Parameters For Point4D.\n" );
printf( "-----------------------------\n" );
printf( "( %.2f, %.2f, %.2f, %.2f )\n\n", PointZero4D->m_fX, PointZero4D->m_fY, PointZero4D->m_fZ, PointZero4D->GetW() );
// Transformations //
printf( "\nThese Are Transforms.\n" );
printf( "================================================================================" );
// 2D Transform
TransZero2D = new Vector4( VEC4_2D, VEC4_TRANSFORM );
printf( "The Parameters For Transform2.\n" );
printf( "-----------------------------\n" );
printf( "( %.2f, %.2f ), W: %.2f\n\n", TransZero2D->m_fX, TransZero2D->m_fY, TransZero2D->GetW() );
// 3D Transform
TransZero3D = new Vector4( VEC4_3D, VEC4_TRANSFORM );
printf( "The Parameters For Transform3.\n" );
printf( "-----------------------------\n" );
printf( "( %.2f, %.2f, %.2f, %.2f )\n\n", TransZero3D->m_fX, TransZero3D->m_fY, TransZero3D->m_fZ, TransZero3D->GetW() );
// 4D Transform
TransZero4D = new Vector4( VEC4_4D, VEC4_TRANSFORM );
printf( "The Parameters For Transform4.\n" );
printf( "-----------------------------\n" );
printf( "( %.2f, %.2f, %.2f, %.2f )\n\n", TransZero4D->m_fX, TransZero4D->m_fY, TransZero4D->m_fZ, TransZero4D->GetW() );
printf( "================================================================================" );
// Contructors Setting Values //
Vector4 *Vec2D, *Point2D, *Trans2D;
Vector4 *Vec3D, *Point3D, *Trans3D;
Vector4 *Vec4D, *Vec4D2, *Point4D, *Point4D2, *Trans4D, *Trans4D2, *Trans4D3 ;
// Second Constructor
printf( "This Constructor Will Create A 2D (Vector, Point, And Transformation).\n" );
printf( "You Will Have To Set The Values For The X And Y Components.\n" );
printf( "================================================================================" );
Vec2D = new Vector4( VEC4_VECTOR, 5.5f, 7.25f );
printf( "( %.2f, %.2f ), W: %.2f\n", Vec2D->m_fX, Vec2D->m_fY, Vec2D->GetW() );
Point2D = new Vector4( VEC4_POINT, 3.7f, 2.99f );
printf( "( %.2f, %.2f ), W: %.2f\n", Point2D->m_fX, Point2D->m_fY, Point2D->GetW() );
Trans2D = new Vector4( VEC4_TRANSFORM, 4.3f, 2.4f );
if ( Trans2D->GetVPT() == VEC4_TRANSFORM )
{
Trans2D->SetW( 2.5f );
}
printf( "( %.2f, %.2f ), W: %.2f\n", Trans2D->m_fX, Trans2D->m_fY, Trans2D->GetW() );
printf( "\n================================================================================" );
// Third Constructor
printf( "This Constructor Will Create A 3D (Vector, Point, And Transformation).\n" );
printf( "You Will Have To Set The Values For The X, Y, And Z Components.\n" );
printf( "================================================================================" );
Vec3D = new Vector4( VEC4_VECTOR, 4.4f, 8.8f, -0.34f );
printf( "( %.2f, %.2f, %.2f, %.2f )\n", Vec3D->m_fX, Vec3D->m_fY, Vec3D->m_fZ, Vec3D->GetW() );
Point3D = new Vector4( VEC4_POINT, 2.4f, 3.2f, 8.74f );
printf( "( %.2f, %.2f, %.2f, %.2f )\n", Point3D->m_fX, Point3D->m_fY, Point3D->m_fZ, Point3D->GetW() );
Trans3D = new Vector4( VEC4_TRANSFORM, 4.2f, 2.4f, 2.5f );
if ( Trans3D->GetVPT() == VEC4_TRANSFORM )
{
Trans3D->SetW( 1.9f );
}
printf( "( %.2f, %.2f, %.2f, %.2f )\n", Trans3D->m_fX, Trans3D->m_fY, Trans3D->m_fZ, Trans3D->GetW() );
printf( "\n================================================================================" );
// Fourth Constructor
printf( "This Constructor Will Create A 4D (Vector And Point).\n" );
printf( "You Will Have To Set The Values For The X, Y, Z & W Components.\n" );
printf( "Here I Will Show Both Cases Of The Vector And Point Aspects Using\n"
"The W Component To Show That If W Is Not 0 Or 1 It Will Be A Transform.\n" );
printf( "================================================================================" );
Vec4D = new Vector4( VEC4_VECTOR, 4.4f, 8.8f, -0.34f, 0.0f );
printf( "( %.2f, %.2f, %.2f, %.2f )\n", Vec4D->m_fX, Vec4D->m_fY, Vec4D->m_fZ, Vec4D->GetW() );
Vec4D2 = new Vector4( VEC4_VECTOR, 4.4f, 8.8f, -0.34f, 3.0f );
printf( "( %.2f, %.2f, %.2f, %.2f )\n", Vec4D2->m_fX, Vec4D2->m_fY, Vec4D2->m_fZ, Vec4D2->GetW() );
Point4D = new Vector4( VEC4_POINT, 2.4f, 3.2f, 8.74f, 1.0f );
printf( "( %.2f, %.2f, %.2f, %.2f )\n", Point4D->m_fX, Point4D->m_fY, Point4D->m_fZ, Point4D->GetW() );
Point4D2 = new Vector4( VEC4_POINT, 2.4f, 3.2f, 8.74f, 4.2f );
printf( "( %.2f, %.2f, %.2f, %.2f )\n", Point4D2->m_fX, Point4D2->m_fY, Point4D2->m_fZ, Point4D2->GetW() );
printf( "\n================================================================================" );
printf ( "Here I Will Show 3 Cases Of The Transform Where\n"
"The Second Two I Set W To 0 And 1\n" );
printf( "================================================================================" );
Trans4D = new Vector4( VEC4_TRANSFORM, 4.2f, 2.4f, 2.5f, 2.9f );
printf( "( %.2f, %.2f, %.2f, %.2f )\n", Trans4D->m_fX, Trans4D->m_fY, Trans4D->m_fZ, Trans4D->GetW() );
Trans4D2 = new Vector4( VEC4_TRANSFORM, 4.2f, 2.4f, 2.5f, 0.0f );
printf( "( %.2f, %.2f, %.2f, %.2f )\n", Trans4D2->m_fX, Trans4D2->m_fY, Trans4D2->m_fZ, Trans4D2->GetW() );
Trans4D3 = new Vector4( VEC4_TRANSFORM, 4.2f, 2.4f, 2.5f, 1.0f );
printf( "( %.2f, %.2f, %.2f, %.2f )\n", Trans4D3->m_fX, Trans4D3->m_fY, Trans4D3->m_fZ, Trans4D3->GetW() );
printf( "\n================================================================================" );
printf( "This Case Is To Show You That When Creating A 2D or 3D Using Its\n"
"Constructor Then Using The SetW Function To Override The Parameter And\n"
"Watch The Class Change Its Type Dynamically. Even Changing\nFrom A Vector To Point\n" );
printf( "================================================================================" );
// Over Riding The Constructors //
Vector4 *Vec2OverRide;
Vec2OverRide = new Vector4( VEC4_VECTOR, 15.5f, 20.5f );
printf( "( %.2f, %.2f ), W:%.2f\n", Vec2OverRide->m_fX, Vec2OverRide->m_fY, Vec2OverRide->GetW() );
Vec2OverRide->SetW( 4.5f );
Vec2OverRide->DisplayText();
printf( "( %.2f, %.2f ), W:%.2f\n", Vec2OverRide->m_fX, Vec2OverRide->m_fY, Vec2OverRide->GetW() );
Vec2OverRide->SetW( 1.0f );
Vec2OverRide->DisplayText();
printf( "( %.2f, %.2f ), W:%.2f\n", Vec2OverRide->m_fX, Vec2OverRide->m_fY, Vec2OverRide->GetW() );
Vec2OverRide->SetType( VEC4_3D );
Vec2OverRide->m_fZ = 19.5f;
Vec2OverRide->DisplayText();
printf( "( %.2f, %.2f, %.2f, %.2f )\n", Vec2OverRide->m_fX, Vec2OverRide->m_fY, Vec2OverRide->m_fZ, Vec2OverRide->GetW() );
Vec2OverRide->SetW( 0.0f );
Vec2OverRide->DisplayText();
printf( "( %.2f, %.2f, %.2f, %.2f )\n", Vec2OverRide->m_fX, Vec2OverRide->m_fY, Vec2OverRide->m_fZ, Vec2OverRide->GetW() );
printf( "\nHere Is On Example Where I Will Allow You To Change The Parameter\nAs We Change This To A Transform4D.\n" );
printf( "Please Enter The Parameter For The W-Component\n" );
int iResult;
float fTemp;
iResult = scanf_s( "%f", &fTemp );
Vec2OverRide->SetVPT( VEC4_TRANSFORM );
Vec2OverRide->SetW( fTemp );
Vec2OverRide->DisplayText();
printf( "( %.2f, %.2f, %.2f, %.2f )\n\n", Vec2OverRide->m_fX, Vec2OverRide->m_fY, Vec2OverRide->m_fZ, Vec2OverRide->GetW() );
printf( "================================================================================" );
printf( "Here I Will Show You How To Convert From 2D-3D Explicitly\n" );
printf( "================================================================================" );
Vector4 *Test2D_To_3D;
printf( "Calling 2D-Zero Constructor Then Setting Each Parameter.\n" );
Test2D_To_3D = new Vector4( VEC4_2D, VEC4_VECTOR );
Test2D_To_3D->m_fX = 3.6f;
Test2D_To_3D->m_fY = 4.0f;
Test2D_To_3D->m_fZ = 6.4f;
printf( "%.2f, %.2f, %.2f\n", Test2D_To_3D->m_fX, Test2D_To_3D->m_fY, Test2D_To_3D->m_fZ );
Test2D_To_3D->DisplayText();
printf( "Now Adding In The W-Component\n" );
Test2D_To_3D->SetW( .25f );
printf( "W: %.2f\n", Test2D_To_3D->GetW() );
Test2D_To_3D->DisplayText();
printf( "Now To Reverse This Back To 2D By Setting Z & W To NULL" );
Test2D_To_3D->m_fZ = NULL;
Test2D_To_3D->SetW( NULL );
Test2D_To_3D->DisplayText();
printf( "Here To Recursively Go Back From 4D To 3D We Need To Reset The Type Manually.\n" );
Test2D_To_3D->SetType( VEC4_2D );
Test2D_To_3D->DisplayText();
getchar();
getchar();
delete VecZero2D;
delete VecZero3D;
delete VecZero4D;
delete PointZero2D;
delete PointZero3D;
delete PointZero4D;
delete TransZero2D;
delete TransZero3D;
delete TransZero4D;
delete Vec2D;
delete Point2D;
delete Trans2D;
delete Vec3D;
delete Point3D;
delete Trans3D;
delete Vec4D;
delete Vec4D2;
delete Point4D;
delete Point4D2;
delete Trans4D;
delete Trans4D2;
delete Trans4D3;
delete Vec2OverRide;
return 0;
}
|
ENJOY! |
|
| |
|
|
|
 |
 |
 |
 |
 |
|
 |
 |
 |
 |
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|
|
 |