User Tools

Site Tools


dragengine:modules:dragonscript:behavior_controldesktop

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.

Instance Counts

This behavior can be used multiple times for example to control different renderable desktops.

Element Class Properties

Element class properties have the prefix controlDesktop. or controlDesktop(id). if id is not empty.

lowerLeft

Virtual plane lower left position in component space.

  • Full name: “controlDesktop.lowerLeft” or “controlDesktop(id).lowerLeft”
  • Type: vector
  • Default value: (-0.5, -0.5, 0)
  • Example (*.deeclass):
    <vector name='controlDesktop.lowerLeft' x='-0.2' y='-0.3' z='0'/>

lowerRight

Virtual plane lower right position.

  • Full name: “controlDesktop.lowerRight” or “controlDesktop(id).lowerRight”
  • Type: vector
  • Default value: (0.5, -0.5, 0)
  • Example (*.deeclass):
    <vector name='controlDesktop.lowerRight' x='0.2' y='-0.3' z='0'/>

upperLeft

Virtual plane upper left position.

  • Full name: “controlDesktop.upperLeft” or “controlDesktop(id).upperLeft”
  • Type: vector
  • Default value: (-0.5, 0.5, 0)
  • Example (*.deeclass):
    <vector name='controlDesktop.upperLeft' x='-0.2' y='0.3' z='0'/>

bone

Name of bone to use as coordinate system for the virtual plane or empty string to use the component coordinate system.

  • Full name: “controlDesktop.bone” or “controlDesktop(id).bone”
  • Type: string
  • Default Value: “”
  • Example (*.deeclass):
    <string name='controlDesktop(right).bone'>display</string>

Required Behaviors

Optional Behaviors

This behavior does not support optional behaviors.

Persistency

This behavior does not use persistency.

API Documentation

ECBehaviorControlDesktop.

Since DragonScript Module Version 1.7

Use Cases

  • In-Game computers monitors the player can control like a real computer
  • VR screens the player can control by pointing his controller at a screen

Element Class Example

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.

Live Examples

You could leave a comment if you were logged in.
dragengine/modules/dragonscript/behavior_controldesktop.txt · Last modified: 2024/03/14 16:50 by dragonlord