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

AInput.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 "AEngine.h"
00024 #include "AState.h"
00025 
00026 const FLOAT mouseSpeed = 2.5f;
00027 
00028 //------------------------------------------------------------------------------------
00029 void input_init()
00030 {
00031         DWORD rc = AS.ndxInput.Create( AS.hInst, AS.hWnd );
00032         if(rc!=NDXERR_OK) throw Error("Please do not switch application while game is loading.  Try again");
00033         ZeroMemory( AS.keyDownLastCycle, sizeof(AS.keyDownLastCycle) );
00034         ZeroMemory( AS.keyDownThisCycle, sizeof(AS.keyDownThisCycle) ); 
00035         input_resetVKeyMapping();
00036 
00037         AS.ndxInput.MouseLimit.left   = 0;
00038         AS.ndxInput.MouseLimit.right  = (int)(AS.windowWidth /mouseSpeed);
00039         AS.ndxInput.MouseLimit.top    = 0;
00040         AS.ndxInput.MouseLimit.bottom = (int)(AS.windowHeight/mouseSpeed);
00041 
00042         AS.input_mouseWheel = 0.5f;
00043 }
00044 //------------------------------------------------------------------------------------
00045 bool input_isKeyDown    ( int key )
00046 {
00047         return AS.keyDownThisCycle[key];
00048 }
00049 //------------------------------------------------------------------------------------
00050 bool input_isKeyPressed ( int key )
00051 {
00052         return !AS.keyDownLastCycle[key] && AS.keyDownThisCycle[key];
00053 }
00054 //------------------------------------------------------------------------------------
00055 bool input_isKeyReleased( int key )
00056 {
00057         return AS.keyDownLastCycle[key] && !AS.keyDownThisCycle[key];
00058 }
00059 //------------------------------------------------------------------------------------
00060 void input_resetVKeyMapping()
00061 {
00062         for( int i=0; i<MAX_KEY; i++ )
00063                 AS.VKmapping[i] = i;
00064 }
00065 //------------------------------------------------------------------------------------
00066 void input_mapVKey( int key, int VKey )
00067 {
00068         assert( key>=0  && key<MAX_KEY );
00069         assert( VKey>=0 && VKey<MAX_KEY );
00070         AS.VKmapping[VKey] = key;
00071 }
00072 //------------------------------------------------------------------------------------
00073 bool input_isVKeyDown      ( int VKey )
00074 {
00075         return input_isKeyDown( AS.VKmapping[VKey] );
00076 }
00077 //------------------------------------------------------------------------------------
00078 bool input_isVKeyPressed ( int VKey )
00079 {
00080         return input_isKeyPressed( AS.VKmapping[VKey] );
00081 }
00082 //------------------------------------------------------------------------------------
00083 bool input_isVKeyReleased( int VKey )
00084 {
00085         return input_isKeyReleased( AS.VKmapping[VKey] );
00086 }
00087 //------------------------------------------------------------------------------------
00088 // Mouse Stuffs
00089 //------------------------------------------------------------------------------------
00090 bool input_isMouseLBDown()
00091 {
00092         return AS.ndxInput.MouseLB;
00093 }
00094 //------------------------------------------------------------------------------------
00095 bool input_isMouseMBDown()
00096 {
00097         return AS.ndxInput.MouseMB;
00098 }
00099 //------------------------------------------------------------------------------------
00100 bool input_isMouseRBDown()
00101 {
00102         return AS.ndxInput.MouseRB;
00103 }
00104 //------------------------------------------------------------------------------------
00105 bool input_isMouseLBClicked()
00106 {
00107         return AS.ndxInput.MouseLBClick;
00108 }
00109 //------------------------------------------------------------------------------------
00110 bool input_isMouseMBClicked()
00111 {
00112         return AS.ndxInput.MouseMBClick;
00113 }
00114 //------------------------------------------------------------------------------------
00115 bool input_isMouseRBClicked()
00116 {
00117         return AS.ndxInput.MouseRBClick;
00118 }
00119 //------------------------------------------------------------------------------------
00120 bool input_isMouseLBDblClicked()
00121 {
00122         return AS.ndxInput.MouseLBDblClick;
00123 }
00124 //------------------------------------------------------------------------------------
00125 bool input_isMouseMBDblClicked()
00126 {
00127         return AS.ndxInput.MouseMBDblClick;
00128 }
00129 //------------------------------------------------------------------------------------
00130 bool input_isMouseRBDblClicked()
00131 {
00132         return AS.ndxInput.MouseRBDblClick;
00133 }
00134 //------------------------------------------------------------------------------------
00135 float input_getMouseX()
00136 {
00137         FLOAT x = AS.ndxInput.MouseXPos *mouseSpeed / AS.windowWidth;
00138         //x = 0.5f + (x-0.5f)*2.0f;
00139         if( x<0 ) x=0; else if (x>1) x=1;
00140         return x;
00141 }
00142 //------------------------------------------------------------------------------------
00143 float input_getMouseY()
00144 {
00145         FLOAT y = AS.ndxInput.MouseYPos *mouseSpeed / AS.windowHeight;
00146         //y = 0.5f + (y-0.5f)*2.0f;
00147         if( y<0 ) y=0; else if (y>1) y=1;
00148         return y;
00149 }
00150 //------------------------------------------------------------------------------------
00151 float input_getMouseWheel()
00152 {
00153         return AS.input_mouseWheel;
00154 }
00155 //------------------------------------------------------------------------------------
00156 float input_mouseIdleTime()
00157 {
00158         return AS.input_mouseIdleTickCount / 62.5f;
00159 }
00160 //------------------------------------------------------------------------------------
00161 

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