00001 #include "global.h"
00002 #include "MercuryDisplay.h"
00003 #include "ScreenODETest.h"
00004 #include "MercuryTheme.h"
00005 #include "MercuryInput.h"
00006 #include "MercuryUtil.h"
00007
00008 REGISTER_SCREEN_CLASS( ScreenODETest )
00009
00010 KeyMappingWithCode( button_a, "0-97" );
00011 KeyMappingWithCode( button_s, "0-115" );
00012 KeyMappingWithCode( button_d, "0-100" );
00013 KeyMappingWithCode( button_w, "0-119" );
00014
00015 ScreenODETest::~ScreenODETest( )
00016 {
00017 DISPLAY->RemoveLight(&m_light);
00018
00019 }
00020
00021 void ScreenODETest::Init()
00022 {
00023 MercuryScreen::Init();
00024
00025 MercuryINI pINI;
00026 pINI.Open( GET_FILE_BY_NAME( "IniFile" ) );
00027
00028 m_pWorld.Init();
00029 m_pWorld.LoadFromINI( pINI, THEME.GetMetricS( m_name, "WorldName" ) );
00030 AddPerspObject( &m_pWorld );
00031
00032 m_shpGround.SetName("Ground");
00033 m_shpGround.Init();
00034 m_shpGround.MakeSprite();
00035 m_shpGround.LoadImage( "GRAPHIC:ground2.png" );
00036 m_shpGround.SetScale( MercuryPoint( 900,900,0));
00037 AddPerspObject( &m_shpGround );
00038
00039 m_pCamera = new MercuryCamera;
00040 m_pCamera->SetName( "Camera" );
00041 m_pCamera->Init();
00042 m_pCamera->SetPosition( MercuryPoint( 500,100,900) );
00043 m_pCamera->SetUp(MercuryPoint(0,0,1));
00044 AddObject( m_pCamera );
00045
00046
00047
00048
00049 m_light.Init();
00050 m_light.SetY(100);
00051 m_light.SetX(-100);
00052 m_light.SetZ(110);
00053 m_light.SetAttenuation(0.001f, Attenuation::LINEAR);
00054 m_light.SetStatic(true);
00055 DISPLAY->AddLight(&m_light);
00056
00057 m_bFirstUpdate=true;
00058 }
00059
00060 void ScreenODETest::Update( const float dTime )
00061 {
00062 MercuryScreen::Update( dTime );
00063 if ( m_bFirstUpdate )
00064 {
00065 m_bFirstUpdate = false;
00066 return;
00067 }
00068 MercuryODEObject * z = m_pWorld.GetODEObjectByName( "Control" );
00069
00070 int dx=0;
00071 int dy=0;
00072 if ( INPUTMAN->IsButtonDown( button_d ) )
00073 dx -=5000;
00074 if ( INPUTMAN->IsButtonDown( button_a ) )
00075 dx += 5000;
00076 if ( INPUTMAN->IsButtonDown( button_w ) )
00077 dy -= 5000;
00078 if ( INPUTMAN->IsButtonDown( button_s ) )
00079 dy += 5000;
00080
00081 float Amplitude = SQRT(float((dx*dx)+(dy*dy)));
00082 float AngleToGo=ATAN2(float(dx),float(-dy));
00083
00084 MercuryPoint Target = m_pWorld.GetODEObjectByName( "Control" )->GetPosition();
00085 MercuryPoint From = m_pCamera->GetPosition();
00086 float AngleDiff=ATAN2((From-Target).x,(From-Target).y);
00087
00088 float RealAngle = AngleToGo - AngleDiff - 1.57f;
00089
00090 dBodySetForce( z->m_oBody, COS(RealAngle)*Amplitude,SIN(RealAngle)*Amplitude,0);
00091 }
00092
00093 void ScreenODETest::Draw()
00094 {
00095 MercuryODEObject * c = m_pWorld.GetODEObjectByName( "Control" );
00096
00097 int x, y;
00098 INPUTMAN->GetCursorPosition(x, y);
00099 m_pCamera->Tweening.StopTweening();
00100
00101
00102 m_pCamera->Tweening.AddCommand( ssprintf( "linear,0.4;x,%f;y,%f;z,%f;",
00103 c->GetX()+COS(float(x)/300)*70,
00104 c->GetY()+SIN(float(x)/300)*70,
00105 c->GetZ()+(float(y)/300)*70) );
00106 m_pCamera->SetTarget(c->GetPosition());
00107
00108 MercuryScreen::Draw();
00109 }
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138