Class TCastleMouseLookNavigation

Unit

Declaration

type TCastleMouseLookNavigation = class(TCastleNavigation)

Description

Abstract navigation class that can utilize mouse look, during which mouse cursor is hidden and we look at MouseLookDelta every frame.

Hierarchy

Overview

Fields

Public nested const DefaultMouseLookHorizontalSensitivity = Pi * 0.1 / 180;
Public nested const DefaultMouseLookVerticalSensitivity = Pi * 0.1 / 180;

Methods

Protected procedure ProcessMouseLookDelta(const Delta: TVector2); virtual;
Public constructor Create(AOwner: TComponent); override;
Public procedure Update(const SecondsPassed: Single; var HandleInput: boolean); override;
Public function Motion(const Event: TInputMotion): boolean; override;
Public function InternalUsingMouseLook: Boolean;

Properties

Public property MouseLook: boolean read FMouseLook write SetMouseLook default false;
Public property MouseLookHorizontalSensitivity: Single read FMouseLookHorizontalSensitivity write FMouseLookHorizontalSensitivity default DefaultMouseLookHorizontalSensitivity;
Public property MouseLookVerticalSensitivity: Single read FMouseLookVerticalSensitivity write FMouseLookVerticalSensitivity default DefaultMouseLookVerticalSensitivity;
Public property InvertVerticalMouseLook: boolean read FInvertVerticalMouseLook write FInvertVerticalMouseLook default false;

Description

Fields

Public nested const DefaultMouseLookHorizontalSensitivity = Pi * 0.1 / 180;

This item has no description.

Public nested const DefaultMouseLookVerticalSensitivity = Pi * 0.1 / 180;

This item has no description.

Methods

Protected procedure ProcessMouseLookDelta(const Delta: TVector2); virtual;

This item has no description.

Public constructor Create(AOwner: TComponent); override;

This item has no description.

Public procedure Update(const SecondsPassed: Single; var HandleInput: boolean); override;

This item has no description. Showing description inherited from TCastleUserInterface.Update.

Control may do here anything that must be continuously repeated. E.g. camera handles here falling down due to gravity, rotating model in Examine mode, and many more.

This method may be used, among many other things, to continuously react to the fact that user pressed some key (or mouse button). For example, if holding some key should move some 3D object, you should do something like:

if HandleInput then
begin
  if Container.Pressed[keyArrowRight] then
    Transform.Position := Transform.Position + Vector3(SecondsPassed * 10, 0, 0);
  HandleInput := not ExclusiveEvents;
end;

Instead of directly using a key code, consider also using TInputShortcut that makes the input key nicely configurable. See engine tutorial about handling inputs.

Multiplying movement by SecondsPassed makes your operation frame-rate independent. Object will move by 10 units in a second, regardless of how many FPS your game has.

The code related to HandleInput is important if you write a generally-useful control that should nicely cooperate with all other controls, even when placed on top of them or under them. The correct approach is to only look at pressed keys/mouse buttons if HandleInput is True. Moreover, if you did check that HandleInput is True, and you did actually handle some keys, then you have to set HandleInput := not ExclusiveEvents. As ExclusiveEvents is True in normal circumstances, this will prevent the other controls (behind the current control) from handling the keys (they will get HandleInput = False). And this is important to avoid doubly-processing the same key press, e.g. if two controls react to the same key, only the one on top should process it.

Note that to handle a single press / release (like "switch light on when pressing a key") you should rather use Press and Release methods. Use this method only for continuous handling (like "holding this key makes the light brighter and brighter").

To understand why such HandleInput approach is needed, realize that the "Update" events are called differently than simple mouse and key events like "Press" and "Release". "Press" and "Release" events return whether the event was somehow "handled", and the container passes them only to the controls under the mouse (decided by TCastleUserInterface.CapturesEventsAtPosition). And as soon as some control says it "handled" the event, other controls (even if under the mouse) will not receive the event.

This approach is not suitable for Update events. Some controls need to do the Update job all the time, regardless of whether the control is under the mouse and regardless of what other controls already did. So all controls (well, all controls that exist, in case of TCastleUserInterface, see TCastleUserInterface.Exists) receive Update calls.

So the "handled" status is passed through HandleInput. If a control is not under the mouse, it will receive HandleInput = False. If a control is under the mouse, it will receive HandleInput = True as long as no other control on top of it didn't already change it to False.

Public function Motion(const Event: TInputMotion): boolean; override;

This item has no description. Showing description inherited from TCastleUserInterface.Motion.

Motion of mouse or touch.

Public function InternalUsingMouseLook: Boolean;

This item has no description.

Properties

Public property MouseLook: boolean read FMouseLook write SetMouseLook default false;

Use mouse look to navigate (rotate the camera).

This also makes mouse cursor of Container hidden, and forces mouse position to the middle of the window (to avoid the situation when mouse movement is blocked by screen borders).

Setting this property at design-time (in CGE editor) does not activate the mouse look in CGE editor. It only controls the mouse look once the application is running.

Public property MouseLookHorizontalSensitivity: Single read FMouseLookHorizontalSensitivity write FMouseLookHorizontalSensitivity default DefaultMouseLookHorizontalSensitivity;

Mouse look sensitivity, if MouseLook is working. These properties specify how much angle change is produced by moving mouse by 1 pixel.

Public property MouseLookVerticalSensitivity: Single read FMouseLookVerticalSensitivity write FMouseLookVerticalSensitivity default DefaultMouseLookVerticalSensitivity;

This item has no description.

Public property InvertVerticalMouseLook: boolean read FInvertVerticalMouseLook write FInvertVerticalMouseLook default false;

If this is True and MouseLook works, then the meaning of vertical mouse movement is inverted: when user moves mouse up, he looks down. Some players are more comfortable with such configuration.


Generated by PasDoc 0.16.0.