{ if (args.Key == Key.Esc) Engine.Exit(); });
}
}]]>
(nameof(MyRotation));
MyName = des.Deserialize(nameof(MyName));
}
// called when the component is attached to some node
public override void OnAttachedToNode()
{
var node = this.Node;
}
}]]>
On Direct3D9 and Android OpenGL ES 2.0 it is possible to lose the rendering context (and therefore GPU resources) due to the application window being minimized or sent to the background.
Additionally, to work around possible GPU driver bugs the desktop OpenGL context will be voluntarily destroyed and recreated when changing screen mode or toggling between fullscreen and windowed. Therefore, on all graphics APIs one must be prepared for losing GPU resources.
Textures that have been loaded from a file, as well as vertex & index buffers that have shadowing enabled will restore their contents automatically, the rest have to be restored manually. On Direct3D9 non-dynamic (managed) textures and buffers will never be lost, as the runtime automatically backs them up to system memory.
();
Renderer.SetViewport(0, Viewport = new Viewport(Context, scene, cameraNode.GetComponent(), null));
// Lights
var lightNode1 = scene.CreateChild();
lightNode1.Position = new Vector3(0, -5, -40);
lightNode1.AddComponent(new Light(Context) { LightType = LightType.Point, Range = 120, Brightness = 1.5f });
// Models
var cache = Application.ResourceCache;
var model = Node.CreateComponent();
model.Model = cache.GetModel ("player.mdl");
var material = cache.GetMaterial("player.xml").Clone("");
model.SetMaterial(material);]]>
();
planeObject.Model = cache.GetModel ("Models/Plane.mdl");
planeObject.SetMaterial(cache.GetMaterial("Materials/StoneTiled.xml"));
]]>
(StaticModel.TypeStatic);
planeObject.Model = cache.GetModel ("Models/Plane.mdl");
planeObject.SetMaterial(cache.GetMaterial("Materials/StoneTiled.xml"));
]]>
();
// 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)
var planeNode = scene.CreateChild("Plane");
planeNode.Scale = new Vector3 (100, 1, 100);
var planeObject = planeNode.CreateComponent ();
planeObject.Model = cache.GetModel ("Models/Plane.mdl");
planeObject.SetMaterial(cache.GetMaterial("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)
var lightNode = scene.CreateChild("DirectionalLight");
lightNode.SetDirection (new Vector3(0.6f, -1.0f, 0.8f));
]]>
();
body.Mass = 1;
body.SetKinematic (true);
var shape = node.CreateComponent ();
shape.SetBox (new Vector3(1,1,1), Vector.Zero, Quaternion.Identity);
node.NodeCollisionStart += (args) => {
Console.WriteLine (“Collision with {0}”, args.OtherNode);
};
}]]>
();
box.Color = Color.Blue;
}]]>
();
cone.Color = Color.Blue;
}]]>
();
cylinder.Color = Color.Blue;
}]]>
();
plane.Color = Color.Blue;
}]]>
();
pyramid.Color = Color.Blue;
}]]>
();
sphere.Color = Color.Blue;
}]]>
();
torus.Color = Color.Blue;
}]]>
A collision shape can be set to trigger mode to only report collisions without actually applying collision forces. This can be used to implement trigger areas. Note that:
A sensor can be triggered only by dynamic bodies T:Urho.Urho2D.BodyType2D’s Dynamic.
Physics queries don't report triggers. To get notified when a sensor is triggered or cease to be triggered, subscribe to E:Urho.Urho2D.PhysicsWorld2D.PhysicsBeginContact2D and E:Urho.Urho2D.PhysicsWorld2D.PhysicsEndContact2D physics events.