void CharacterDemo::CreateCharacter() { ResourceCache* cache = GetSubsystem<ResourceCache>(); Node* objectNode = scene_->CreateChild("Jack"); objectNode->SetPosition(Vector3(0.0f, 1.0f, 0.0f)); // spin node Node* adjustNode = objectNode->CreateChild("AdjNode"); adjustNode->SetRotation( Quaternion(180, Vector3(0,1,0) ) ); // Create the rendering component + animation controller AnimatedModel* object = adjustNode->CreateComponent<AnimatedModel>(); object->SetModel(cache->GetResource<Model>("Models/Mutant/Mutant.mdl")); object->SetMaterial(cache->GetResource<Material>("Models/Mutant/Materials/mutant_M.xml")); object->SetCastShadows(true); adjustNode->CreateComponent<AnimationController>(); // Set the head bone for manual control object->GetSkeleton().GetBone("Mutant:Head")->animated_ = false; // Create rigidbody, and set non-zero mass so that the body becomes dynamic RigidBody* body = objectNode->CreateComponent<RigidBody>(); body->SetCollisionLayer(1); body->SetMass(1.0f); // Set zero angular factor so that physics doesn't turn the character on its own. // Instead we will control the character yaw manually body->SetAngularFactor(Vector3::ZERO); // Set the rigidbody to signal collision also when in rest, so that we get ground collisions properly body->SetCollisionEventMode(COLLISION_ALWAYS); // Set a capsule shape for collision CollisionShape* shape = objectNode->CreateComponent<CollisionShape>(); shape->SetCapsule(0.7f, 1.8f, Vector3(0.0f, 0.9f, 0.0f)); // Create the character logic component, which takes care of steering the rigidbody // Remember it so that we can set the controls. Use a WeakPtr because the scene hierarchy already owns it // and keeps it alive as long as it's not removed from the hierarchy character_ = objectNode->CreateComponent<Character>(); }
void Vehicle::InitWheel(const String& name, const Vector3& offset, WeakPtr<Node>& wheelNode, unsigned& wheelNodeID) { ResourceCache* cache = GetSubsystem<ResourceCache>(); // Note: do not parent the wheel to the hull scene node. Instead create it on the root level and let the physics // constraint keep it together wheelNode = GetScene()->CreateChild(name); wheelNode->SetPosition(node_->LocalToWorld(offset)); wheelNode->SetRotation(node_->GetRotation() * (offset.x_ >= 0.0 ? Quaternion(0.0f, 0.0f, -90.0f) : Quaternion(0.0f, 0.0f, 90.0f))); wheelNode->SetScale(Vector3(0.8f, 0.5f, 0.8f)); // Remember the ID for serialization wheelNodeID = wheelNode->GetID(); StaticModel* wheelObject = wheelNode->CreateComponent<StaticModel>(); RigidBody* wheelBody = wheelNode->CreateComponent<RigidBody>(); CollisionShape* wheelShape = wheelNode->CreateComponent<CollisionShape>(); Constraint* wheelConstraint = wheelNode->CreateComponent<Constraint>(); wheelObject->SetModel(cache->GetResource<Model>("Models/Cylinder.mdl")); wheelObject->SetMaterial(cache->GetResource<Material>("Materials/Stone.xml")); wheelObject->SetCastShadows(true); wheelShape->SetSphere(1.0f); wheelBody->SetFriction(1.0f); wheelBody->SetMass(1.0f); wheelBody->SetLinearDamping(0.2f); // Some air resistance wheelBody->SetAngularDamping(0.75f); // Could also use rolling friction wheelBody->SetCollisionLayer(1); wheelConstraint->SetConstraintType(CONSTRAINT_HINGE); wheelConstraint->SetOtherBody(GetComponent<RigidBody>()); // Connect to the hull body wheelConstraint->SetWorldPosition(wheelNode->GetPosition()); // Set constraint's both ends at wheel's location wheelConstraint->SetAxis(Vector3::UP); // Wheel rotates around its local Y-axis wheelConstraint->SetOtherAxis(offset.x_ >= 0.0 ? Vector3::RIGHT : Vector3::LEFT); // Wheel's hull axis points either left or right wheelConstraint->SetLowLimit(Vector2(-180.0f, 0.0f)); // Let the wheel rotate freely around the axis wheelConstraint->SetHighLimit(Vector2(180.0f, 0.0f)); wheelConstraint->SetDisableCollision(true); // Let the wheel intersect the vehicle hull }
void VehicleDemo::CreateScene() { ResourceCache* cache = GetSubsystem<ResourceCache>(); scene_ = new Scene(context_); // Create scene subsystem components scene_->CreateComponent<Octree>(); scene_->CreateComponent<PhysicsWorld>(); // Create camera and define viewport. We will be doing load / save, so it's convenient to create the camera outside the scene, // so that it won't be destroyed and recreated, and we don't have to redefine the viewport on load cameraNode_ = new Node(context_); Camera* camera = cameraNode_->CreateComponent<Camera>(); camera->SetFarClip(500.0f); GetSubsystem<Renderer>()->SetViewport(0, new Viewport(context_, scene_, camera)); // Create static scene content. First create a zone for ambient lighting and fog control Node* zoneNode = scene_->CreateChild("Zone"); Zone* zone = zoneNode->CreateComponent<Zone>(); zone->SetAmbientColor(Color(0.15f, 0.15f, 0.15f)); zone->SetFogColor(Color(0.5f, 0.5f, 0.7f)); zone->SetFogStart(300.0f); zone->SetFogEnd(500.0f); zone->SetBoundingBox(BoundingBox(-2000.0f, 2000.0f)); // Create a directional light with cascaded shadow mapping Node* lightNode = scene_->CreateChild("DirectionalLight"); lightNode->SetDirection(Vector3(0.3f, -0.5f, 0.425f)); Light* light = lightNode->CreateComponent<Light>(); light->SetLightType(LIGHT_DIRECTIONAL); light->SetCastShadows(true); light->SetShadowBias(BiasParameters(0.00025f, 0.5f)); light->SetShadowCascade(CascadeParameters(10.0f, 50.0f, 200.0f, 0.0f, 0.8f)); light->SetSpecularIntensity(0.5f); // Create heightmap terrain with collision Node* terrainNode = scene_->CreateChild("Terrain"); terrainNode->SetPosition(Vector3::ZERO); Terrain* terrain = terrainNode->CreateComponent<Terrain>(); terrain->SetPatchSize(64); terrain->SetSpacing(Vector3(2.0f, 0.1f, 2.0f)); // Spacing between vertices and vertical resolution of the height map terrain->SetSmoothing(true); terrain->SetHeightMap(cache->GetResource<Image>("Textures/HeightMap.png")); terrain->SetMaterial(cache->GetResource<Material>("Materials/Terrain.xml")); // The terrain consists of large triangles, which fits well for occlusion rendering, as a hill can occlude all // terrain patches and other objects behind it terrain->SetOccluder(true); RigidBody* body = terrainNode->CreateComponent<RigidBody>(); body->SetCollisionLayer(2); // Use layer bitmask 2 for static geometry CollisionShape* shape = terrainNode->CreateComponent<CollisionShape>(); shape->SetTerrain(); // Create 1000 mushrooms in the terrain. Always face outward along the terrain normal const unsigned NUM_MUSHROOMS = 1000; for (unsigned i = 0; i < NUM_MUSHROOMS; ++i) { Node* objectNode = scene_->CreateChild("Mushroom"); Vector3 position(Random(2000.0f) - 1000.0f, 0.0f, Random(2000.0f) - 1000.0f); position.y_ = terrain->GetHeight(position) - 0.1f; objectNode->SetPosition(position); // Create a rotation quaternion from up vector to terrain normal objectNode->SetRotation(Quaternion(Vector3::UP, terrain->GetNormal(position))); objectNode->SetScale(3.0f); StaticModel* object = objectNode->CreateComponent<StaticModel>(); object->SetModel(cache->GetResource<Model>("Models/Mushroom.mdl")); object->SetMaterial(cache->GetResource<Material>("Materials/Mushroom.xml")); object->SetCastShadows(true); RigidBody* body = objectNode->CreateComponent<RigidBody>(); body->SetCollisionLayer(2); CollisionShape* shape = objectNode->CreateComponent<CollisionShape>(); shape->SetTriangleMesh(object->GetModel(), 0); } }
void CharacterDemo::CreateScene() { ResourceCache* cache = GetSubsystem<ResourceCache>(); scene_ = new Scene(context_); // Create scene subsystem components scene_->CreateComponent<Octree>(); scene_->CreateComponent<PhysicsWorld>(); // Create camera and define viewport. We will be doing load / save, so it's convenient to create the camera outside the scene, // so that it won't be destroyed and recreated, and we don't have to redefine the viewport on load cameraNode_ = new Node(context_); Camera* camera = cameraNode_->CreateComponent<Camera>(); camera->SetFarClip(300.0f); GetSubsystem<Renderer>()->SetViewport(0, new Viewport(context_, scene_, camera)); // Create static scene content. First create a zone for ambient lighting and fog control Node* zoneNode = scene_->CreateChild("Zone"); Zone* zone = zoneNode->CreateComponent<Zone>(); zone->SetAmbientColor(Color(0.15f, 0.15f, 0.15f)); zone->SetFogColor(Color(0.5f, 0.5f, 0.7f)); zone->SetFogStart(100.0f); zone->SetFogEnd(300.0f); zone->SetBoundingBox(BoundingBox(-1000.0f, 1000.0f)); // Create a directional light with cascaded shadow mapping Node* lightNode = scene_->CreateChild("DirectionalLight"); lightNode->SetDirection(Vector3(0.3f, -0.5f, 0.425f)); Light* light = lightNode->CreateComponent<Light>(); light->SetLightType(LIGHT_DIRECTIONAL); light->SetCastShadows(true); light->SetShadowBias(BiasParameters(0.00025f, 0.5f)); light->SetShadowCascade(CascadeParameters(10.0f, 50.0f, 200.0f, 0.0f, 0.8f)); light->SetSpecularIntensity(0.5f); // Create the floor object Node* floorNode = scene_->CreateChild("Floor"); floorNode->SetPosition(Vector3(0.0f, -0.5f, 0.0f)); floorNode->SetScale(Vector3(200.0f, 1.0f, 200.0f)); StaticModel* object = floorNode->CreateComponent<StaticModel>(); object->SetModel(cache->GetResource<Model>("Models/Box.mdl")); object->SetMaterial(cache->GetResource<Material>("Materials/Stone.xml")); RigidBody* body = floorNode->CreateComponent<RigidBody>(); // Use collision layer bit 2 to mark world scenery. This is what we will raycast against to prevent camera from going // inside geometry body->SetCollisionLayer(2); CollisionShape* shape = floorNode->CreateComponent<CollisionShape>(); shape->SetBox(Vector3::ONE); // Create mushrooms of varying sizes const unsigned NUM_MUSHROOMS = 60; for (unsigned i = 0; i < NUM_MUSHROOMS; ++i) { Node* objectNode = scene_->CreateChild("Mushroom"); objectNode->SetPosition(Vector3(Random(180.0f) - 90.0f, 0.0f, Random(180.0f) - 90.0f)); objectNode->SetRotation(Quaternion(0.0f, Random(360.0f), 0.0f)); objectNode->SetScale(2.0f + Random(5.0f)); StaticModel* object = objectNode->CreateComponent<StaticModel>(); object->SetModel(cache->GetResource<Model>("Models/Mushroom.mdl")); object->SetMaterial(cache->GetResource<Material>("Materials/Mushroom.xml")); object->SetCastShadows(true); RigidBody* body = objectNode->CreateComponent<RigidBody>(); body->SetCollisionLayer(2); CollisionShape* shape = objectNode->CreateComponent<CollisionShape>(); shape->SetTriangleMesh(object->GetModel(), 0); } // Create movable boxes. Let them fall from the sky at first const unsigned NUM_BOXES = 100; for (unsigned i = 0; i < NUM_BOXES; ++i) { float scale = Random(2.0f) + 0.5f; Node* objectNode = scene_->CreateChild("Box"); objectNode->SetPosition(Vector3(Random(180.0f) - 90.0f, Random(10.0f) + 10.0f, Random(180.0f) - 90.0f)); objectNode->SetRotation(Quaternion(Random(360.0f), Random(360.0f), Random(360.0f))); objectNode->SetScale(scale); StaticModel* object = objectNode->CreateComponent<StaticModel>(); object->SetModel(cache->GetResource<Model>("Models/Box.mdl")); object->SetMaterial(cache->GetResource<Material>("Materials/Stone.xml")); object->SetCastShadows(true); RigidBody* body = objectNode->CreateComponent<RigidBody>(); body->SetCollisionLayer(2); // Bigger boxes will be heavier and harder to move body->SetMass(scale * 2.0f); CollisionShape* shape = objectNode->CreateComponent<CollisionShape>(); shape->SetBox(Vector3::ONE); } }
void Labyrinth::CreateBlock(int number) { ResourceCache* cache = GetSubsystem<ResourceCache>(); Node* objectNode = scene_->CreateChild("Floor"); objectNode->SetPosition(Vector3(0, 0, 5)); objectNode->SetRotation(Quaternion(0, 0, -90)); objectNode->SetScale(1); StaticModel* object = objectNode->CreateComponent<StaticModel>(); object->SetModel(cache->GetResource<Model>("Urho resources/Models/BlockFence.mdl")); //object->SetMaterial(cache->GetResource<Material>("Urho resources/Materials/Hedge.xml")); object->SetMaterial(cache->GetResource<Material>("Urho resources/Materials/BrickA.xml")); //object->SetCastShadows(true); RigidBody* body = objectNode->CreateComponent<RigidBody>(); body->SetCollisionLayer(2); // Bigger boxes will be heavier and harder to move //body->SetMass(scale * 2.0f); CollisionShape* shape = objectNode->CreateComponent<CollisionShape>(); shape->SetBox(Vector3(2, 2, 2)); Node* nodeApple = scene_->CreateChild("Apple"); nodeApple->SetPosition(Vector3(0, 3, 9)); nodeApple->SetRotation(Quaternion(0, 0, -90)); nodeApple->SetScale(1); StaticModel* apple = nodeApple->CreateComponent<StaticModel>(); apple->SetModel(cache->GetResource<Model>("Urho resources/Models/Apple.mdl")); //apple->SetMaterial(cache->GetResource<Material>("Urho resources/Materials/Hedge.xml")); apple->SetMaterial(cache->GetResource<Material>("Urho resources/Materials/Apple.xml")); //apple->SetCastShadows(true); RigidBody* bodyApple = nodeApple->CreateComponent<RigidBody>(); bodyApple->SetCollisionLayer(2); // Bigger boxes will be heavier and harder to move //bodyApple->SetMass(scale * 2.0f); CollisionShape* shapeApple = nodeApple->CreateComponent<CollisionShape>(); shapeApple->SetBox(Vector3(2, 2, 2)); Node* nodeCherry = scene_->CreateChild("Cherry"); nodeCherry->SetPosition(Vector3(9, 3, 0)); nodeCherry->SetRotation(Quaternion(0, 0, -90)); nodeCherry->SetScale(1); StaticModel* cherry = nodeCherry->CreateComponent<StaticModel>(); cherry->SetModel(cache->GetResource<Model>("Urho resources/Models/Cherry.mdl")); //cherry->SetMaterial(cache->GetResource<Material>("Urho resources/Materials/Hedge.xml")); cherry->SetMaterial(cache->GetResource<Material>("Urho resources/Materials/Cherry.xml")); //cherry->SetCastShadows(true); RigidBody* bodyCherry = nodeCherry->CreateComponent<RigidBody>(); bodyCherry->SetCollisionLayer(2); // Bigger boxes will be heavier and harder to move //bodyCherry->SetMass(scale * 2.0f); CollisionShape* shapeCherry = nodeCherry->CreateComponent<CollisionShape>(); shapeCherry->SetBox(Vector3(2, 2, 2)); Node* nodeBanana = scene_->CreateChild("Banana"); nodeBanana->SetPosition(Vector3(0, 3, 15)); nodeBanana->SetRotation(Quaternion(0, 0, -90)); nodeBanana->SetScale(1); StaticModel* banana = nodeBanana->CreateComponent<StaticModel>(); banana->SetModel(cache->GetResource<Model>("Urho resources/Models/Banana.mdl")); //banana->SetMaterial(cache->GetResource<Material>("Urho resources/Materials/Hedge.xml")); banana->SetMaterial(cache->GetResource<Material>("Urho resources/Materials/Banana.xml")); //banana->SetCastShadows(true); RigidBody* bodyBanana = nodeBanana->CreateComponent<RigidBody>(); bodyBanana->SetCollisionLayer(2); // Bigger boxes will be heavier and harder to move //bodyBanana->SetMass(scale * 2.0f); CollisionShape* shapeBanana = nodeBanana->CreateComponent<CollisionShape>(); shapeBanana->SetBox(Vector3(2, 2, 2)); /*switch (number) { // TODO //case }*/ }
void Labyrinth::CreateMap(int mapLength, int mapWidth) { // TODO //Scene* scene_ = context_->GetSubsystem<Scene>(); ResourceCache* cache = GetSubsystem<ResourceCache>(); // Create the floor object Node* floorNode = scene_->CreateChild("Floor"); floorNode->SetPosition(Vector3(0.0f, -0.5f, 0.0f)); floorNode->SetScale(Vector3(200.0f, 1.0f, 200.0f)); StaticModel* object = floorNode->CreateComponent<StaticModel>(); object->SetModel(cache->GetResource<Model>("Models/Box.mdl")); object->SetMaterial(cache->GetResource<Material>("Urho resources/Materials/Grass.xml")); RigidBody* body = floorNode->CreateComponent<RigidBody>(); // Use collision layer bit 2 to mark world scenery. This is what we will raycast against to prevent camera from going // inside geometry body->SetCollisionLayer(2); CollisionShape* shape = floorNode->CreateComponent<CollisionShape>(); shape->SetBox(Vector3::ONE); // Create movable boxes. Let them fall from the sky at first const unsigned NUM_BOXES = 100; const float SCALE = 0.5; int numberX = (float)mapLength/SCALE; int numberZ = (float)mapWidth/SCALE; int beginX = (0 - mapLength/2); int beginZ = (0 - mapWidth/2); // TODO vzdialenost kamery podla rozlisenia obrazovky for (unsigned i = 0; i < numberX; i++) { for (int j = 0; j < numberZ; j++) { //float scale = Random(2.0f) + 0.5f; //float scale = 1; Node* objectNode = scene_->CreateChild("Floor"); objectNode->SetPosition(Vector3(i, 0, j)); //objectNode->SetRotation(Quaternion(Random(360.0f), Random(360.0f), Random(360.0f))); objectNode->SetScale(SCALE); StaticModel* object = objectNode->CreateComponent<StaticModel>(); object->SetModel(cache->GetResource<Model>("Urho resources/Models/Block.mdl")); //object->SetMaterial(cache->GetResource<Material>("Urho resources/Materials/Hedge.xml")); object->SetMaterial(cache->GetResource<Material>("Urho resources/Materials/GrassA.xml")); //object->SetCastShadows(true); RigidBody* body = objectNode->CreateComponent<RigidBody>(); body->SetCollisionLayer(2); // Bigger boxes will be heavier and harder to move //body->SetMass(scale * 2.0f); CollisionShape* shape = objectNode->CreateComponent<CollisionShape>(); shape->SetBox(Vector3(2,2,2)); } } for (unsigned i = 0; i < numberX; i++) { for (int j = 0; j < numberZ; j++) { //float scale = Random(2.0f) + 0.5f; //float scale = 1; if (i == 0 || j == 0 || i == numberX-1 || j == numberZ-1) { Node* objectNode = scene_->CreateChild("Floor"); objectNode->SetPosition(Vector3(i, 1, j)); //objectNode->SetRotation(Quaternion(Random(360.0f), Random(360.0f), Random(360.0f))); objectNode->SetScale(SCALE); StaticModel* object = objectNode->CreateComponent<StaticModel>(); object->SetModel(cache->GetResource<Model>("Urho resources/Models/Block.mdl")); //object->SetMaterial(cache->GetResource<Material>("Urho resources/Materials/Hedge.xml")); object->SetMaterial(cache->GetResource<Material>("Urho resources/Materials/GrassA.xml")); //object->SetCastShadows(true); RigidBody* body = objectNode->CreateComponent<RigidBody>(); body->SetCollisionLayer(2); // Bigger boxes will be heavier and harder to move //body->SetMass(scale * 2.0f); CollisionShape* shape = objectNode->CreateComponent<CollisionShape>(); shape->SetBox(Vector3(2, 2, 2)); } } } CreateCoins(); CreateBlock(1); }
//------------------- //------------------- void VaniaDebugEnv::Setup(SharedPtr<Scene> scene, SharedPtr<Node> cameraNode) { scene_ = scene; cameraNode_ = cameraNode; ResourceCache* cache = GetSubsystem<ResourceCache>(); // Create scene node & StaticModel component for showing a static plane /*Node* planeNode = scene_->CreateChild("Plane"); planeNode->SetScale(Vector3(100.0f, 1.0f, 100.0f)); StaticModel* planeObject = planeNode->CreateComponent<StaticModel>(); planeObject->SetModel(cache->GetResource<Model>("Models/Plane.mdl")); planeObject->SetMaterial(cache->GetResource<Material>("Materials/StoneTiled.xml"));*/ // Create a Zone component for ambient lighting & fog control Node* zoneNode = scene_->CreateChild("Zone"); Zone* zone = zoneNode->CreateComponent<Zone>(); zone->SetBoundingBox(BoundingBox(-1000.0f, 1000.0f)); zone->SetAmbientColor(Color(0.15f, 0.15f, 0.15f)); zone->SetFogColor(Color(0.5f, 0.5f, 0.7f)); zone->SetFogStart(100.0f); zone->SetFogEnd(300.0f); // Create a directional light to the world. Enable cascaded shadows on it Node* lightNode = scene_->CreateChild("DirectionalLight"); lightNode->SetDirection(Vector3(0.6f, -1.0f, 0.8f)); Light* light = lightNode->CreateComponent<Light>(); light->SetLightType(LIGHT_DIRECTIONAL); light->SetCastShadows(true); light->SetShadowBias(BiasParameters(0.00025f, 0.5f)); // Set cascade splits at 10, 50 and 200 world units, fade shadows out at 80% of maximum shadow distance light->SetShadowCascade(CascadeParameters(10.0f, 50.0f, 200.0f, 0.0f, 0.8f)); // Create animated models /*const unsigned NUM_MODELS = 100; const float MODEL_MOVE_SPEED = 2.0f; const float MODEL_ROTATE_SPEED = 100.0f; const BoundingBox bounds(Vector3(-47.0f, 0.0f, -47.0f), Vector3(47.0f, 0.0f, 47.0f)); for (unsigned i = 0; i < NUM_MODELS; ++i) { Node* modelNode = scene_->CreateChild("Jack"); modelNode->SetPosition(Vector3(Random(90.0f) - 45.0f, 0.0f, Random(90.0f) - 45.0f)); modelNode->SetRotation(Quaternion(0.0f, Random(360.0f), 0.0f)); AnimatedModel* modelObject = modelNode->CreateComponent<AnimatedModel>(); modelObject->SetModel(cache->GetResource<Model>("Models/Jack.mdl")); modelObject->SetMaterial(cache->GetResource<Material>("Materials/Jack.xml")); modelObject->SetCastShadows(true); // Create an AnimationState for a walk animation. Its time position will need to be manually updated to advance the // animation, The alternative would be to use an AnimationController component which updates the animation automatically, // but we need to update the model's position manually in any case Animation* walkAnimation = cache->GetResource<Animation>("Models/Jack_Walk.ani"); AnimationState* state = modelObject->AddAnimationState(walkAnimation); // The state would fail to create (return null) if the animation was not found if (state) { // Enable full blending weight and looping state->SetWeight(1.0f); state->SetLooped(true); } // Create our custom Mover component that will move & animate the model during each frame's update //Mover* mover = modelNode->CreateComponent<Mover>(); //mover->SetParameters(MODEL_MOVE_SPEED, MODEL_ROTATE_SPEED, bounds); }*/ { Node* floorNode = scene_->CreateChild("Floor"); floorNode->SetPosition(Vector3(0.0f, -1.0f, 0.0f)); floorNode->SetScale(Vector3(1000.0f, 1.0f, 1000.0f)); StaticModel* floorObject = floorNode->CreateComponent<StaticModel>(); floorObject->SetModel(cache->GetResource<Model>("Models/Box.mdl")); floorObject->SetMaterial(cache->GetResource<Material>("Materials/StoneTiled.xml")); // Make the floor physical by adding RigidBody and CollisionShape components. The RigidBody's default // parameters make the object static (zero mass.) Note that a CollisionShape by itself will not participate // in the physics simulation RigidBody* body = floorNode->CreateComponent<RigidBody>(); CollisionShape* shape = floorNode->CreateComponent<CollisionShape>(); body->SetCollisionLayer(32); body->SetCollisionMask(63); // Set a box shape of size 1 x 1 x 1 for collision. The shape will be scaled with the scene node scale, so the // rendering and physics representation sizes should match (the box model is also 1 x 1 x 1.) shape->SetBox(Vector3::ONE); } /*Node* stateNode = scene_->CreateChild("state"); stateNode->SetPosition(positions_[0]); StaticModel* stateModel = stateNode->CreateComponent<StaticModel>(); stateModel->SetModel( cache->GetResource<Model>(String("Models/States/")+states_[0]) );*/ // Create the camera. Limit far clip distance to match the fog //cameraNode_ = scene_->CreateChild("Camera"); //Camera* camera = cameraNode_->CreateComponent<Camera>(); //camera->SetFarClip(300.0f); // Set an initial position for the camera scene node above the plane cameraNode_->SetPosition(Vector3(0.0f, 5.0f, 0.0f)); //give the camera the logic I want //CameraLogic* cameralogic = cameraNode_->CreateComponent<CameraLogic>(); }
void VehicleDemo::CreateScene() { ResourceCache* cache = GetSubsystem<ResourceCache>(); scene_ = new Scene(context_); // Create scene subsystem components scene_->CreateComponent<Octree>(); scene_->CreateComponent<PhysicsWorld>(); scene_->CreateComponent<DebugRenderer>(); // Create camera and define viewport. We will be doing load / save, so it's convenient to create the camera outside the scene, // so that it won't be destroyed and recreated, and we don't have to redefine the viewport on load cameraNode_ = new Node(context_); Camera* camera = cameraNode_->CreateComponent<Camera>(); camera->SetFarClip(500.0f); GetSubsystem<Renderer>()->SetViewport(0, new Viewport(context_, scene_, camera)); //GetSubsystem<Renderer>()->SetHDRRendering(true); RenderPath* effectRenderPath=GetSubsystem<Renderer>()->GetViewport(0)->GetRenderPath(); //effectRenderPath->Append(cache->GetResource<XMLFile>("PostProcess/AutoExposure.xml")); effectRenderPath->Append(cache->GetResource<XMLFile>("PostProcess/Blur.xml")); effectRenderPath->SetShaderParameter("BlurRadius", Variant(0.002f) ); effectRenderPath->SetShaderParameter("BlurSigma", Variant(0.001f) ); effectRenderPath->SetEnabled("Blur", false); // Create static scene content. First create a zone for ambient lighting and fog control Node* zoneNode = scene_->CreateChild("Zone"); Zone* zone = zoneNode->CreateComponent<Zone>(); //zone->SetAmbientColor(Color(0.15f, 0.15f, 0.15f)); zone->SetFogColor(Color(0.2f, 0.2f, 0.3f)); zone->SetFogStart(300.0f); zone->SetFogEnd(500.0f); zone->SetBoundingBox(BoundingBox(-2000.0f, 2000.0f)); /* // Create a directional light with cascaded shadow mapping Node* lightNode = scene_->CreateChild("DirectionalLight"); lightNode->SetDirection(Vector3(0.3f, -0.5f, 0.425f)); Light* light = lightNode->CreateComponent<Light>(); light->SetLightType(LIGHT_DIRECTIONAL); light->SetCastShadows(true); light->SetShadowBias(BiasParameters(0.00025f, 0.5f)); light->SetShadowCascade(CascadeParameters(20.0f, 50.0f, 200.0f, 0.0f, 0.8f)); light->SetSpecularIntensity(0.5f); */ // Create heightmap terrain with collision Node* terrainNode = scene_->CreateChild("Terrain"); terrainNode->SetPosition(Vector3::ZERO); Terrain* terrain = terrainNode->CreateComponent<Terrain>(); terrain->SetPatchSize(64); terrain->SetSpacing(Vector3(2.0f, 0.1f, 2.0f)); // Spacing between vertices and vertical resolution of the height map terrain->SetSmoothing(true); terrain->SetHeightMap(cache->GetResource<Image>("Textures/HeightMap.png")); terrain->SetMaterial(cache->GetResource<Material>("Materials/Terrain.xml")); // The terrain consists of large triangles, which fits well for occlusion rendering, as a hill can occlude all // terrain patches and other objects behind it terrain->SetOccluder(true); RigidBody* body = terrainNode->CreateComponent<RigidBody>(); body->SetCollisionLayer(2); // Use layer bitmask 2 for static geometry CollisionShape* shape = terrainNode->CreateComponent<CollisionShape>(); shape->SetTerrain(); // Create skybox. The Skybox component is used like StaticModel, but it will be always located at the camera, giving the // illusion of the box planes being far away. Use just the ordinary Box model and a suitable material, whose shader will // generate the necessary 3D texture coordinates for cube mapping /* Node* skyNode2 = scene_->CreateChild("Sky"); skyNode2->SetScale(80.0f); // The scale actually does not matter Skybox* skybox2 = skyNode2->CreateComponent<Skybox>(); skybox2->SetModel(cache->GetResource<Model>("Models/Box.mdl")); skybox2->SetMaterial(cache->GetResource<Material>("Materials/Skybox.xml")); */ Node* skyNode = scene_->CreateChild("ProcSkyNode"); skyNode->SetEnabled(true); skyNode->SetName("ProcSkyNode"); skyNode->SetPosition(Urho3D::Vector3(0.0, 0.0, 0.0)); skyNode->SetRotation(Urho3D::Quaternion(1, 0, 0, 0)); skyNode->SetScale(Urho3D::Vector3(100.0, 100.0, 100.0)); ProcSky* procSky = skyNode->CreateComponent<ProcSky>(); procSky->SetEnabled(true); Node* skyLightNode = skyNode->CreateChild("ProcSkyLight"); skyLightNode->SetEnabled(true); skyLightNode->SetPosition(Urho3D::Vector3(0.0, 0.0, 0.0)); skyLightNode->SetRotation(Urho3D::Quaternion(0.707107, 0, -0.707107, 0)); skyLightNode->SetScale(Urho3D::Vector3(1, 1, 1)); Light* skyLight = skyLightNode->CreateComponent<Light>(); skyLight->SetLightType(LIGHT_DIRECTIONAL); skyLight->SetColor(Urho3D::Color(0.753, 0.749, 0.678, 1)); skyLight->SetSpecularIntensity(0); skyLight->SetOccludee(false); skyLight->SetOccluder(false); skyLight->SetCastShadows(true); skyLight->SetShadowCascade(Urho3D::CascadeParameters(20, 50, 100, 500, 0.8f)); skyLight->SetShadowFocus(Urho3D::FocusParameters(true, true, true, 1.0f, 5.0f)); skyLight->SetShadowBias(Urho3D::BiasParameters(1e-005, 0.001)); if (skyNode) { //ProcSky* procSky(skyNode->GetComponent<ProcSky>()); if (procSky) { // Can set other parameters here; e.g., SetUpdateMode(), SetUpdateInterval(), SetRenderSize() procSky->Initialize(); URHO3D_LOGINFO("ProcSky Initialized."); } else { URHO3D_LOGERROR("ProcSky node missing ProcSky component."); } } else { URHO3D_LOGERROR("ProcSky node not found in scene."); } // Create 1000 mushrooms in the terrain. Always face outward along the terrain normal /* const unsigned NUM_MUSHROOMS = 0; for (unsigned i = 0; i < NUM_MUSHROOMS; ++i) { Node* objectNode = scene_->CreateChild("SafetyCone"); Vector3 position(Random(2000.0f) - 1000.0f, 0.0f, Random(2000.0f) - 1000.0f); position.y_ = terrain->GetHeight(position); objectNode->SetPosition(position); // Create a rotation quaternion from up vector to terrain normal objectNode->SetRotation(Quaternion(Vector3::UP, terrain->GetNormal(position))); objectNode->SetScale(3.0f); StaticModel* object = objectNode->CreateComponent<StaticModel>(); object->SetModel(cache->GetResource<Model>("MyProjects/SafetyCone/SafetyCone.mdl")); object->SetMaterial(cache->GetResource<Material>("MyProjects/SafetyCone/ConeBase.xml")); object->SetMaterial(cache->GetResource<Material>("MyProjects/SafetyCone/SafetyCone.xml")); object->SetCastShadows(true); RigidBody* body = objectNode->CreateComponent<RigidBody>(); //body->SetCollisionLayer(2); body->SetMass(2.0f); body->SetFriction(0.75f); CollisionShape* shape = objectNode->CreateComponent<CollisionShape>(); //shape->SetTriangleMesh(object->GetModel(), 0); shape->SetConvexHull(object->GetModel(), 0); } */ }