00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00023 #include "WinMainSelector.h"
00024 #if defined COMPILE_DEMO3DCURSOR
00025
00026 #include "..\AEngine\AEngine.h"
00027
00028 namespace {
00029 ATexture terrainTexture = NULL;
00030 AMesh terrainMesh = NULL;
00031
00032 ATexture mouseCursor = NULL;
00033 ATexture tankTexture = NULL;
00034 AMesh tankMesh = NULL;
00035 AMesh turretMesh = NULL;
00036 FLOAT camTheta, camRadius, camHeight;
00037 Vec3 tankPos;
00038 FLOAT tankTheta, turretTheta;
00039
00040 Vec2 mouse2D;
00041 Vec3 mouse3D;
00042 }
00043
00044
00045 void init()
00046 {
00047 sys_showConsole(true);
00048
00049 terrainTexture = load_texture("textures\\environment\\terrain_mixed.tga");
00050 terrainMesh = load_mesh("models\\environment\\terrain_box.obj");
00051
00052
00053 mouseCursor = load_texture("textures\\interface\\cursor.dds");
00054 tankTexture = load_texture("textures\\units\\tank_light.tga");
00055 tankMesh = load_mesh("models\\parts\\tank_light_chasis.obj");
00056 turretMesh = load_mesh("models\\parts\\tank_light_turret.obj");
00057
00058 camTheta = 0.0f;
00059 camRadius = 30.0f;
00060 camHeight = 10.0f;
00061
00062 tankPos = Vec3D(0.0f,0.0f,0.0f);
00063 tankTheta = turretTheta = 0.0f;
00064 }
00065
00066 void update()
00067 {
00068 Vec3D camPos( cosf(camTheta)*camRadius, sinf(camTheta)*camRadius, camHeight );
00069 const Vec3D origin(0.0f,0.0f,0.0f);
00070 camera_set( camPos, origin, 0.1f );
00071
00072
00073 if( input_isKeyDown(KeyCodes::key_LEFT) ) camTheta -= 0.05f;
00074 if( input_isKeyDown(KeyCodes::key_RIGHT) ) camTheta += 0.05f;
00075 if( input_isKeyDown(KeyCodes::key_UP) ) camRadius -= 0.3f;
00076 if( input_isKeyDown(KeyCodes::key_DOWN) ) camRadius += 0.3f;
00077 if( input_isKeyDown(KeyCodes::key_PRIOR) ) camHeight += 0.3f;
00078 if( input_isKeyDown(KeyCodes::key_NEXT) ) camHeight -= 0.3f;
00079
00080 mouse2D = Vec2D( input_getMouseX(),input_getMouseY() );
00081 mouse3D = math_translateScreenToWorldPlane( mouse2D, 0.0f );
00082
00083 }
00084
00085 void render()
00086 {
00087 overlay_text() << "Use the arrow keys and the PgUp/PgDown to control CAMERA" << endl;
00088 overlay_textOut( Vec2D(0.0f,0.0f), 1.0f );
00089
00090 const Vec3D tankSize( 4.0f, 2.0f, 0.1f );
00091 const Vec3D turretSize( 3.7f, 1.7f, 0.1f );
00092
00093 mesh_render( tankMesh, tankPos, tankSize, Vec3D(tankTheta,90.0f,0.0f), tankTexture );
00094 mesh_render( turretMesh, tankPos, turretSize, Vec3D(tankTheta+turretTheta,90.0f,0.0f), tankTexture );
00095
00096 mesh_render( terrainMesh, Vec3D(0,0,-1.2f), Vec3D(30.0f,30.0f,1.0f), Vec3D(0,0,0), terrainTexture );
00097
00098
00099 const FLOAT cursorSize = 0.05f;
00100 overlay_image( mouseCursor, mouse2D+Vec2D(cursorSize/2,cursorSize/2), Vec2D(cursorSize,cursorSize), BlendModes::KEY );
00101
00102 overlay_text() << "Mouse Cursor in 3D = " << mouse3D[0] << " " << mouse3D[1] << " " << mouse3D[2];
00103 overlay_textOut( Vec2D(0.0f, 0.1f) );
00104
00105 overlay_text() << "Mouse Cursor in 2D = " << input_getMouseX() << " " << input_getMouseY();
00106 overlay_textOut( Vec2D(0.0f, 0.2f) );
00107
00108 Vec2D p = math_translateWorldToScreen( Vec3D(2.0f,1.0f,0.0f) );
00109 overlay_text() << "Test Point= " << p[0] << " " << p[1];
00110 overlay_textOut( Vec2D(0.0f, 0.4f) );
00111 }
00112
00113 INT WINAPI WinMain( HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR, INT )
00114 {
00115 sys_init(hInst,800,600,32,false);
00116 sys_setInitFunc(init);
00117 sys_setUpdateFunc(update);
00118 sys_setRenderFunc(render);
00119 sys_go();
00120 return 0;
00121 }
00122
00123 #endif