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

ACamera.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 
00022 #include "AEngine.h"
00023 #include "AUtil.h"
00024 
00026 void camera_set( const Vec3D pos,  const Vec3D target, const FLOAT smoothness )
00027 {
00028         assert( 0<=smoothness && smoothness<=1 && "camera smoothness must be between 0,1");     
00029         AS.camera_pos    = smoothness*AS.camera_pos    + (1.0f-smoothness)*pos;
00030         AS.camera_target = smoothness*AS.camera_target + (1.0f-smoothness)*target;
00031 
00032         // apply vibration
00033         FLOAT accel = - AS.camera_vibratePos * 5.7f;
00034         AS.camera_vibrateSpeed  += accel;
00035         AS.camera_vibrateSpeed  *= 0.96f;
00036         AS.camera_vibratePos    += AS.camera_vibrateSpeed * 0.4f;       
00037         AS.camera_pos.z += AS.camera_vibratePos * 0.05f;
00038         AS.camera_target.z += AS.camera_vibratePos * 0.05f;
00039 
00040         // prevents looking straight down
00041         if( AS.camera_pos[0]==AS.camera_target[0] && AS.camera_pos[1]==AS.camera_target[1] )
00042                 AS.camera_pos[1] += 0.00001f;
00043         
00044         const Vec3D upAxis( 0.0f, 0.0f, 1.0f );
00045         D3DXMatrixLookAtLH(&AS.camera_viewMatrix, &AS.camera_pos, &AS.camera_target, &upAxis );
00046         D3DXMatrixPerspectiveFovLH( &AS.camera_projMatrix, D3DXToRadian(60), 1.33333f, 0.1f, 1000.0f );
00047 
00048         AS.camera_world2projMatrix = AS.camera_viewMatrix * AS.camera_projMatrix;       
00049 }
00051 Vec3D camera_getPos()
00052 {
00053         return AS.camera_pos;
00054 }
00056 Vec3D camera_getVec()
00057 {
00058         Vec3D dir = AS.camera_target - AS.camera_pos;
00059         FLOAT len = D3DXVec3Length(&dir);
00060         return dir * 1.0f/len;
00061 }
00063 void camera_setScreenSize( FLOAT size )
00064 {
00065         assert( size>0.0f && size<=1.0f );
00066         AS.camera_screenSize = size;
00067 }
00068 //------------------------------------------------------------------------------------
00069 void camera_addVibration(float amount)
00070 {
00071         amount = absf(amount);
00072         if( AS.camera_vibrateSpeed > 0 )
00073                 AS.camera_vibrateSpeed += amount;
00074         else
00075                 AS.camera_vibrateSpeed -= amount;
00076 }
00077 //------------------------------------------------------------------------------------

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