void Game::fireCube(const std::string&) { Entity* camera; if (m_sceneManager.findEntity("camera", camera)) { static size_t n = 0; stringstream ss; ss << "missile-cube-" << ++n; Entity* cube = m_sceneManager.getRoot().addChild(ss.str()); Vector3 orientationUnit = VECTOR3_UNIT_Z_NEG.rotate(camera->getOrientationAbs()); cube->setPositionAbs(camera->getPositionAbs() + orientationUnit); cube->setOrientationAbs(camera->getOrientationAbs()); RenderableMesh* cubeMesh = new RenderableMesh(cube); cubeMesh->loadBox(MISSILE_SIZE, MISSILE_SIZE, MISSILE_SIZE); RigidBody* cubeBody = new RigidBody(cube); cubeBody->init(1.0, 0.8); cubeBody->addBox(MISSILE_SIZE, MISSILE_SIZE, MISSILE_SIZE); cubeBody->setLinearVelocity(orientationUnit * FIRE_SPEED); } }
void Game::loadScene() { cout << "Loading scene..." << endl; Entity* root = m_sceneManager.getRootPtr(); Entity* floor = root->addChild("floor"); floor->setPositionAbs(0.0f, -1.0f, 0.0f); RenderableMesh* floorMesh = new RenderableMesh(floor); floorMesh->loadBox(100, 1, 100); RigidBody* floorBody = new RigidBody(floor); floorBody->addBox(100, 1, 100); Entity* b1 = root->addChild("b1"); b1->setPositionAbs(5.0f, 4.0f, -10.0f); RenderableMesh* b1Mesh = new RenderableMesh(b1); b1Mesh->loadBox(3.0f, 9.0f, 3.0f); RigidBody* b1Body = new RigidBody(b1); b1Body->addBox(3, 9, 3); // model faces (triangles) // icosphere1 20 // icosphere2 80 // icosphere3 320 // icosphere4 1,280 // icosphere5 5,120 // icosphere6 20,480 // icosphere7 81,920 // icosphere8 327,680 // icosphere9 1,310,720 // icosphere10 5,242,880 Entity* cube = root->addChild("cube"); cube->setPositionAbs(-1.0, 8.0, 0.0); cube->setOrientationAbs(0.5, 0.3, 0.2); RenderableMesh* cubeMesh = new RenderableMesh(cube); cubeMesh->loadBox(0.5, 0.5, 0.5); RigidBody* cubeBody = new RigidBody(cube); cubeBody->init(1.0); cubeBody->addBox(0.5, 0.5, 0.5); Entity* mesh = root->addChild("model"); mesh->setPositionRel(1.5f, 5.0f, 0.0f); RenderableMesh* renderableMesh = new RenderableMesh(mesh); renderableMesh->loadFromFile("assets/meshes/materialtest.dae"); RigidBody* meshBody = new RigidBody(mesh); meshBody->init(10.0); meshBody->addBox(2, 2, 2); // meshBody->addConvexHull("assets/meshes/materialtest.dae"); Entity* camera = root->addChild("camera"); camera->setPositionAbs(0.0f, 4.0f, 10.0f); camera->pitch(-0.2); // camera->lookAt(cube->getPositionAbs(), VECTOR3_UNIT_Y); Camera* camComponent = new Camera(camera, CAMERA_PROJECTION); camComponent->setPerspectiveFOV(45.0); // RigidBody* cameraBody = new RigidBody(camera); // cameraBody->addSphere(1); Entity* light1 = root->addChild("light1"); light1->setPositionAbs(5, 5, 0); Light* light1Cmp = new Light(light1); light1Cmp->setDiffuse(1.0, 1.0, 1.0); // Entity* light2 = root->addChild("light2"); // light2->setPositionAbs(0, 5, 5); // Light* light2Cmp = new Light(light2); // light2Cmp->setDiffuse(0.0, 1.0, 0.0); // Entity* light3 = root->addChild("light3"); // light3->setPositionAbs(0, 5, 0); // Light* light3Cmp = new Light(light3); // light3Cmp->setDiffuse(0.0, 0.0, 1.0); // cout << Terminal::listsToString() << endl; // cout << m_sceneManager.sceneGraphToString() << endl; // cout << RenderManager::getRenderer().listsToString() << endl; // cout << ResourceManager::listsToString() << endl; }