Urho3D Wiki
Tags: Visual edit apiedit
Tags: Visual edit apiedit
Line 7: Line 7:
   
 
== Explanation of Basic Functionality ==
 
== Explanation of Basic Functionality ==
[These explanations should explain basic stuff by using on of the simpler examples.]
+
[These explanations should explain basic stuff by using one of the simpler examples.]
   
 
=== The Node Model ===
 
=== The Node Model ===

Revision as of 05:00, 14 February 2015

Creating a new Project with Codeblocks using [one of the samples]

[TODO]

[This example should have a simple scene, like a ground plane with two character on it, a moving light (circle?) and a movable camera.]

[There should be a copyable piece of code here that already does everything this tutorial explains later. So the user can set up the project, copy the code and sees something nice. And then gets to know what the pieces of the code do. Also: images how the sample should look like. And how to set it up.]

Explanation of Basic Functionality

[These explanations should explain basic stuff by using one of the simpler examples.]

The Node Model

Urho3D organizes all objects (like 3D-models, lights and cameras) in nodes. These nodes are in a hierarchical system. Nodes can have children nodes and by that become a parent node. A node is always moved, rotated and scaled relative to its parent. By modifying the parent, you are also modifying all its children.

Example: You could make a car model attached to a node and parent wheels and passengers (with nodes) to this car node. So by moving or rotating the car node, all child nodes are moved the same way and you don't need to move every node by itself.

When you move a node along its X-Axis, this movement may be completely different from moving along the global X-Axis, depending on the rotation of all parent nodes.

Nodes can have names and can be found by searching for these names.

Creating a Node and adding a model

Node* objectNode=scene_->CreateChild("Examplenode");     // create a node with the name Examplenode
objectNode->SetPosition(Vector3(10,5,2));                // move the node to the XYZ-position 5 2 1. 3D Positions are stored as the Vector3 type.
objectNode->Yaw(42);                                     // rotate node 42 degrees to its right
objectNode->SetScale(5);                                 // scale the node to 5 times its size
StaticModel* object=objectNode->CreateComponent<StaticModel>();                     // create a new model and append it directly to the node.
object->SetModel(cache->GetResource<Model>("Models/examplemesh.mdl"));              // loads the "examplemesh.mdl" from the "Models" folder
object->SetMaterial(cache->GetResource<Material>("Materials/examplematerial.xml")); // loads the "examplematerial.xml"
object->SetCastShadows(true);                                                       // enables shadow casting

Creating the Camera

[TODO]

Moving the Camera

[TODO]

Adding a moving light

Inside the class definition:

Node* lightNode;

Inside the CreateScene() function:

lightNode=scene_->CreateChild("PointLight");       // create the node for our light
Light* light=lightNode->CreateComponent<Light>();  // create a light and directly add it to the node
light->SetLightType(LIGHT_POINT);                  // The light should be a point light,
light->SetCastShadows(true);                       // cast shadows
light->SetRange(100);                              // and have a range of 100 units.

[TODO: Some nice movement in an easy manor.]