Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

Demo3DCursor.cpp

Go to the documentation of this file.
00001 /*
00002 CS Senior Project 2003
00003 Team : Leftfield
00004 Project : ModernWarfare
00005 Members :
00006 - Russ Christensen              <rchriste@cs.utah.edu>
00007 - Todd Smith                    <tcsmith@cs.utah.edu>
00008 - Usit Duongsaa                 <duongsaa@cs.utah.edu>
00009 Copyright 2003 Russ Christensen, Usit Duongsaa, and Todd Smith. All rights reserved.
00010 
00011 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
00012 
00013 Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 
00014 Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 
00015 THIS SOFTWARE IS PROVIDED BY RUSS CHRISTENSEN, USIT DUONGSAA, AND TODD SMITH ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL RUSS, USIT, TODD OR OTHER CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
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         //mouseCursor = load_texture("textures\\interface\\mouseCursors.tga");
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         // camera control
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         // mouse cursor
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

Generated on Wed Apr 23 05:50:15 2003 for Modern Warfare by doxygen1.3-rc2