int main(int argc, char *argv[]) { #ifdef Q_WS_X11 XInitThreads(); #endif Engine engine(argc, argv,"demo_game/media/"); SceneGraph* sg = engine.getScenegraph_TEMPORARY(); g_sg = sg; QList<InputManager::Control> controls; controls.push_back(InputManager::Control(false,"avance")); controls.push_back(InputManager::Control(false,"recule")); controls.push_back(InputManager::Control(false,"gauche")); controls.push_back(InputManager::Control(false,"droite")); INPUT_MANAGER.addControls(controls); INPUT_MANAGER.addBinding("KB_Z","avance"); INPUT_MANAGER.addBinding("KB_Up","avance"); INPUT_MANAGER.addBinding("KB_S","recule"); INPUT_MANAGER.addBinding("KB_Down","recule"); INPUT_MANAGER.addBinding("KB_Q","gauche"); INPUT_MANAGER.addBinding("KB_Left","gauche"); INPUT_MANAGER.addBinding("KB_D","droite"); INPUT_MANAGER.addBinding("KB_Right","droite"); Node* nRot = new Node("Rotating node"); Node* nQt = new Node("Qt Logo"); Node* nCam = new Node("Camera"); Node* nCamFollow = new Node("Camera Follow"); Node* nHead = new Node("Head"); Node* nStar = new Node("Star"); Node* nLight = new Node("Light"); Node* nLight2 = new Node("Light2"); Node* nUni = new Node("Unicorn"); Node* nGarg = new Node("Gargoyle"); Node* nDuck = new Node("Duck"); Node* nBuddy = new Node("Buddy"); Node* nSand = new Node("Sand"); QVector<Node*> balls; QVector<Node*> walls; for(int i=0 ; i<4 ; i++) { walls.push_back(new Node("Wall" + QString().setNum(i+1))); } for(int i=0 ; i<15 ; i++) { balls.push_back(new Node("Ball" + QString().setNum(i+1))); } nRot->addProperty(new IProperty()); // nRot->addProperty(new DummyUpdatable()); // nQt->addProperty(new QtLogo(engine.getGLW_TEMPORARY())); // nQt->addProperty(new Grid(1.0f, 1.0f, 40, 40)); //nDuckGrid->addProperty(new Grid(1.0f, 1.0f, 40, 40)); nCam->addProperty(new Camera(70,1,200)); nCamFollow->addProperty(new Camera(90,1,200)); nHead->addProperty(new DummyUpdatable()); Light* light; light = new Light(false); //light->setType(Light::SUN); //light->setDiffuseColor(Vector4f(0.2,1.0,0.2,1.0)); //light->setSpecularColor(Vector4f(0.2,1.0,0.2,1.0)); light->setDiffuseColor(Vector4f(1.0,1.0,0.0,1.0)); light->setSpecularColor(Vector4f(1.0,1.0,1.0,1.0)); nLight2->addProperty(light); light = new Light(true); //light->setType(Light::SPOT); light->setDiffuseColor(Vector4f(1.0,1.0,1.0,1.0)); light->setSpecularColor(Vector4f(1.0,1.0,1.0,1.0)); //light->setDiffuseColor(Vector4f(1.0,0.2,0.2,1.0)); //light->setSpecularColor(Vector4f(1.0,0.2,0.2,1.0)); nLight->addProperty(light); Mesh plane = MESH_MANAGER.get("Plane"); Mesh cube = MESH_MANAGER.get("Cube"); Mesh sphere = MESH_MANAGER.get("Sphere_16_32"); Mesh mesh = MESH_MANAGER.get("duck"); Mesh buddymesh = MESH_MANAGER.get("buddy"); Material buddy = MATERIAL_MANAGER.get("buddy"); Material duck = MATERIAL_MANAGER.get("duck"); Material star = MATERIAL_MANAGER.get("star"); Material gargoyle = MATERIAL_MANAGER.get("gargoyle"); Material sand = MATERIAL_MANAGER.get("sand"); Material gradientmats[4]; gradientmats[0] = MATERIAL_MANAGER.get("grad1"); gradientmats[1] = MATERIAL_MANAGER.get("grad2"); gradientmats[2] = MATERIAL_MANAGER.get("grad3"); gradientmats[3] = MATERIAL_MANAGER.get("grad4"); Sample sample = SAMPLE_MANAGER.get("quacking.wav"); nDuck->addProperty(new MeshRenderer(mesh,duck)); nStar->addProperty(new MeshRenderer(plane,star)); //nUni->addProperty(new MeshRenderer(cube,unicorn)); nGarg->addProperty(new MeshRenderer(cube,gargoyle)); nBuddy->addProperty(new MeshRenderer(buddymesh,buddy)); nSand->addProperty(new MeshRenderer(cube,sand)); nDuck->addProperty(new DummyControlable()); nDuck->addProperty(new SoundEmitter(sample)); nDuck->link(nCamFollow); nDuck->link(nHead); //nDuck->link(nDuckGrid); nHead->link(nStar); nHead->link(nLight); nCam->link(nLight2); nHead->link(nUni); sg->link(nDuck); sg->link(nBuddy); sg->link(nRot); sg->link(nQt); sg->link(nSand); for(QVector<Node*>::iterator it = walls.begin() ; it != walls.end() ; it++) { sg->link(*it); } for(QVector<Node*>::iterator it = balls.begin() ; it != balls.end() ; it++) { sg->link(*it); } nRot->link(nCam); nRot->link(nGarg); nRot->moveTo(Vector3f(0,0,0)); nQt->moveTo(Vector3f(0,-0.5,0)); nQt->rotate(Vector3f(1,0,0),90); nCam->moveTo(Vector3f(0,10.0,0)); nCam->rotate(Vector3f(1,0,0),270); nCamFollow->moveTo(Vector3f(0,2,3)); nCamFollow->rotate(Vector3f(1,0,0),345); nUni->rotate(Vector3f(0,0,-1),90); nUni->rotate(Vector3f(-1,0,0),90); nHead->moveTo(Vector3f(0,0.5,0)); nUni->moveTo(Vector3f(1.5,0,0)); nStar->moveTo(Vector3f(-1.5,0,0)); nStar->rotate(Vector3f(0,0,1),270); nLight->moveTo(Vector3f(-1.5,0,0)); nLight2->moveTo(Vector3f(0,0,-3)); nSand->moveTo(Vector3f(0,-0.5,0)); nSand->rotate(Vector3f(1,0,0),270); nSand->setScale(Vector3f(10,10,0.01)); walls[0]->moveTo(Vector3f(0,1,-2)); //walls[0]->moveTo(Vector3f(0,1,-5)); walls[0]->setScale(Vector3f(10,3,0.01)); walls[1]->moveTo(Vector3f(0,1, 2)); //walls[1]->moveTo(Vector3f(0,1, 5)); walls[1]->setScale(Vector3f(10,3,0.01)); walls[2]->moveTo(Vector3f( 2,1,0)); //walls[2]->moveTo(Vector3f( 5,1,0)); walls[2]->setScale(Vector3f(0.01,3,10)); walls[3]->moveTo(Vector3f(-2,1,0)); //walls[3]->moveTo(Vector3f(-5,1,0)); walls[3]->setScale(Vector3f(0.01,3,10)); for(int i=0 ; i<balls.size() ; i++) { balls[i]->moveTo(Vector3f(0,4+2*i,0)); float s1 = 0.1+(qrand() % 900)/1000.0; float s2 = 0.1+(qrand() % 900)/1000.0; float s3 = 0.1+(qrand() % 900)/1000.0; balls[i]->setScale(Vector3f(s1,s2,s3)); } nGarg->moveTo(Vector3f(-3,3,-3)); nGarg->setScale(Vector3f(1,0.3,1)); nBuddy->moveTo(Vector3f(3,1.5,3)); nBuddy->rotate(Vector3f(1,0,0),-90); nBuddy->rotate(Vector3f(0,1,0),180); nDuck->moveTo(Vector3f(0,-0.5,-1.8)); nDuck->rotate(Vector3f(0,1,0),127); //nDuckGrid->rotate(Vector3f(1,0,0),270); PhysicObject::Properties prop; nSand->addProperty(new PhysicObject(prop)); for(QVector<Node*>::iterator it=walls.begin() ; it != walls.end() ; it++) { (*it)->addProperty(new PhysicObject(prop)); //(*it)->addProperty(new MeshRenderer(cube,gargoyle)); } prop.is_kinematic = true; nGarg->addProperty(new PhysicObject(prop)); prop.shape = PhysicObject::MESH; prop.mesh_name = "duck"; nDuck->addProperty(new PhysicObject(prop)); prop.is_kinematic = false; prop.mass = 100.0; prop.restitution = 0.1; int nbDuckLight = 0; prop.shape = PhysicObject::BOX; for(QVector<Node*>::iterator it=balls.begin() ; it != balls.end() ; it++) { (*it)->addProperty(new PhysicObject(prop)); prop.mass += 1.0; (*it)->addProperty(new MeshRenderer(cube,gradientmats[nbDuckLight%4])); if(nbDuckLight < 0) { light = new Light(false); if(nbDuckLight % 3 == 0) { light->setDiffuseColor(Vector4f(0.2,0.2,1.0,1.0)); light->setSpecularColor(Vector4f(0.2,0.2,1.0,1.0)); } else if(nbDuckLight % 3 == 1) { light->setDiffuseColor(Vector4f(1.0,0.2,0.2,1.0)); light->setSpecularColor(Vector4f(1.0,0.2,0.2,1.0)); } else { light->setDiffuseColor(Vector4f(0.2,1.0,0.2,1.0)); light->setSpecularColor(Vector4f(0.2,1.0,0.2,1.0)); } (*it)->addProperty(light); } nbDuckLight++; } // Beurk ! Mais je peux le faire alors je me prive pas ^^ //RENDER_MANAGER.setCurrentCamera(static_cast<Camera*>(nCamFollow->properties().child("Camera"))); RENDER_MANAGER.setCurrentCamera(static_cast<Camera*>(nCamFollow->properties().child("Camera"))); RenderManager::Background background; background.type = RenderManager::Background::SKYBOX; background.color = Vector3f(0.5,0.5,0.5); background.sunDirection = Vector3f(10,5,10); background.textures[0] = TEXTURE_MANAGER.get("stormy_front.tga"); background.textures[1] = TEXTURE_MANAGER.get("stormy_left.tga"); background.textures[2] = TEXTURE_MANAGER.get("stormy_back.tga"); background.textures[3] = TEXTURE_MANAGER.get("stormy_right.tga"); background.textures[4] = TEXTURE_MANAGER.get("stormy_top.tga"); background.textures[5] = TEXTURE_MANAGER.get("stormy_bottom.tga"); RENDER_MANAGER.setBackground(background); RENDER_MANAGER.setAmbient(Vector3f(0.8,0.8,0.8)); COMMAND_MANAGER.registerCommand("spawn_duck",spawn_duck); COMMAND_MANAGER.readFile("config.cfg"); int ret = engine.start(); return ret; }
int main(int argc, char *argv[]) { #ifdef Q_WS_X11 XInitThreads(); #endif Engine engine(argc, argv,"demo_game/media/"); SceneGraph* sg = engine.getScenegraph_TEMPORARY(); QList<InputManager::Control> controls; controls.push_back(InputManager::Control(false,"avance")); controls.push_back(InputManager::Control(false,"recule")); controls.push_back(InputManager::Control(false,"gauche")); controls.push_back(InputManager::Control(false,"droite")); INPUT_MANAGER.addControls(controls); INPUT_MANAGER.addBinding("KB_Z","avance"); INPUT_MANAGER.addBinding("KB_Up","avance"); INPUT_MANAGER.addBinding("KB_S","recule"); INPUT_MANAGER.addBinding("KB_Down","recule"); INPUT_MANAGER.addBinding("KB_Q","gauche"); INPUT_MANAGER.addBinding("KB_Left","gauche"); INPUT_MANAGER.addBinding("KB_D","droite"); INPUT_MANAGER.addBinding("KB_Right","droite"); Node* nTerrain = new Node("Terrain"); Node* nBase = new Node("Base"); Node* nRot = new Node("Rotating node"); Node* nLight = new Node("Light"); Node* nPlane = new Node("Plane"); Node* nCentre = new Node("Centre"); Node* nCamFollow = new Node("Camera Follow"); Texture heightmap; if(argc>1) { heightmap = TEXTURE_MANAGER.get(argv[1]); } else { heightmap = TEXTURE_MANAGER.get("heightmap_island.tga"); } Mesh sphere = MESH_MANAGER.get("Sphere_16_32"); Mesh palm = MESH_MANAGER.get("palm"); Mesh mesh = MESH_MANAGER.get("duckplane"); Material mat = MATERIAL_MANAGER.get("palm"); Material duckmat = MATERIAL_MANAGER.get("duckplane"); Material terrain = MATERIAL_MANAGER.get("terrain_test"); PhysicObject::Properties prop; prop.is_kinematic = false; prop.mass = 100.0; prop.restitution = 0.1; //prop.linDamping = 0.6; //prop.angDamping = 0.3; prop.shape = PhysicObject::MESH; prop.mesh_name = "duckplane"; sg->link(nCentre); nCentre->link(nPlane); nCentre->move(Vector3f(512.0,50.0,512.0)); nPlane->addProperty(new MeshRenderer(mesh,duckmat)); nPlane->rotate(Vector3f(0.0,0.0,1.0), 20.0); nPlane->move(Vector3f(286.0,20.0,0.0)); //nPlane->setScale(Vector3f(5.0,5.0,5.0)); nCentre->addProperty(new DummyUpdatable(0.1)); Camera* cam = new Camera(90,1,1024); nCamFollow->addProperty(cam); nCamFollow->move(Vector3f(0,2,5)); nCamFollow->rotate(Vector3f(-1,0,0),15); nPlane->link(nCamFollow); Light* light = new Light(true); light->setAttenuation(0,1.f/512.f,0); //light->setAttenuation(0.1,0,0); light->setType(Light::SUN); nLight->addProperty(light); /* nLight->move(Vector3f(512.0, 75.0, 512.0)); nLight->rotate(Vector3f(0.0, 0.0, 1.0),35); */ nLight->lookAt(Vector3f(4.3,13,10)); nLight->rotate(nLight->apply(Vector3f(0,1,0)),90); nLight->moveTo(25*Vector3f(4.3,13,10) + Vector3f(512,50,512)); //nLight->lookAt(Vector3f(512,50,512)); //nLight->rotate(Vector3f(0,1,0),-90); /* cam = new Camera(90,1,1024); nLight->addProperty(cam); */ nBase->rotate(Vector3f(1,0,0),90); nBase->rotate(Vector3f(0,1,0),-45); nTerrain->addProperty(new TerrainRenderer(heightmap, terrain, 70.0f, 2.f,20.f)); nTerrain->setScale(Vector3f(1,3,1)); sg->link(nTerrain); sg->link(nLight); nBase->link(nRot); sg->link(nBase); addTree(sg,Vector3f(502.7,39.2,616.7),135); addTree(sg,Vector3f(494.8,37.2,628.1),45); addTree(sg,Vector3f(520.6,40.2,612.8),12); addTree(sg,Vector3f(513.1,38.2,622.6),286); addTree(sg,Vector3f(520.5,37.2,632.2),124); RenderManager::Background background; background.type = RenderManager::Background::COLOR; background.color = Vector3f(0,0,0); background.sunDirection = Vector3f(4.3,13,10); background.textures[0] = TEXTURE_MANAGER.get("interstellar_lf.tga"); background.textures[1] = TEXTURE_MANAGER.get("interstellar_ft.tga"); background.textures[2] = TEXTURE_MANAGER.get("interstellar_rt.tga"); background.textures[3] = TEXTURE_MANAGER.get("interstellar_bk.tga"); background.textures[4] = TEXTURE_MANAGER.get("interstellar_up.tga"); background.textures[5] = TEXTURE_MANAGER.get("interstellar_dn.tga"); background.type = RenderManager::Background::SKYBOX; RENDER_MANAGER.setBackground(background); //RENDER_MANAGER.setCurrentCamera(cam); RENDER_MANAGER.setAmbient(Vector3f(0.1,0.2,0.15)); COMMAND_MANAGER.readFile("config.cfg"); int ret = engine.start(); return ret; }