int main () { printf ("Results of sprite1_test:\n"); try { Test test (L"Sprite 1", true); RenderManager render_manager = test.RenderManager (); render_manager.LoadResource ("data/sprites.rfx"); render_manager.LoadResource ("data/bottom.jpg"); render_manager.LoadResource ("data/sprites.xmtl"); Entity entity = render_manager.CreateEntity (); Primitive primitive = render_manager.CreatePrimitive (); // SpriteList sprites = primitive.AddStandaloneSpriteList (SpriteMode_Oriented, math::vec3f (0, 1.0f, 0)); // SpriteList sprites = primitive.AddStandaloneSpriteList (SpriteMode_Billboard, math::vec3f (0, 1.0f, 0)); // SpriteList sprites = primitive.AddBatchingSpriteList (SpriteMode_Oriented, math::vec3f (0, 1.0f, 0)); SpriteList sprites = primitive.AddBatchingSpriteList (SpriteMode_Oriented, math::vec3f (0, 1.0f, 0)); Sprite sprite; primitive.Buffers ().ReserveDynamicBuffers (8192, 8192); entity.SetWorldScissor (Box (math::vec3f (0.0f), math::vec3f (1.0f))); entity.EnableScissor (); sprite.position = math::vec3f (0.0f); sprite.size = math::vec2f (1.0f); sprite.color = math::vec4f (1.0f); sprite.tex_offset = math::vec2f (0.0f); sprite.tex_size = math::vec2f (1.0f); sprite.normal = math::vec3f (0, 0, 1.0f); sprite.rotation = math::anglef (); sprites.SetMaterial ("sprite"); sprites.Add (1, &sprite); entity.SetPrimitive (primitive); entity.SetWorldMatrix (math::rotate (math::degree (45.0f), math::vec3f (0, 0, 1))); Frame frame = render_manager.CreateFrame (); frame.DisableAutoCleanup (); frame.SetRenderTarget ("main_color_target", test.Window ().ColorBuffer ()); frame.SetRenderTarget ("main_depth_stencil_target", test.Window ().DepthStencilBuffer ()); frame.SetEffect ("main"); frame.SetClearColor (math::vec4f (0.0f, 0.0f, 1.0f, 1.0f)); frame.SetEntityDrawHandler (&update_entity_frame_transformations); common::PropertyMap entity_dependent_properties; frame.SetEntityDependentProperties (entity_dependent_properties); entity_dependent_properties.SetProperty ("myObjectMatrix", math::mat4f (1.0f)); common::PropertyMap frame_properties = frame.Properties (); common::PropertyMap entity_properties = entity.Properties (); frame_properties.SetProperty ("myProjMatrix", get_ortho_proj (-2, 2, -2, 2, -15, 15)); frame_properties.SetProperty ("myViewMatrix", inverse (math::lookat (math::vec3f (0, 0, 10), math::vec3f (0.0f), math::vec3f (0, 1, 0)))); frame.SetViewProjectionMatrix (frame_properties.GetMatrix ("myProjMatrix") * frame_properties.GetMatrix ("myViewMatrix")); frame.AddEntity (entity); test.ShowWindow (); syslib::Application::RegisterEventHandler (syslib::ApplicationEvent_OnIdle, xtl::bind (&idle, xtl::ref (test), xtl::ref (entity), xtl::ref (frame))); return test.Run (); } catch (std::exception& e) { printf ("%s\n", e.what ()); } return 0; }
Level::Level( int which ) { Starfield starfield( 350 ); Hud hud; Timer *timer = Timer::Instance(); Video *video = Video::Instance(); SpriteList *spriteList = SpriteList::Instance(); Ship *player = new Ship(); // the player sprite bool quit = false; SDL_Event event; camera = Camera::Instance(); camera->Follow( player ); player->UseAI( false ); player->IsPlayer( true ); player->SetThrust( 5. ); // add player spriteList->Add( player ); Ship *test = new Ship( 15, 15 ); spriteList->Add( test ); if( SDL_Init( SDL_INIT_JOYSTICK ) != 0 ) cout << "massive joystick error" << endl; // move to an input class timer->Reset(); hud.Message( HUD_MSG_COMMAND, "Good morning, pilot." ); while( !quit ) { // erase video->Blank(); // update // get user input while( SDL_PollEvent( &event ) ) { switch( event.type ) { case SDL_QUIT: quit = true; break; case SDL_JOYAXISMOTION: cout << "joystick motion!" << endl; if(event.jaxis.which == 0) player->Turn( (float)-20 * 0.15f ); break; case SDL_KEYDOWN: switch( event.key.keysym.sym ) { case SDLK_ESCAPE: quit = true; break; case SDLK_w: player->ThrottleUp(); break; case SDLK_s: player->ThrottleDown(); break; default: break; } break; case SDL_MOUSEMOTION: if(( event.motion.xrel ) && ( event.motion.xrel != 160 )) { if( abs(event.motion.xrel) > 20 ) if(event.motion.xrel < 0) player->Turn( (float)-20 * 0.15f ); else player->Turn( (float)20 * 0.15f ); else player->Turn( (float)event.motion.xrel * 0.15f ); } break; case SDL_MOUSEBUTTONDOWN: if( event.button.button == 1) player->Fire(); if( event.button.button == 4) player->ThrottleUp(); if( event.button.button == 5) player->ThrottleDown(); break; default: break; } } for( int n = timer->GetLoops(); n ; --n ) { // update various systems camera->Update(); starfield.Update(); spriteList->Update(); hud.Update(); } // draw starfield.Draw(); spriteList->Draw(); hud.Draw(); video->Update(); timer->Delay(); } }