HelloPolycodeApp.cpp 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #include "HelloPolycodeApp.h"
  2. HelloPolycodeApp::HelloPolycodeApp(PolycodeView *view) : EventHandler() {
  3. core = new POLYCODE_CORE(view, 640,480,false,true,6,16,90, 0, true);
  4. CoreServices::getInstance()->getResourceManager()->addArchive("Resources/default.pak");
  5. CoreServices::getInstance()->getResourceManager()->addDirResource("default", false);
  6. CoreServices::getInstance()->getResourceManager()->addDirResource("Resources", false);
  7. scene = new Scene();
  8. ScenePrimitive *ground = new ScenePrimitive(ScenePrimitive::TYPE_PLANE, 5,5);
  9. ground->setMaterialByName("GroundMaterial");
  10. scene->addEntity(ground);
  11. torus = new ScenePrimitive(ScenePrimitive::TYPE_TORUS, 0.8,0.3,30,20);
  12. torus->setMaterialByName("CubeMaterial");
  13. torus->setPosition(0.0, 0.5, 0.0);
  14. scene->addEntity(torus);
  15. SceneLight *light = new SceneLight(SceneLight::POINT_LIGHT, scene, 5);
  16. light->setPosition(3,2,3);
  17. light->setLightColor(1,0,0);
  18. scene->addLight(light);
  19. light = new SceneLight(SceneLight::POINT_LIGHT, scene, 5);
  20. light->setPosition(-3,2,3);
  21. light->setLightColor(0,1,0);
  22. scene->addLight(light);
  23. light = new SceneLight(SceneLight::POINT_LIGHT, scene, 5);
  24. light->setPosition(-3,2,-3);
  25. light->setLightColor(0,0,1);
  26. scene->addLight(light);
  27. light = new SceneLight(SceneLight::POINT_LIGHT, scene, 5);
  28. light->setPosition(3,2,-3);
  29. light->setLightColor(1,0,1);
  30. scene->addLight(light);
  31. lights = new Entity();
  32. scene->addChild(lights);
  33. light = new SceneLight(SceneLight::SPOT_LIGHT, scene, 4);
  34. light->setPosition(0,4,1);
  35. light->setLightColor(1,1,0);
  36. scene->addLight(light);
  37. lights->addChild(light);
  38. light->lookAt(Vector3(0,0,0));
  39. light->enableShadows(true);
  40. light->getSpotlightCamera()->frustumCulling = false;
  41. light = new SceneLight(SceneLight::SPOT_LIGHT, scene, 4);
  42. light->setPosition(0,4,-1);
  43. light->setLightColor(0,1,1);
  44. scene->addLight(light);
  45. lights->addChild(light);
  46. light->lookAt(Vector3(0,0,0));
  47. light->enableShadows(true);
  48. light->getSpotlightCamera()->frustumCulling = false;
  49. cameraRotation = 0.0;
  50. }
  51. HelloPolycodeApp::~HelloPolycodeApp() {
  52. }
  53. bool HelloPolycodeApp::Update() {
  54. lights->Yaw(core->getElapsed() * 10.0);
  55. torus->Roll(core->getElapsed() * 10.0);
  56. cameraRotation += core->getElapsed() * 0.1;
  57. scene->getDefaultCamera()->setPosition(sin(cameraRotation) * 7.0, 7.0,cos(cameraRotation) * 7.0);
  58. scene->getDefaultCamera()->lookAt(Vector3(0,0,0));
  59. return core->updateAndRender();
  60. }