1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
|
#include "Engine.h"
#include "Matrix.h"
#include "Vector.h"
using namespace std;
using namespace Octane;
Font *font=NULL;
bool game_preload()
{
g_engine->setAppTitle("Math Matrix Demo");
g_engine->setScreen(1024,768,32,false);
return true;
}
bool game_init(HWND hwnd)
{
font = new Font( "Arial Bold", 18);
if (!font)
{
debug << "Error creating font" << endl;
return false;
}
return true;
}
void game_end()
{
if (font) delete font;
}
void game_update( float elapsedTime ) {}
void game_render3d() {}
std::string Vector2ToString( Vector2& V )
{
ostringstream out;
out << V.getX() << ", " << V.getY();
return out.str();
}
std::string Vector3ToString( Vector3& V )
{
ostringstream out;
out << V.getX() << ", " << V.getY() << ", " << V.getZ();
return out.str();
}
std::string MatrixToString( D3DXMATRIX& M )
{
ostringstream out;
out << M._11 << ", " << M._12 << ", " << M._13 << ", " << M._14 << endl;
out << M._21 << ", " << M._22 << ", " << M._23 << ", " << M._24 << endl;
out << M._31 << ", " << M._32 << ", " << M._33 << ", " << M._34 << endl;
out << M._41 << ", " << M._42 << ", " << M._43 << ", " << M._44;
return out.str();
}
void game_render2d()
{
std::ostringstream out;
out.setf(ios::fixed);
out << setprecision(2);
Matrix A;
A.setIdentity();
A *= 1.25f;
out << "Matrix A * 1.25 = " << endl << MatrixToString(A) << endl << endl;
Matrix B;
B.Fill( 12.875 );
out << "Matrix B = " << endl << MatrixToString(B) << endl << endl;
A += B;
out << "Matrix A + B = " << endl << MatrixToString(A) << endl << endl;
Matrix C = B * 2.75;
out << "Matrix C = B * 2.75 : " << endl << MatrixToString(C) << endl << endl;
D3DXMATRIX D;
D3DXMatrixRotationX( &D, 3.14f );
//instantiating a Matrix on the heap
Matrix *E = new Matrix( D );
out << "Matrix E = D (D3DXMATRIX copy) : " << endl << MatrixToString( *E ) << endl << endl;
E->setIdentity();
E->Translate( 1, -2, 3 );
out << "E -> Translated (1, -2, 3) = " << endl << MatrixToString( *E ) << endl << endl;
font->Print(0, 0, out.str());
//Start second column
out.str( "" );
E->Scale( 1, -2, 3 );
E->rotateX( 1 );
out << "E -> RotateX(1) = " << endl << MatrixToString( *E ) << endl << endl;
E->rotateY( -2 );
out << "E -> RotateY(-2) = " << endl << MatrixToString( *E ) << endl << endl;
E->rotateZ( 3 );
out << "E -> RotateZ(3) = " << endl << MatrixToString( *E ) << endl << endl;
E->rotateYawPitchRoll( 1, -2, 3 );
out << "E-> RotateYawPitchRoll(1, -2, 3) = " << endl << MatrixToString( *E ) << endl << endl;
delete E;
font ->Print(400, 0 , out.str() );
}
void game_event( IEvent* e )
{
switch( e->getID() )
{
case EVENT_KEYPRESS:
{
KeyPressEvent* evt = (KeyPressEvent*) e;
if (evt->keycode == DIK_ESCAPE)
g_engine->Shutdown();
break;
}
}
}
|