本文整理汇总了C++中StaticModel类的典型用法代码示例。如果您正苦于以下问题:C++ StaticModel类的具体用法?C++ StaticModel怎么用?C++ StaticModel使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了StaticModel类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: GetContext
void Water::CreateScene()
{
ResourceCache* cache = GetContext()->m_ResourceCache.get();
scene_ = new Scene(GetContext());
// Create octree, use default volume (-1000, -1000, -1000) to (1000, 1000, 1000)
scene_->CreateComponent<Octree>();
// 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(1.0f, 1.0f, 1.0f));
zone->SetFogStart(500.0f);
zone->SetFogEnd(750.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));
light->SetShadowCascade(CascadeParameters(10.0f, 50.0f, 200.0f, 0.0f, 0.8f));
light->SetSpecularIntensity(0.5f);
// Apply slightly overbright lighting to match the skybox
light->SetColor(Color(1.2f, 1.2f, 1.2f));
// 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* skyNode = scene_->CreateChild("Sky");
skyNode->SetScale(500.0f); // The scale actually does not matter
Skybox* skybox = skyNode->CreateComponent<Skybox>();
skybox->SetModel(cache->GetResource<Model>("Models/Box.mdl"));
skybox->SetMaterial(cache->GetResource<Material>("Materials/Skybox.xml"));
// Create heightmap terrain
Node* terrainNode = scene_->CreateChild("Terrain");
terrainNode->SetPosition(Vector3(0.0f, 0.0f, 0.0f));
Terrain* terrain = terrainNode->CreateComponent<Terrain>();
terrain->SetPatchSize(64);
terrain->SetSpacing(Vector3(2.0f, 0.5f, 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);
// Create 1000 boxes in the terrain. Always face outward along the terrain normal
unsigned NUM_OBJECTS = 1000;
for (unsigned i = 0; i < NUM_OBJECTS; ++i)
{
Node* objectNode = scene_->CreateChild("Box");
Vector3 position(Random(2000.0f) - 1000.0f, 0.0f, Random(2000.0f) - 1000.0f);
position.y_ = terrain->GetHeight(position) + 2.25f;
objectNode->SetPosition(position);
// Create a rotation quaternion from up vector to terrain normal
objectNode->SetRotation(Quaternion(Vector3(0.0f, 1.0f, 0.0f), terrain->GetNormal(position)));
objectNode->SetScale(5.0f);
StaticModel* object = objectNode->CreateComponent<StaticModel>();
object->SetModel(cache->GetResource<Model>("Models/Box.mdl"));
object->SetMaterial(cache->GetResource<Material>("Materials/Stone.xml"));
object->SetCastShadows(true);
}
Node* shipNode = scene_->CreateChild("Ship");
shipNode->SetPosition(Vector3(0.0f, 4.6f, 0.0f));
//shipNode->SetRotation(Quaternion(0.0f, Random(360.0f), 0.0f));
shipNode->SetScale(0.5f + Random(2.0f));
StaticModel* shipObject = shipNode->CreateComponent<StaticModel>();
shipObject->SetModel(cache->GetResource<Model>("Models/ship04.mdl"));
shipObject->SetMaterial(0,cache->GetResource<Material>("Materials/ship04_Material0.xml"));
shipObject->SetMaterial(1,cache->GetResource<Material>("Materials/ship04_Material1.xml"));
shipObject->SetMaterial(2,cache->GetResource<Material>("Materials/ship04_Material2.xml"));
shipObject->SetCastShadows(true);
// Create a water plane object that is as large as the terrain
waterNode_ = scene_->CreateChild("Water");
waterNode_->SetScale(Vector3(2048.0f, 1.0f, 2048.0f));
waterNode_->SetPosition(Vector3(0.0f, 5.0f, 0.0f));
StaticModel* water = waterNode_->CreateComponent<StaticModel>();
water->SetModel(cache->GetResource<Model>("Models/Plane.mdl"));
water->SetMaterial(cache->GetResource<Material>("Materials/Water.xml"));
// Set a different viewmask on the water plane to be able to hide it from the reflection camera
water->SetViewMask(0x80000000);
// Create the camera. Set far clip to match the fog. Note: now we actually create the camera node outside
// the scene, because we want it to be unaffected by scene load / save
cameraNode_ = new Node(GetContext());
Camera* camera = cameraNode_->CreateComponent<Camera>();
camera->setFarClipDistance(750.0f);
// Set an initial position for the camera scene node above the ground
cameraNode_->SetPosition(Vector3(0.0f, 7.0f, -20.0f));
}
示例2: Scene
void Physics::CreateScene()
{
ResourceCache* cache = GetSubsystem<ResourceCache>();
scene_ = new Scene(context_);
// Create octree, use default volume (-1000, -1000, -1000) to (1000, 1000, 1000)
// Create a physics simulation world with default parameters, which will update at 60fps. Like the Octree must
// exist before creating drawable components, the PhysicsWorld must exist before creating physics components.
// Finally, create a DebugRenderer component so that we can draw physics debug geometry
scene_->CreateComponent<Octree>();
scene_->CreateComponent<PhysicsWorld>();
scene_->CreateComponent<DebugRenderer>();
// 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(1.0f, 1.0f, 1.0f));
zone->SetFogStart(300.0f);
zone->SetFogEnd(500.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 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* skyNode = scene_->CreateChild("Sky");
skyNode->SetScale(500.0f); // The scale actually does not matter
Skybox* skybox = skyNode->CreateComponent<Skybox>();
skybox->SetModel(cache->GetResource<Model>("Models/Box.mdl"));
skybox->SetMaterial(cache->GetResource<Material>("Materials/Skybox.xml"));
{
// Create a floor object, 1000 x 1000 world units. Adjust position so that the ground is at zero Y
Node* floorNode = scene_->CreateChild("Floor");
floorNode->SetPosition(Vector3(0.0f, -0.5f, 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>();
// 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);
}
{
// Create a pyramid of movable physics objects
for (int y = 0; y < 8; ++y)
{
for (int x = -y; x <= y; ++x)
{
Node* boxNode = scene_->CreateChild("Box");
boxNode->SetPosition(Vector3((float)x, -(float)y + 8.0f, 0.0f));
StaticModel* boxObject = boxNode->CreateComponent<StaticModel>();
boxObject->SetModel(cache->GetResource<Model>("Models/Box.mdl"));
boxObject->SetMaterial(cache->GetResource<Material>("Materials/StoneEnvMapSmall.xml"));
boxObject->SetCastShadows(true);
// Create RigidBody and CollisionShape components like above. Give the RigidBody mass to make it movable
// and also adjust friction. The actual mass is not important; only the mass ratios between colliding
// objects are significant
RigidBody* body = boxNode->CreateComponent<RigidBody>();
body->SetMass(1.0f);
body->SetFriction(0.75f);
CollisionShape* shape = boxNode->CreateComponent<CollisionShape>();
shape->SetBox(Vector3::ONE);
}
}
}
// Create the camera. Set far clip to match the fog. Note: now we actually create the camera node outside the scene, because
// we want it to be unaffected by scene load / save
cameraNode_ = new Node(context_);
Camera* camera = cameraNode_->CreateComponent<Camera>();
camera->SetFarClip(500.0f);
// Set an initial position for the camera scene node above the floor
cameraNode_->SetPosition(Vector3(0.0f, 5.0f, -20.0f));
}
示例3: Scene
void SkeletalAnimation::CreateScene()
{
ResourceCache* cache = GetSubsystem<ResourceCache>();
scene_ = new Scene(context_);
// Create octree, use default volume (-1000, -1000, -1000) to (1000, 1000, 1000)
// Also create a DebugRenderer component so that we can draw debug geometry
scene_->CreateComponent<Octree>();
scene_->CreateComponent<DebugRenderer>();
// 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);
state->SetTime(Random(walkAnimation->GetLength()));
}
// 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);
}
// 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));
}
示例4: String
//.........这里部分代码省略.........
Vector3(3.66952991486f,-0.00619999971241f,0.732804954052f),
Vector3(3.72557497025f,-0.00619999971241f,0.641584992409f),
Vector3(3.53317499161f,-0.00904999952763f,1.00545012951f),
Vector3(3.5650601387f,-0.00619999971241f,0.886059999466f),
Vector3(3.40220499039f,-0.00429999921471f,1.02564501762f),
Vector3(3.82462024689f,-0.00239999918267f,0.349364906549f),
Vector3(3.70352506638f,-0.0052499989979f,0.491724967957f),
Vector3(3.60558986664f,-0.0052499989979f,0.511260032654f),
Vector3(3.44979000092f,-0.00429999921471f,0.630430102348f),
Vector3(3.3455851078f,-0.0052499989979f,0.875915110111f),
Vector3(2.3500752449f,-0.0052499989979f,1.56273007393f),
Vector3(3.1991353035f,-0.00144999939948f,1.08977997303f),
Vector3(3.26395010948f,-0.00144999939948f,1.17536497116f),
Vector3(2.79603528976f,-0.00714999902993f,1.73529994488f),
Vector3(2.81455516815f,-0.00144999939948f,1.42764496803f),
Vector3(3.25786995888f,-0.00144999939948f,1.38491988182f),
Vector3(3.21765995026f,-0.00619999971241f,1.58336496353f),
Vector3(3.04369020462f,-0.00429999921471f,1.68953490257f),
Vector3(3.07175517082f,-0.00999999977648f,2.11033010483f),
Vector3(1.79783010483f,0.0185000002384f,0.926185011864f),
Vector3(2.24017524719f,-0.00619999971241f,0.882490038872f),
Vector3(2.32092523575f,-0.0052499989979f,1.23307991028f),
Vector3(2.81634521484f,-0.00429999921471f,1.25435996056f)
};
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));
示例5: Scene
void MasterControl::CreateScene()
{
world_.scene = new Scene(context_);
//Create octree, use default volume (-1000, -1000, -1000) to (1000,1000,1000)
{
world_.scene->CreateComponent<Octree>();
}
//Create the physics
{
PhysicsWorld * const physicsWorld = world_.scene->CreateComponent<PhysicsWorld>();
physicsWorld->SetGravity(Vector3::ZERO);
}
world_.scene->CreateComponent<DebugRenderer>();
//Create an invisible plane for mouse raycasting
world_.voidNode = world_.scene->CreateChild("Void");
//Location is set in update since the plane moves with the camera.
world_.voidNode->SetScale(Vector3(1000.0f, 1.0f, 1000.0f));
StaticModel* planeModel = world_.voidNode->CreateComponent<StaticModel>();
planeModel->SetModel(cache_->GetResource<Model>("Models/Plane.mdl"));
planeModel->SetMaterial(cache_->GetResource<Material>("Materials/Terrain.xml"));
CreateBackground();
{
// 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* skyNode = world_.scene->CreateChild("Sky");
skyNode->SetScale(500.0f); // The scale actually does not matter
Skybox* skybox = skyNode->CreateComponent<Skybox>();
skybox->SetModel(cache_->GetResource<Model>("Models/Box.mdl"));
skybox->SetMaterial(cache_->GetResource<Material>("Materials/Skybox.xml"));
}
//Create a directional light to the world. Enable cascaded shadows on it
{
Node* lightNode = world_.scene->CreateChild("DirectionalLight");
lightNode->SetDirection(Vector3(0.0f, -1.0f, 0.0f));
Light* light = lightNode->CreateComponent<Light>();
light->SetLightType(LIGHT_DIRECTIONAL);
light->SetBrightness(1.0f);
light->SetColor(Color(1.0f, 0.8f, 0.7f));
light->SetCastShadows(true);
light->SetShadowBias(BiasParameters(0.00025f, 0.5f));
//Set cascade splits at 10, 50, 200 world unitys, fade shadows at 80% of maximum shadow distance
light->SetShadowCascade(CascadeParameters(7.0f, 23.0f, 42.0f, 500.0f, 0.8f));
}
//Create a second directional light without shadows
{
Node * const lightNode = world_.scene->CreateChild("DirectionalLight");
lightNode->SetDirection(Vector3(0.0, 1.0, 0.0));
Light * const light = lightNode->CreateComponent<Light>();
light->SetLightType(LIGHT_DIRECTIONAL);
light->SetBrightness(0.25);
light->SetColor(Color(1.0, 1.0, 1.0));
light->SetCastShadows(true);
light->SetShadowBias(BiasParameters(0.00025f, 0.5f));
}
//Create camera
world_.camera = new CameraMaster(context_, this);
}
示例6: Scene
void PhysicsStressTest::CreateScene()
{
ResourceCache* cache = GetSubsystem<ResourceCache>();
scene_ = new Scene(context_);
// Create octree, use default volume (-1000, -1000, -1000) to (1000, 1000, 1000)
// Create a physics simulation world with default parameters, which will update at 60fps. Like the Octree must
// exist before creating drawable components, the PhysicsWorld must exist before creating physics components.
// Finally, create a DebugRenderer component so that we can draw physics debug geometry
scene_->CreateComponent<Octree>();
scene_->CreateComponent<PhysicsWorld>();
scene_->CreateComponent<DebugRenderer>();
// 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 a floor object, 500 x 500 world units. Adjust position so that the ground is at zero Y
Node* floorNode = scene_->CreateChild("Floor");
floorNode->SetPosition(Vector3(0.0f, -0.5f, 0.0f));
floorNode->SetScale(Vector3(500.0f, 1.0f, 500.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
RigidBody* body = floorNode->CreateComponent<RigidBody>();
CollisionShape* shape = floorNode->CreateComponent<CollisionShape>();
shape->SetBox(Vector3::ONE);
}
{
// Create static mushrooms with triangle mesh collision
const unsigned NUM_MUSHROOMS = 50;
for (unsigned i = 0; i < NUM_MUSHROOMS; ++i)
{
Node* mushroomNode = scene_->CreateChild("Mushroom");
mushroomNode->SetPosition(Vector3(Random(400.0f) - 200.0f, 0.0f, Random(400.0f) - 200.0f));
mushroomNode->SetRotation(Quaternion(0.0f, Random(360.0f), 0.0f));
mushroomNode->SetScale(5.0f + Random(5.0f));
StaticModel* mushroomObject = mushroomNode->CreateComponent<StaticModel>();
mushroomObject->SetModel(cache->GetResource<Model>("Models/Mushroom.mdl"));
mushroomObject->SetMaterial(cache->GetResource<Material>("Materials/Mushroom.xml"));
mushroomObject->SetCastShadows(true);
RigidBody* body = mushroomNode->CreateComponent<RigidBody>();
CollisionShape* shape = mushroomNode->CreateComponent<CollisionShape>();
// By default the highest LOD level will be used, the LOD level can be passed as an optional parameter
shape->SetTriangleMesh(mushroomObject->GetModel());
}
}
{
// Create a large amount of falling physics objects
const unsigned NUM_OBJECTS = 1000;
for (unsigned i = 0; i < NUM_OBJECTS; ++i)
{
Node* boxNode = scene_->CreateChild("Box");
boxNode->SetPosition(Vector3(0.0f, i * 2.0f + 100.0f, 0.0f));
StaticModel* boxObject = boxNode->CreateComponent<StaticModel>();
boxObject->SetModel(cache->GetResource<Model>("Models/Box.mdl"));
boxObject->SetMaterial(cache->GetResource<Material>("Materials/StoneSmall.xml"));
boxObject->SetCastShadows(true);
// Give the RigidBody mass to make it movable and also adjust friction
RigidBody* body = boxNode->CreateComponent<RigidBody>();
body->SetMass(1.0f);
body->SetFriction(1.0f);
// Disable collision event signaling to reduce CPU load of the physics simulation
body->SetCollisionEventMode(COLLISION_NEVER);
CollisionShape* shape = boxNode->CreateComponent<CollisionShape>();
shape->SetBox(Vector3::ONE);
}
}
// Create the camera. Limit far clip distance to match the fog. Note: now we actually create the camera node outside
// the scene, because we want it to be unaffected by scene load / save
cameraNode_ = new Node(context_);
Camera* camera = cameraNode_->CreateComponent<Camera>();
camera->SetFarClip(300.0f);
// Set an initial position for the camera scene node above the floor
cameraNode_->SetPosition(Vector3(0.0f, 3.0f, -20.0f));
//.........这里部分代码省略.........
示例7: Scene
void MasterControl::CreateScene()
{
world.scene = new Scene(context_);
world.octree = world.scene->CreateComponent<Octree>();
physicsWorld_ = world.scene->CreateComponent<PhysicsWorld>();
physicsWorld_->SetGravity(Vector3::ZERO);
world.scene->CreateComponent<DebugRenderer>();
//Create a Zone component for ambient ing & fog control
Node* zoneNode = world.scene->CreateChild("Zone");
Zone* zone = zoneNode->CreateComponent<Zone>();
zone->SetBoundingBox(BoundingBox(Vector3(-100.0f, -50.0f, -100.0f),Vector3(100.0f, 0.0f, 100.0f)));
zone->SetAmbientColor(Color(0.15f, 0.15f, 0.15f));
zone->SetFogColor(Color(0.0f, 0.0f, 0.0f));
zone->SetFogStart(56.8f);
zone->SetFogEnd(61.8f);
//Add a directional light to the world. Enable cascaded shadows on it
Node* lightNode = world.scene->CreateChild("PointLight");
lightNode->SetPosition(Vector3::UP*5.0);
lightNode->SetRotation(Quaternion(90.0f, 0.0f, 0.0f));
Light* light = lightNode->CreateComponent<Light>();
light->SetLightType(LIGHT_DIRECTIONAL);
light->SetBrightness(1.0f);
light->SetRange(7.0f);
light->SetColor(Color(1.0f, 0.9f, 0.95f));
light->SetCastShadows(false);
light->SetShadowBias(BiasParameters(0.00025f, 0.5f));
//Set cascade splits at 10, 50, 200 world unitys, fade shadows at 80% of maximum shadow distance
light->SetShadowCascade(CascadeParameters(7.0f, 23.0f, 42.0f, 500.0f, 0.8f));
//Create cursor
world.cursor.sceneCursor = world.scene->CreateChild("Cursor");
//world.cursor.sceneCursor->SetPosition(Vector3(0.0f,0.0f,0.0f));
StaticModel* cursorObject = world.cursor.sceneCursor->CreateComponent<StaticModel>();
cursorObject->SetModel(cache_->GetResource<Model>("Resources/Models/Hexagon.mdl"));
cursorObject->SetMaterial(cache_->GetResource<Material>("Resources/Materials/Glow.xml"));
world.cursor.sceneCursor->SetEnabled(false);
//Create an invisible plane for mouse raycasting
world.voidNode = world.scene->CreateChild("Void");
//Location is set in update since the plane moves with the camera.
world.voidNode->SetScale(Vector3(1000.0f, 1.0f, 1000.0f));
StaticModel* planeObject = world.voidNode->CreateComponent<StaticModel>();
planeObject->SetModel(cache_->GetResource<Model>("Models/Plane.mdl"));
planeObject->SetMaterial(cache_->GetResource<Material>("Resources/Materials/Invisible.xml"));
//Create camera
world.camera = new heXoCam(context_, this);
//Create arena
tileMaster_ = new TileMaster(context_, this);
for (int i = 0; i < 6; i++){
new ArenaEdge(context_, this, (60.0f * i)+30.0f);
}
spawnMaster_ = new SpawnMaster(context_, this);
player_ = new Player(context_, this);
apple_ = new Apple(context_, this);
heart_ = new Heart(context_, this);
}
示例8: bounds
//-------------------
//-------------------
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);
//.........这里部分代码省略.........
示例9: Scene
void GameApplication::CreateScene()
{
ResourceCache* cache = GetSubsystem<ResourceCache>();
scene_ = new Scene(context_);
// Create octree, use default volume (-1000, -1000, -1000) to (1000, 1000, 1000)
// Also create a DebugRenderer component so that we can draw debug geometry
scene_->CreateComponent<Octree>();
scene_->CreateComponent<DebugRenderer>();
// 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/dikuang.mdl"));
Material* material = cache->GetResource<Material>("Materials/Water.xml");
planeObject->SetMaterial(material); //dikuang
// 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.3f, 0.3f, 0.3f));
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.2f, -0.5f, -0.1f));
Light* light = lightNode->CreateComponent<Light>();
light->SetLightType(LIGHT_DIRECTIONAL);
// light->SetSpecularIntensity(3);
light->SetBrightness(1);
light->SetCastShadows(true);
light->SetShadowBias(BiasParameters(0.0001f, 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));
InitGridModels();
// Create the camera. Limit far clip distance to match the fog
cameraNode_ = scene_->CreateChild("Camera");
Camera* camera = cameraNode_->CreateComponent<Camera>();
//float fZoom = camera->GetFov();
//camera->SetFov(fZoom);
camera->SetFarClip(300.0f);
// Set an initial position for the camera scene node above the plane
cameraNode_->SetPosition(Vector3(0.2318,7.5248,-0.2721));
yaw_ = 0.10003410;
pitch_ = 90;
// cameraNode_->SetPosition(Vector3(5.0f, 5.0f, -15.0f));
//pitch_ = 19;
cameraNode_->SetRotation(Quaternion(pitch_, yaw_, 0.0f));
}
示例10: Scene
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);
}
}
示例11: Scene
void Navigation::CreateScene()
{
ResourceCache* cache = GetSubsystem<ResourceCache>();
scene_ = new Scene(context_);
// Create octree, use default volume (-1000, -1000, -1000) to (1000, 1000, 1000)
// Also create a DebugRenderer component so that we can draw debug geometry
scene_->CreateComponent<Octree>();
scene_->CreateComponent<DebugRenderer>();
// 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 some mushrooms
const unsigned NUM_MUSHROOMS = 100;
for (unsigned i = 0; i < NUM_MUSHROOMS; ++i)
CreateMushroom(Vector3(Random(90.0f) - 45.0f, 0.0f, Random(90.0f) - 45.0f));
// Create randomly sized boxes. If boxes are big enough, make them occluders
const unsigned NUM_BOXES = 20;
for (unsigned i = 0; i < NUM_BOXES; ++i)
{
Node* boxNode = scene_->CreateChild("Box");
float size = 1.0f + Random(10.0f);
boxNode->SetPosition(Vector3(Random(80.0f) - 40.0f, size * 0.5f, Random(80.0f) - 40.0f));
boxNode->SetScale(size);
StaticModel* boxObject = boxNode->CreateComponent<StaticModel>();
boxObject->SetModel(cache->GetResource<Model>("Models/Box.mdl"));
boxObject->SetMaterial(cache->GetResource<Material>("Materials/Stone.xml"));
boxObject->SetCastShadows(true);
if (size >= 3.0f)
boxObject->SetOccluder(true);
}
// Create Jack node that will follow the path
jackNode_ = scene_->CreateChild("Jack");
jackNode_->SetPosition(Vector3(-5.0f, 0.0f, 20.0f));
AnimatedModel* modelObject = jackNode_->CreateComponent<AnimatedModel>();
modelObject->SetModel(cache->GetResource<Model>("Models/Jack.mdl"));
modelObject->SetMaterial(cache->GetResource<Material>("Materials/Jack.xml"));
modelObject->SetCastShadows(true);
// Create a NavigationMesh component to the scene root
NavigationMesh* navMesh = scene_->CreateComponent<NavigationMesh>();
// Create a Navigable component to the scene root. This tags all of the geometry in the scene as being part of the
// navigation mesh. By default this is recursive, but the recursion could be turned off from Navigable
scene_->CreateComponent<Navigable>();
// Add padding to the navigation mesh in Y-direction so that we can add objects on top of the tallest boxes
// in the scene and still update the mesh correctly
navMesh->SetPadding(Vector3(0.0f, 10.0f, 0.0f));
// Now build the navigation geometry. This will take some time. Note that the navigation mesh will prefer to use
// physics geometry from the scene nodes, as it often is simpler, but if it can not find any (like in this example)
// it will use renderable geometry instead
navMesh->Build();
// 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 and looking down
cameraNode_->SetPosition(Vector3(0.0f, 50.0f, 0.0f));
pitch_ = 80.0f;
cameraNode_->SetRotation(Quaternion(pitch_, yaw_, 0.0f));
}
示例12: Scene
void LuaIntegration::CreateScene()
{
ResourceCache* cache = GetSubsystem<ResourceCache>();
scene_ = new Scene(context_);
// Create the Octree component to the scene so that drawable objects can be rendered. Use default volume
// (-1000, -1000, -1000) to (1000, 1000, 1000)
scene_->CreateComponent<Octree>();
// Create a Zone component into a child scene node. The Zone controls ambient lighting and fog settings. Like the Octree,
// it also defines its volume with a bounding box, but can be rotated (so it does not need to be aligned to the world X, Y
// and Z axes.) Drawable objects "pick up" the zone they belong to and use it when rendering; several zones can exist
Node* zoneNode = scene_->CreateChild("Zone");
Zone* zone = zoneNode->CreateComponent<Zone>();
// Set same volume as the Octree, set a close bluish fog and some ambient light
zone->SetBoundingBox(BoundingBox(-1000.0f, 1000.0f));
zone->SetAmbientColor(Color(0.05f, 0.1f, 0.15f));
zone->SetFogColor(Color(0.1f, 0.2f, 0.3f));
zone->SetFogStart(10.0f);
zone->SetFogEnd(100.0f);
LuaFile* scriptFile = cache->GetResource<LuaFile>("LuaScripts/Rotator.lua");
if (!scriptFile)
return;
// Create randomly positioned and oriented box StaticModels in the scene
const unsigned NUM_OBJECTS = 2000;
for (unsigned i = 0; i < NUM_OBJECTS; ++i)
{
Node* boxNode = scene_->CreateChild("Box");
boxNode->SetPosition(Vector3(Random(200.0f) - 100.0f, Random(200.0f) - 100.0f, Random(200.0f) - 100.0f));
// Orient using random pitch, yaw and roll Euler angles
boxNode->SetRotation(Quaternion(Random(360.0f), Random(360.0f), Random(360.0f)));
StaticModel* boxObject = boxNode->CreateComponent<StaticModel>();
boxObject->SetModel(cache->GetResource<Model>("Models/Box.mdl"));
boxObject->SetMaterial(cache->GetResource<Material>("Materials/Stone.xml"));
// Add our custom Rotator script object (using the LuaScriptInstance C++ component to instantiate / store it) which will
// rotate the scene node each frame, when the scene sends its update event
LuaScriptInstance* instance = boxNode->CreateComponent<LuaScriptInstance>();
instance->CreateObject(scriptFile, "Rotator");
// Call the script object's "SetRotationSpeed" function.
WeakPtr<LuaFunction> function = instance->GetScriptObjectFunction("SetRotationSpeed");
if (function && function->BeginCall(instance))
{
function->PushUserType(Vector3(10.0f, 20.0f, 30.0f), "Vector3");
function->EndCall();
}
}
// Create the camera. Let the starting position be at the world origin. As the fog limits maximum visible distance, we can
// bring the far clip plane closer for more effective culling of distant objects
cameraNode_ = scene_->CreateChild("Camera");
Camera* camera = cameraNode_->CreateComponent<Camera>();
camera->SetFarClip(100.0f);
// Create a point light to the camera scene node
Light* light = cameraNode_->CreateComponent<Light>();
light->SetLightType(LIGHT_POINT);
light->SetRange(30.0f);
}
示例13: Scene
void SignedDistanceFieldText::CreateScene()
{
ResourceCache* cache = GetSubsystem<ResourceCache>();
scene_ = new Scene(context_);
// Create the Octree component to the scene. This is required before adding any drawable components, or else nothing will
// show up. The default octree volume will be from (-1000, -1000, -1000) to (1000, 1000, 1000) in world coordinates; it
// is also legal to place objects outside the volume but their visibility can then not be checked in a hierarchically
// optimizing manner
scene_->CreateComponent<Octree>();
// Create a child scene node (at world origin) and a StaticModel component into it. Set the StaticModel to show a simple
// plane mesh with a "stone" material. Note that naming the scene nodes is optional. Scale the scene node larger
// (100 x 100 world units)
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 directional light to the world so that we can see something. The light scene node's orientation controls the
// light direction; we will use the SetDirection() function which calculates the orientation from a forward direction vector.
// The light will use default settings (white light, no shadows)
Node* lightNode = scene_->CreateChild("DirectionalLight");
lightNode->SetDirection(Vector3(0.6f, -1.0f, 0.8f)); // The direction vector does not need to be normalized
Light* light = lightNode->CreateComponent<Light>();
light->SetLightType(LIGHT_DIRECTIONAL);
// Create more StaticModel objects to the scene, randomly positioned, rotated and scaled. For rotation, we construct a
// quaternion from Euler angles where the Y angle (rotation about the Y axis) is randomized. The mushroom model contains
// LOD levels, so the StaticModel component will automatically select the LOD level according to the view distance (you'll
// see the model get simpler as it moves further away). Finally, rendering a large number of the same object with the
// same material allows instancing to be used, if the GPU supports it. This reduces the amount of CPU work in rendering the
// scene.
const unsigned NUM_OBJECTS = 200;
for (unsigned i = 0; i < NUM_OBJECTS; ++i)
{
Node* mushroomNode = scene_->CreateChild("Mushroom");
mushroomNode->SetPosition(Vector3(Random(90.0f) - 45.0f, 0.0f, Random(90.0f) - 45.0f));
mushroomNode->SetScale(0.5f + Random(2.0f));
StaticModel* mushroomObject = mushroomNode->CreateComponent<StaticModel>();
mushroomObject->SetModel(cache->GetResource<Model>("Models/Mushroom.mdl"));
mushroomObject->SetMaterial(cache->GetResource<Material>("Materials/Mushroom.xml"));
Node* mushroomTitleNode = mushroomNode->CreateChild("MushroomTitle");
mushroomTitleNode->SetPosition(Vector3(0.0f, 1.2f, 0.0f));
Text3D* mushroomTitleText = mushroomTitleNode->CreateComponent<Text3D>();
mushroomTitleText->SetText("Mushroom " + String(i));
mushroomTitleText->SetFont(cache->GetResource<Font>("Fonts/BlueHighway.sdf"), 24);
mushroomTitleText->SetColor(Color::RED);
if (i % 3 == 1)
{
mushroomTitleText->SetColor(Color::GREEN);
mushroomTitleText->SetTextEffect(TE_SHADOW);
mushroomTitleText->SetEffectColor(Color(0.5f, 0.5f, 0.5f));
}
else if (i % 3 == 2)
{
mushroomTitleText->SetColor(Color::YELLOW);
mushroomTitleText->SetTextEffect(TE_STROKE);
mushroomTitleText->SetEffectColor(Color(0.5f, 0.5f, 0.5f));
}
mushroomTitleText->SetAlignment(HA_CENTER, VA_CENTER);
}
// Create a scene node for the camera, which we will move around
// The camera will use default settings (1000 far clip distance, 45 degrees FOV, set aspect ratio automatically)
cameraNode_ = scene_->CreateChild("Camera");
cameraNode_->CreateComponent<Camera>();
// Set an initial position for the camera scene node above the plane
cameraNode_->SetPosition(Vector3(0.0f, 5.0f, 0.0f));
}
示例14: StaticModel
//! Loads and returns a static model from a file.
StaticModel* ModelImporter::LoadStaticModel(string filename)
{
// Is the model already loaded?
if(mStaticModelMap.find(filename) != mStaticModelMap.end())
return mStaticModelMap[filename];
Assimp::Importer importer;
mFilename = filename;
StaticModel* model = NULL;
// Important! Makes sure that if the angle between two face normals is > 80 they are not smoothed together.
// Since the angle between a cubes face normals is 90 the lighting looks very bad if we don't specify this.
importer.SetPropertyFloat(AI_CONFIG_PP_GSN_MAX_SMOOTHING_ANGLE, 80.0f);
importer.SetPropertyInteger(AI_CONFIG_IMPORT_TER_MAKE_UVS, 1);
importer.SetPropertyInteger(AI_CONFIG_PP_SBP_REMOVE, aiPrimitiveType_LINE);
// Load scene from the file.
const aiScene* scene = importer.ReadFile(filename,
aiProcess_CalcTangentSpace |
aiProcess_Triangulate |
aiProcess_GenSmoothNormals |
aiProcess_SplitLargeMeshes |
aiProcess_ConvertToLeftHanded |
aiProcess_SortByPType);
// Successfully loaded the scene.
if(scene)
{
// Create the model that is getting filled out.
model = new StaticModel();
// Loop through all meshes.
for(int i = 0; i < scene->mNumMeshes; i++)
{
aiMesh* assimpMesh = scene->mMeshes[i];
vector<Vertex> vertices;
vector<UINT> indices;
// Add vertices to the vertex list.
for(int i = 0; i < assimpMesh->mNumVertices; i++)
{
aiVector3D v = assimpMesh->mVertices[i];
aiVector3D n = assimpMesh->mNormals[i];
aiVector3D t = aiVector3D(0, 0, 0);
if(assimpMesh->HasTextureCoords(0))
t = assimpMesh->mTextureCoords[0][i];
n = n.Normalize();
Vertex vertex(v.x, v.y, v.z, n.x, n.y, n.z, 0, 0, 0, t.x, t.y);
vertices.push_back(vertex);
}
// Add indices to the index list.
for(int i = 0; i < assimpMesh->mNumFaces; i++)
for(int j = 0; j < assimpMesh->mFaces[i].mNumIndices; j++)
indices.push_back(assimpMesh->mFaces[i].mIndices[j]);
// Get the path to the texture in the directory.
aiString path;
aiMaterial* material = scene->mMaterials[assimpMesh->mMaterialIndex];
material->Get(AI_MATKEY_TEXTURE_DIFFUSE(0), path);
FindValidPath(&path);
// Extract all the ambient, diffuse and specular colors.
aiColor4D ambient, diffuse, specular;
material->Get(AI_MATKEY_COLOR_AMBIENT, ambient);
material->Get(AI_MATKEY_COLOR_DIFFUSE, diffuse);
material->Get(AI_MATKEY_COLOR_SPECULAR, specular);
// Create the mesh and its primitive.
StaticMesh* mesh = new StaticMesh();
Primitive* primitive = new Primitive(GlobalApp::GetD3DDevice(), vertices, indices);
mesh->SetPrimitive(primitive);
mesh->SetVertices(vertices);
mesh->SetIndices(indices);
mPrimtiveFactory->AddPrimitive(path.C_Str(), primitive);
// Any texture?
if(_stricmp(path.C_Str(), "") != 0)
mesh->LoadTexture(path.C_Str());
// Any normal map?
aiString nmap;
material->Get(AI_MATKEY_TEXTURE_HEIGHT(0), nmap);
FindValidPath(&nmap);
if(_stricmp(nmap.C_Str(), "") != 0)
mesh->SetNormalMap(GlobalApp::GetGraphics()->LoadTexture(nmap.C_Str()));
// [NOTE] The material is set to white.
mesh->SetMaterial(Material(Colors::White)); // Was before [NOTE]
model->SetFilename(filename);
// Add the mesh to the model.
model->AddMesh(mesh);
}
// Add to the model map and return it.
mStaticModelMap[filename] = model;
//.........这里部分代码省略.........
示例15: LoadTGATextureData
StaticModel* ModelLoader::GenerateTerrain(VulkanBase* vulkanBase, std::string filename)
{
// Check if the model already is loaded
if (mModelMap.find(filename) != mModelMap.end())
return mModelMap[filename];
// Load the terrain froma .tga file
TextureData texture;
LoadTGATextureData((char*)filename.c_str(), &texture);
StaticModel* terrain = new StaticModel;
Mesh mesh;
int vertexCount = texture.width * texture.height;
int triangleCount = (texture.width - 1) * (texture.height - 1) * 2;
int x, z;
mesh.vertices.resize(vertexCount);
mesh.indices.resize(triangleCount * 3);
printf("bpp %d\n", texture.bpp);
for (x = 0; x < texture.width; x++)
for (z = 0; z < texture.height; z++)
{
// Vertex array. You need to scale this properly
float height = texture.imageData[(x + z * texture.width) * (texture.bpp / 8)] / 15.0f;
vec3 pos = vec3(x / 1.0, height, z / 1.0);
vec3 normal = vec3(0, 0, 0);
vec2 uv = vec2(x / (float)texture.width, z / (float)texture.height);
Vertex vertex = Vertex(pos, normal, uv, vec3(0, 0, 0), vec3(1.0, 1.0, 1.0));
mesh.vertices[x + z * texture.width] = vertex;
}
// Normal vectors. You need to calculate these.
for (x = 0; x < texture.width; x++)
{
for (z = 0; z < texture.height; z++)
{
vec3 p1, p2, p3;
vec3 edge = { 0.0f, 0.0f, 0.0f };
int i1;
// p1 [x-1][z-1]
if (x < 1 && z < 1)
i1 = (x + 1 + (z + 1) * texture.width);
else
i1 = (x - 1 + (z - 1) * texture.width);
// TODO: NOTE: HAX
if (i1 < 0)
i1 = 0;
p1 = mesh.vertices[i1].Pos;
// p1 [x-1][z] (if on the edge use [x+1] instead of [x-1])
int i2;
if (x < 1)
i2 = (x + 1 + (z)* texture.width);
else
i2 = (x - 1 + (z)* texture.width);
p2 = mesh.vertices[i2].Pos;
// p1 [x][z-1]
int i3;
if (z < 1)
i3 = (x + (z + 1) * texture.width);
else
i3 = (x + (z - 1) * texture.width);
p3 = mesh.vertices[i3].Pos;
vec3 e1 = p2 - p1;
vec3 e2 = p3 - p1;
vec3 normal = glm::cross(e2, e1);
if (normal != vec3(0, 0, 0))
int asda = 1;
normal = glm::normalize(normal);
//i = (x + 1 + (z + 1) * texture.width);
mesh.vertices[i1].Normal += normal;
mesh.vertices[i2].Normal += normal;
mesh.vertices[i3].Normal += normal;
// NOTE: Testing
//mesh.vertices[i].Normal = vec3(0, 0, 0);
}
}
for (x = 0; x < texture.width - 1; x++)
{
for (z = 0; z < texture.height - 1; z++)
{
// Triangle 1
mesh.indices[(x + z * (texture.width - 1)) * 6 + 0] = x + z * texture.width;
mesh.indices[(x + z * (texture.width - 1)) * 6 + 1] = x + (z + 1) * texture.width;
//.........这里部分代码省略.........