Start Page » DragonScript Scripting Language » Behavior Elements: Quick and Easy Development » ECBehaviorControlDesktop
Behavior element behavior adding support to control desktop by player.
The behavior allows player (or other actors) to move the mouse pointer on a ECBehaviorRenderableDesktop by looking or pointing at the desired position. Also the player can simulate a left or right mouse click by using an input binding defined by the actor himself. This kind of input is typically used for VR games but can be also used for non VR games like first person shooters.
The behavior defines three corner points of a virtual rectangular plane. The player looking or pointing direction is intersected with this virtual plane. The relative position of this hit point is mapped to the Desktop widget. The three corners of the virtual plane are the lower left, lower right and upper left corner.
Optionally a bone name can be specified. If the bone name is not empty the virtual plane corners are relative to the bone. This allows to create desktop input zones which can be displaced.
The behavior can be optionally disabled to allow the input to be available to the player only if certain conditions are fulfilled.
The actor is responsible to move the mouse pointer. This behavior provides convenience methods to do the calculation and updating of the mouse pointer.
This behavior can be used multiple times for example to control different renderable desktops.
Element class properties have the prefix controlDesktop. or controlDesktop(id). if id is not empty.
Virtual plane lower left position in component space.
<vector name='controlDesktop.lowerLeft' x='-0.2' y='-0.3' z='0'/>
Virtual plane lower right position.
<vector name='controlDesktop.lowerRight' x='0.2' y='-0.3' z='0'/>
Virtual plane upper left position.
<vector name='controlDesktop.upperLeft' x='-0.2' y='0.3' z='0'/>
Name of bone to use as coordinate system for the virtual plane or empty string to use the component coordinate system.
<string name='controlDesktop(right).bone'>display</string>
This behavior does not support optional behaviors.
This behavior does not use persistency.
Since DragonScript Module Version 1.7
Example of an example class using a component with a dynamic skin where the screen texture is a renderable desktop the player can control:
class MyElement extends BehaviorElementClass public var ECBehaviorComponent component public var ECBehaviorDynamicSkin dynamicSkin public var ECBehaviorRenderableDesktop renderableDesktop public var ECBehaviorControlDesktop controlDesktop public func new() // Create component component = ECBehaviorComponent.new(this, null) // Create dynamic skin. This allows individual component textures // to be dynamically defined at runtime. dynamicSkin = ECBehaviorDynamicSkin.new(this, component) // Create renderable desktop. This creates a Desktop widget which // is used as content for the component texture named "screen". // The desktop widget has a size of 1024x868 pixels. // // By default the desktop is empty. You have to add windows to // the desktop after the element has been created. A typical // solution is to create individual behaviors for all windows // added to the desktop. renderableDesktop = ECBehaviorRenderableDesktop.new(this, dynamicSkin) renderableDesktop.getRenderable().setValue("screen") renderableDesktop.getSize().setPoint(Point.new(1024, 768)) // Add support to control the desktop. Multiple desktops can be // controlled individually by adding multiple behaviors with // unique identifiers each controlling one single renderable desktop. controlDesktop = ECBehaviorControlDesktop.new(this, renderableDesktop) end end
A typical usage of this behavior looks like this:
class MyPlayerAction extends BAAFirstPersonVR public func new() end public func void playerThink(float elapsed) super.think(elapsed) // Check if right hand controller is pointing at an element if vrRightHandPointAt.hasVRHandPointAtElement() // Store the hit element and hit point in world space. Typically you want // to test them against mulitple supported interactions. var BehaviorElement element = vrRightHandPointAt.getPointAtBehaviorElement() var DVector hitPoint = vrRightHandPointAt.getPointAtHitPoint() // Move mouse on the desktop controller if present in the pointed at element var ECBehaviorControlDesktop.Instance controlDesktop = ECBehaviorControlDesktop.getInstanceIn(element) if controlDesktop != null // The call moveMouse() converts the hit point in world space to desktop // coordinates. If the world position is outside the desktop area nothing // is done and false is returned. Otherwise the mouse position is updated // and true is returned. In this example we stop here if we updated the // desktop mouse position in case more interactions are check below if controlDesktop.moveMouse(hitPoint) return end end // Here you could check for other supported interactions end // The same could be done for vrLeftHandPointAt too end end
The same example can be done using ECBehaviorLookAt instead of ECBehaviorVRHandPointAt.