本文整理汇总了C++中Zone::SetFogColor方法的典型用法代码示例。如果您正苦于以下问题:C++ Zone::SetFogColor方法的具体用法?C++ Zone::SetFogColor怎么用?C++ Zone::SetFogColor使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zone
的用法示例。
在下文中一共展示了Zone::SetFogColor方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: CreateScene
void RTTScene::CreateScene()
{
rttScene_ = new Scene(context_);
rttScene_->CreateComponent<Octree>();
Node* zoneNode = rttScene_->CreateChild("Zone");
Zone* zone = zoneNode->CreateComponent<Zone>();
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);
//用来指定ViewPort时的定位
rttCameraNode_ = rttScene_->CreateChild("Camera");
Camera* camera = rttCameraNode_->CreateComponent<Camera>();
Light* light = rttCameraNode_->CreateComponent<Light>();
light->SetLightType(LIGHT_POINT);
renderTexture = new Texture2D(context_);
//设置当前场景的ViewPort
renderTexture->SetSize(_width,_height,Graphics::GetRGBFormat(),TEXTURE_RENDERTARGET);
RenderSurface* surface = renderTexture->GetRenderSurface();
renderTexture->SetFilterMode(FILTER_BILINEAR);
Viewport* rttViewPort = new Viewport(context_,rttScene_,camera);
surface->SetViewport(0,rttViewPort);
}
示例2: CreateScene
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);
// 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("LuaScripts/Rotator.lua", "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);
}
示例3: CreateScene
void Labyrinth::CreateScene()
{
// ADDED
ResourceCache* cache = GetSubsystem<ResourceCache>();
scene_ = new Scene(context_);
// TODO vzdialenost kamery podla rozlisenia obrazovky
// 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
// TODO treb vytunit poziciu kamery a jej rotaciu
cameraNode_ = new Node(context_);
cameraNode_->SetName("cameraNode");
Camera* camera = cameraNode_->CreateComponent<Camera>();
camera->SetFarClip(300.0f);
// aby to vyzeralo ako 2.5D treba prepnut ortho na true
/*camera->SetOrthographic(false);
cameraNode_->SetPosition(Vector3(10, 90, 10));
cameraNode_->SetRotation(Quaternion(75, 0, 0));
GetSubsystem<Renderer>()->SetViewport(0, new Viewport(context_, scene_, camera));*/
camera->SetOrthographic(false);
cameraNode_->SetPosition(Vector3(0, 10, 0));
cameraNode_->SetRotation(Quaternion(90, 0, 0));
// Create static scene content. First create a zone for ambient lightning 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(1000.0f);
zone->SetFogEnd(1000.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(1.0f);
// ------------------------------------------
CreateFloor(20, 14);
}
示例4: Start
void Sample::Start()
{
context_->RegisterSubsystem(new NanoGUI(context_));
NanoGUI* nanogui = GetSubsystem<NanoGUI>();
if (nanogui)
{
nanogui->Initialize();
}
cache_ = GetSubsystem<ResourceCache>();
ui_ = GetSubsystem<UI>();
graphics_ = GetSubsystem<Graphics>();
//////////////////////////////////////////////////////////////////////////
// Get default styles
XMLFile* styleFile = cache_->GetResource<XMLFile>("UI/DefaultStyle.xml");
ui_->GetRoot()->SetDefaultStyle(styleFile);
// create main ui
rootUI_ = ui_->GetRoot()->CreateChild<UIElement>("IDERoot");
rootUI_->SetSize(ui_->GetRoot()->GetSize());
rootUI_->SetTraversalMode(TM_DEPTH_FIRST); // This is needed for root-like element to prevent artifacts
rootUI_->SetDefaultStyle(styleFile);
//////////////////////////////////////////////////////////////////////////
/// Create console
console_ = engine_->CreateConsole();
console_->SetDefaultStyle(styleFile);
//////////////////////////////////////////////////////////////////////////
/// Create debug HUD.
debugHud_ = engine_->CreateDebugHud();
debugHud_->SetDefaultStyle(styleFile);
//////////////////////////////////////////////////////////////////////////
/// Subscribe key down event
SubscribeToEvent(E_KEYDOWN, HANDLER(Sample, HandleKeyDown));
// edit clear color, set background color
Renderer* renderer = GetSubsystem<Renderer>();
Zone* zone = renderer->GetDefaultZone();
zone->SetFogColor(Color(0.3f, 0.3f, 0.4f)); // Set background color for the scene
//////////////////////////////////////////////////////////////////////////
/// Create Cursor
// Cursor* cursor_ = new Cursor(context_);
// cursor_->SetStyleAuto(styleFile);
// ui_->SetCursor(cursor_);
// if (GetPlatform() == "Android" || GetPlatform() == "iOS")
// ui_->GetCursor()->SetVisible(false);
/// Show Platform Cursor
Input* input = GetSubsystem<Input>();
input->SetMouseVisible(true);
}
示例5: CreateScene
void AnimatingScene::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);
// 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 component which will rotate the scene node each frame, when the scene sends its update event.
// The Rotator component derives from the base class LogicComponent, which has convenience functionality to subscribe
// to the various update events, and forward them to virtual functions that can be implemented by subclasses. This way
// writing logic/update components in C++ becomes similar to scripting.
// Now we simply set same rotation speed for all objects
Rotator* rotator = boxNode->CreateComponent<Rotator>();
rotator->SetRotationSpeed(Vector3(10.0f, 20.0f, 30.0f));
}
// 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);
}
示例6: HandleWhiteBackground
void Typography::HandleWhiteBackground(StringHash eventType, VariantMap& eventData)
{
auto* box = static_cast<CheckBox*>(eventData[Toggled::P_ELEMENT].GetPtr());
bool checked = box->IsChecked();
Color fg = checked ? Color::BLACK : Color::WHITE;
Color bg = checked ? Color::WHITE : Color::BLACK;
auto* renderer = GetSubsystem<Renderer>();
Zone* zone = renderer->GetDefaultZone();
zone->SetFogColor(bg);
PODVector<UIElement*> text = uielement_->GetChildrenWithTag(TEXT_TAG, true);
for (int i = 0; i < text.Size(); i++)
{
text[i]->SetColor(fg);
}
}
示例7: SetupScreenUI
/// Setup the screen UI
void GameEconomicGameClient::SetupScreenUI(void)
{
/// Create a new scene UI
scenePlayerUI_= new Scene(context_);
scenePlayerUI_-> CreateComponent<Octree>();
scenePlayerUI_-> CreateComponent<DebugRenderer>();
/// Add a lightdelightNode
Node* lightNode = scenePlayerUI_->CreateChild("uidirectionallight");
lightNode->SetDirection(Vector3(0.0f, .8f, 3.20f)); /// The direction vector does not need to be normalized
Light* light = lightNode->CreateComponent<Light>();
light->SetLightType(LIGHT_DIRECTIONAL);
/// Create a Zone component for ambient lighting & fog control
Node* zoneNode = scenePlayerUI_->CreateChild("uizone");
Zone* zone = zoneNode->CreateComponent<Zone>();
Vector3 boundingBoxMin(-20.0f,-20.0f,-20.0f);
Vector3 boundingBoxMax(20.0f,20.0f,20.0f);
/// change bounding box to something more accurate
zone->SetBoundingBox(BoundingBox(boundingBoxMin,boundingBoxMax));
zone->SetFogColor(Color(.08f, .08f, .08f));
zone->SetFogStart(10.0f);
zone->SetFogEnd(20.0f);
zone->SetHeightFog (false);
/// Add Camera
Node * cameraNodePlayerUI_ = scenePlayerUI_->CreateChild("uicamera");
cameraNodePlayerUI_->CreateComponent<Camera>();
/// Set an initial position for the camera scene node above the plane
cameraNodePlayerUI_->SetPosition(Vector3(0.0f, 0.8f, 3.0f));
Node * emptyNode= scenePlayerUI_->CreateChild("uiempty");
emptyNode->SetPosition(Vector3(0.0f,0.73f,0.0f));
/// Create character node;
Node * characterNode= scenePlayerUI_->CreateChild("Character");
characterNode->SetPosition(Vector3(0.0f,0.0f,0.0f));
cameraNodePlayerUI_ -> LookAt(Vector3(emptyNode->GetPosition()));
lightNode -> Rotate(Quaternion(.398377,0.854323,0.141073,-0.302532));
}
示例8: CreateScene
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.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));
// 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 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
cameraNode_->SetPosition(Vector3(0.0f, 5.0f, 0.0f));
}
示例9: CreateScene
void HugeObjectCount::CreateScene()
{
ResourceCache* cache = GetSubsystem<ResourceCache>();
if (!scene_)
scene_ = new Scene(context_);
else
{
scene_->Clear();
boxNodes_.Clear();
}
// 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 for ambient light & fog control
Node* zoneNode = scene_->CreateChild("Zone");
Zone* zone = zoneNode->CreateComponent<Zone>();
zone->SetBoundingBox(BoundingBox(-1000.0f, 1000.0f));
zone->SetFogColor(Color(0.2f, 0.2f, 0.2f));
zone->SetFogStart(200.0f);
zone->SetFogEnd(300.0f);
// Create a directional light
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);
if (!useGroups_)
{
light->SetColor(Color(0.7f, 0.35f, 0.0f));
// Create individual box StaticModels in the scene
for (int y = -125; y < 125; ++y)
{
for (int x = -125; x < 125; ++x)
{
Node* boxNode = scene_->CreateChild("Box");
boxNode->SetPosition(Vector3(x * 0.3f, 0.0f, y * 0.3f));
boxNode->SetScale(0.25f);
StaticModel* boxObject = boxNode->CreateComponent<StaticModel>();
boxObject->SetModel(cache->GetResource<Model>("Models/Box.mdl"));
boxNodes_.Push(SharedPtr<Node>(boxNode));
}
}
}
else
{
light->SetColor(Color(0.6f, 0.6f, 0.6f));
light->SetSpecularIntensity(1.5f);
// Create StaticModelGroups in the scene
StaticModelGroup* lastGroup = 0;
for (int y = -125; y < 125; ++y)
{
for (int x = -125; x < 125; ++x)
{
// Create new group if no group yet, or the group has already "enough" objects. The tradeoff is between culling
// accuracy and the amount of CPU processing needed for all the objects. Note that the group's own transform
// does not matter, and it does not render anything if instance nodes are not added to it
if (!lastGroup || lastGroup->GetNumInstanceNodes() >= 25 * 25)
{
Node* boxGroupNode = scene_->CreateChild("BoxGroup");
lastGroup = boxGroupNode->CreateComponent<StaticModelGroup>();
lastGroup->SetModel(cache->GetResource<Model>("Models/Box.mdl"));
}
Node* boxNode = scene_->CreateChild("Box");
boxNode->SetPosition(Vector3(x * 0.3f, 0.0f, y * 0.3f));
boxNode->SetScale(0.25f);
boxNodes_.Push(SharedPtr<Node>(boxNode));
lastGroup->AddInstanceNode(boxNode);
}
}
}
// Create the camera. Create it outside the scene so that we can clear the whole scene without affecting it
if (!cameraNode_)
{
cameraNode_ = new Node(context_);
cameraNode_->SetPosition(Vector3(0.0f, 10.0f, -100.0f));
Camera* camera = cameraNode_->CreateComponent<Camera>();
camera->SetFarClip(300.0f);
}
}
示例10: Scene
void Urho2DConstraints::CreateScene()
{
scene_ = new Scene(context_);
scene_->CreateComponent<Octree>();
scene_->CreateComponent<DebugRenderer>();
auto* physicsWorld = scene_->CreateComponent<PhysicsWorld2D>(); // Create 2D physics world component
physicsWorld->SetDrawJoint(true); // Display the joints (Note that DrawDebugGeometry() must be set to true to acually draw the joints)
drawDebug_ = true; // Set DrawDebugGeometry() to true
// Create camera
cameraNode_ = scene_->CreateChild("Camera");
// Set camera's position
cameraNode_->SetPosition(Vector3(0.0f, 0.0f, 0.0f)); // Note that Z setting is discarded; use camera.zoom instead (see MoveCamera() below for example)
camera_ = cameraNode_->CreateComponent<Camera>();
camera_->SetOrthographic(true);
auto* graphics = GetSubsystem<Graphics>();
camera_->SetOrthoSize((float)graphics->GetHeight() * PIXEL_SIZE);
camera_->SetZoom(1.2f * Min((float)graphics->GetWidth() / 1280.0f, (float)graphics->GetHeight() / 800.0f)); // Set zoom according to user's resolution to ensure full visibility (initial zoom (1.2) is set for full visibility at 1280x800 resolution)
// Set up a viewport to the Renderer subsystem so that the 3D scene can be seen
ea::shared_ptr<Viewport> viewport(new Viewport(context_, scene_, camera_));
auto* renderer = GetSubsystem<Renderer>();
renderer->SetViewport(0, viewport);
Zone* zone = renderer->GetDefaultZone();
zone->SetFogColor(Color(0.1f, 0.1f, 0.1f)); // Set background color for the scene
// Create 4x3 grid
for (unsigned i = 0; i<5; ++i)
{
Node* edgeNode = scene_->CreateChild("VerticalEdge");
auto* edgeBody = edgeNode->CreateComponent<RigidBody2D>();
if (!dummyBody)
dummyBody = edgeBody; // Mark first edge as dummy body (used by mouse pick)
auto* edgeShape = edgeNode->CreateComponent<CollisionEdge2D>();
edgeShape->SetVertices(Vector2(i*2.5f -5.0f, -3.0f), Vector2(i*2.5f -5.0f, 3.0f));
edgeShape->SetFriction(0.5f); // Set friction
}
for (unsigned j = 0; j<4; ++j)
{
Node* edgeNode = scene_->CreateChild("HorizontalEdge");
/*RigidBody2D* edgeBody = */edgeNode->CreateComponent<RigidBody2D>();
auto* edgeShape = edgeNode->CreateComponent<CollisionEdge2D>();
edgeShape->SetVertices(Vector2(-5.0f, j*2.0f -3.0f), Vector2(5.0f, j*2.0f -3.0f));
edgeShape->SetFriction(0.5f); // Set friction
}
auto* cache = GetSubsystem<ResourceCache>();
// Create a box (will be cloned later)
Node* box = scene_->CreateChild("Box");
box->SetPosition(Vector3(0.8f, -2.0f, 0.0f));
auto* boxSprite = box->CreateComponent<StaticSprite2D>();
boxSprite->SetSprite(cache->GetResource<Sprite2D>("Urho2D/Box.png"));
auto* boxBody = box->CreateComponent<RigidBody2D>();
boxBody->SetBodyType(BT_DYNAMIC);
boxBody->SetLinearDamping(0.0f);
boxBody->SetAngularDamping(0.0f);
auto* shape = box->CreateComponent<CollisionBox2D>(); // Create box shape
shape->SetSize(Vector2(0.32f, 0.32f)); // Set size
shape->SetDensity(1.0f); // Set shape density (kilograms per meter squared)
shape->SetFriction(0.5f); // Set friction
shape->SetRestitution(0.1f); // Set restitution (slight bounce)
// Create a ball (will be cloned later)
Node* ball = scene_->CreateChild("Ball");
ball->SetPosition(Vector3(1.8f, -2.0f, 0.0f));
auto* ballSprite = ball->CreateComponent<StaticSprite2D>();
ballSprite->SetSprite(cache->GetResource<Sprite2D>("Urho2D/Ball.png"));
auto* ballBody = ball->CreateComponent<RigidBody2D>();
ballBody->SetBodyType(BT_DYNAMIC);
ballBody->SetLinearDamping(0.0f);
ballBody->SetAngularDamping(0.0f);
auto* ballShape = ball->CreateComponent<CollisionCircle2D>(); // Create circle shape
ballShape->SetRadius(0.16f); // Set radius
ballShape->SetDensity(1.0f); // Set shape density (kilograms per meter squared)
ballShape->SetFriction(0.5f); // Set friction
ballShape->SetRestitution(0.6f); // Set restitution: make it bounce
// Create a polygon
Node* polygon = scene_->CreateChild("Polygon");
polygon->SetPosition(Vector3(1.6f, -2.0f, 0.0f));
polygon->SetScale(0.7f);
auto* polygonSprite = polygon->CreateComponent<StaticSprite2D>();
polygonSprite->SetSprite(cache->GetResource<Sprite2D>("Urho2D/Aster.png"));
auto* polygonBody = polygon->CreateComponent<RigidBody2D>();
polygonBody->SetBodyType(BT_DYNAMIC);
auto* polygonShape = polygon->CreateComponent<CollisionPolygon2D>();
// TODO: create from ea::vector<Vector2> using SetVertices()
polygonShape->SetVertexCount(6); // Set number of vertices (mandatory when using SetVertex())
polygonShape->SetVertex(0, Vector2(-0.8f, -0.3f));
polygonShape->SetVertex(1, Vector2(0.5f, -0.8f));
polygonShape->SetVertex(2, Vector2(0.8f, -0.3f));
polygonShape->SetVertex(3, Vector2(0.8f, 0.5f));
polygonShape->SetVertex(4, Vector2(0.5f, 0.9f));
polygonShape->SetVertex(5, Vector2(-0.5f, 0.7f));
polygonShape->SetDensity(1.0f); // Set shape density (kilograms per meter squared)
//.........这里部分代码省略.........
示例11: CreateScene
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);
}
}
示例12: Start
void Sample::Start()
{
cache_ = GetSubsystem<ResourceCache>();
ui_ = GetSubsystem<UI>();
graphics_ = GetSubsystem<Graphics>();
//////////////////////////////////////////////////////////////////////////
// Get default styles
XMLFile* styleFile = cache_->GetResource<XMLFile>("UI/DefaultStyle.xml");
ui_->GetRoot()->SetDefaultStyle(styleFile);
// create main ui
rootUI_ = ui_->GetRoot()->CreateChild<UIElement>("IDERoot");
rootUI_->SetSize(ui_->GetRoot()->GetSize());
rootUI_->SetTraversalMode(TM_DEPTH_FIRST); // This is needed for root-like element to prevent artifacts
rootUI_->SetDefaultStyle(styleFile);
//////////////////////////////////////////////////////////////////////////
/// Create console
console_ = engine_->CreateConsole();
console_->SetDefaultStyle(styleFile);
//////////////////////////////////////////////////////////////////////////
/// Create debug HUD.
debugHud_ = engine_->CreateDebugHud();
debugHud_->SetDefaultStyle(styleFile);
//////////////////////////////////////////////////////////////////////////
/// Subscribe key down event
SubscribeToEvent(E_KEYDOWN, HANDLER(Sample, HandleKeyDown));
// edit clear color, set background color
Renderer* renderer = GetSubsystem<Renderer>();
Zone* zone = renderer->GetDefaultZone();
zone->SetFogColor(Color(0.3f, 0.3f, 0.4f)); // Set background color for the scene
//////////////////////////////////////////////////////////////////////////
/// Create Cursor
// Cursor* cursor_ = new Cursor(context_);
// cursor_->SetStyleAuto(styleFile);
// ui_->SetCursor(cursor_);
// if (GetPlatform() == "Android" || GetPlatform() == "iOS")
// ui_->GetCursor()->SetVisible(false);
/// Show Platform Cursor
Input* input = GetSubsystem<Input>();
input->SetMouseVisible(true);
//////////////////////////////////////////////////////////////////////////
/// create an svg image
rootUI_->AddChild(CreateSVGSprite("GameData/svg/23.svg"));
Sprite* drawing = CreateSVGSprite("GameData/svg/drawing.svg");
if (drawing)
{
// Set logo sprite hot spot
drawing->SetHotSpot(0, drawing->GetHeight());
drawing->SetAlignment(HA_LEFT, VA_BOTTOM);
rootUI_->AddChild(drawing);
}
Sprite* nano = CreateSVGSprite("GameData/svg/nano.svg");
if (nano)
{
// Set logo sprite hot spot
nano->SetHotSpot(0, -nano->GetHeight());
nano->SetAlignment(HA_LEFT, VA_TOP);
rootUI_->AddChild(nano);
}
}
示例13: CreateScene
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));
}
示例14: Scene
void Urho2DPlatformer::CreateScene()
{
scene_ = new Scene(context_);
sample2D_->scene_ = scene_;
// Create the Octree, DebugRenderer and PhysicsWorld2D components to the scene
scene_->CreateComponent<Octree>();
scene_->CreateComponent<DebugRenderer>();
/*PhysicsWorld2D* physicsWorld =*/ scene_->CreateComponent<PhysicsWorld2D>();
// Create camera
cameraNode_ = scene_->CreateChild("Camera");
auto* camera = cameraNode_->CreateComponent<Camera>();
camera->setProjectionType(PT_ORTHOGRAPHIC);
auto* graphics = GetContext()->m_Graphics.get();
camera->SetOrthoSize((float)graphics->GetHeight() * PIXEL_SIZE);
camera->SetZoom(2.0f * Min((float)graphics->GetWidth() / 1280.0f, (float)graphics->GetHeight() / 800.0f)); // Set zoom according to user's resolution to ensure full visibility (initial zoom (2.0) is set for full visibility at 1280x800 resolution)
// Setup the viewport for displaying the scene
SharedPtr<Viewport> viewport(new Viewport(context_, scene_, camera));
auto* renderer = GetContext()->m_Renderer.get();
renderer->SetViewport(0, viewport);
// Set background color for the scene
Zone* zone = renderer->GetDefaultZone();
zone->SetFogColor(Color(0.2f, 0.2f, 0.2f));
// Create tile map from tmx file
auto* cache = GetContext()->m_ResourceCache.get();
SharedPtr<Node> tileMapNode(scene_->CreateChild("TileMap"));
auto* tileMap = tileMapNode->CreateComponent<TileMap2D>();
tileMap->SetTmxFile(cache->GetResource<TmxFile2D>("Urho2D/Tilesets/Ortho.tmx"));
const TileMapInfo2D& info = tileMap->GetInfo();
// Create Spriter Imp character (from sample 33_SpriterAnimation)
Node* spriteNode = sample2D_->CreateCharacter(info, 0.8f, Vector3(1.0f, 8.0f, 0.0f), 0.2f);
character2D_ = spriteNode->CreateComponent<Character2D>(); // Create a logic component to handle character behavior
// Generate physics collision shapes from the tmx file's objects located in "Physics" (top) layer
TileMapLayer2D* tileMapLayer = tileMap->GetLayer(tileMap->GetNumLayers() - 1);
sample2D_->CreateCollisionShapesFromTMXObjects(tileMapNode, tileMapLayer, info);
// Instantiate enemies and moving platforms at each placeholder of "MovingEntities" layer (placeholders are Poly Line objects defining a path from points)
sample2D_->PopulateMovingEntities(tileMap->GetLayer(tileMap->GetNumLayers() - 2));
// Instantiate coins to pick at each placeholder of "Coins" layer (placeholders for coins are Rectangle objects)
TileMapLayer2D* coinsLayer = tileMap->GetLayer(tileMap->GetNumLayers() - 3);
sample2D_->PopulateCoins(coinsLayer);
// Init coins counters
character2D_->remainingCoins_ = coinsLayer->GetNumObjects();
character2D_->maxCoins_ = coinsLayer->GetNumObjects();
//Instantiate triggers (for ropes, ladders, lava, slopes...) at each placeholder of "Triggers" layer (placeholders for triggers are Rectangle objects)
sample2D_->PopulateTriggers(tileMap->GetLayer(tileMap->GetNumLayers() - 4));
// Create background
sample2D_->CreateBackgroundSprite(info, 3.5, "Textures/HeightMap.png", true);
// Check when scene is rendered
g_graphicsSignals.endRendering.Connect(this,&Urho2DPlatformer::HandleSceneRendered);
}
示例15: CreateScene
void DynamicGeometry::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 for ambient light & fog control
Node* zoneNode = scene_->CreateChild("Zone");
Zone* zone = zoneNode->CreateComponent<Zone>();
zone->SetBoundingBox(BoundingBox(-1000.0f, 1000.0f));
zone->SetFogColor(Color(0.2f, 0.2f, 0.2f));
zone->SetFogStart(200.0f);
zone->SetFogEnd(300.0f);
// Create a directional light
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);
light->SetColor(Color(0.4f, 1.0f, 0.4f));
light->SetSpecularIntensity(1.5f);
// Get the original model and its unmodified vertices, which are used as source data for the animation
Model* originalModel = cache->GetResource<Model>("Models/Box.mdl");
if (!originalModel)
{
ATOMIC_LOGERROR("Model not found, cannot initialize example scene");
return;
}
// Get the vertex buffer from the first geometry's first LOD level
VertexBuffer* buffer = originalModel->GetGeometry(0, 0)->GetVertexBuffer(0);
const unsigned char* vertexData = (const unsigned char*)buffer->Lock(0, buffer->GetVertexCount());
if (vertexData)
{
unsigned numVertices = buffer->GetVertexCount();
unsigned vertexSize = buffer->GetVertexSize();
// Copy the original vertex positions
for (unsigned i = 0; i < numVertices; ++i)
{
const Vector3& src = *reinterpret_cast<const Vector3*>(vertexData + i * vertexSize);
originalVertices_.Push(src);
}
buffer->Unlock();
// Detect duplicate vertices to allow seamless animation
vertexDuplicates_.Resize(originalVertices_.Size());
for (unsigned i = 0; i < originalVertices_.Size(); ++i)
{
vertexDuplicates_[i] = i; // Assume not a duplicate
for (unsigned j = 0; j < i; ++j)
{
if (originalVertices_[i].Equals(originalVertices_[j]))
{
vertexDuplicates_[i] = j;
break;
}
}
}
}
else
{
ATOMIC_LOGERROR("Failed to lock the model vertex buffer to get original vertices");
return;
}
// Create StaticModels in the scene. Clone the model for each so that we can modify the vertex data individually
for (int y = -1; y <= 1; ++y)
{
for (int x = -1; x <= 1; ++x)
{
Node* node = scene_->CreateChild("Object");
node->SetPosition(Vector3(x * 2.0f, 0.0f, y * 2.0f));
StaticModel* object = node->CreateComponent<StaticModel>();
SharedPtr<Model> cloneModel = originalModel->Clone();
object->SetModel(cloneModel);
// Store the cloned vertex buffer that we will modify when animating
animatingBuffers_.Push(SharedPtr<VertexBuffer>(cloneModel->GetGeometry(0, 0)->GetVertexBuffer(0)));
}
}
// Finally create one model (pyramid shape) and a StaticModel to display it from scratch
// Note: there are duplicated vertices to enable face normals. We will calculate normals programmatically
{
const unsigned numVertices = 18;
float vertexData[] = {
// Position Normal
0.0f, 0.5f, 0.0f, 0.0f, 0.0f, 0.0f,
0.5f, -0.5f, 0.5f, 0.0f, 0.0f, 0.0f,
0.5f, -0.5f, -0.5f, 0.0f, 0.0f, 0.0f,
0.0f, 0.5f, 0.0f, 0.0f, 0.0f, 0.0f,
-0.5f, -0.5f, 0.5f, 0.0f, 0.0f, 0.0f,
0.5f, -0.5f, 0.5f, 0.0f, 0.0f, 0.0f,
0.0f, 0.5f, 0.0f, 0.0f, 0.0f, 0.0f,
//.........这里部分代码省略.........