00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
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
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
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