aboutsummaryrefslogtreecommitdiffstats
path: root/Samples/OculusWorldDemo/Player.h
blob: 7b45d7d4e97522d2da62116600fb14eff656da89 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/************************************************************************************

Filename    :   Player.h
Content     :   Avatar movement and collision detection
Created     :   October 4, 2012

Copyright   :   Copyright 2012 Oculus, Inc. All Rights reserved.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.


*************************************************************************************/

#ifndef OVR_WorldDemo_Player_h
#define OVR_WorldDemo_Player_h

#include "OVR.h"
#include "Kernel/OVR_KeyCodes.h"
#include "../CommonSrc/Render/Render_Device.h"

using namespace OVR;
using namespace OVR::Render;

//-------------------------------------------------------------------------------------
// The RHS coordinate system is assumed.  
const Vector3f	RightVector(1.0f, 0.0f, 0.0f);
const Vector3f	UpVector(0.0f, 1.0f, 0.0f);
const Vector3f	ForwardVector(0.0f, 0.0f, -1.0f); // -1 because HMD looks along -Z at identity orientation

const float		YawInitial	= 0.0f;
const float		Sensitivity	= 0.3f; // low sensitivity to ease people into it gently.
const float		MoveSpeed	= 3.0f; // m/s

// These are used for collision detection
const float		RailHeight	= 0.8f;


//-------------------------------------------------------------------------------------
// ***** Player

// Player class describes position and movement state of the player in the 3D world.
class Player
{
public:

	float				UserEyeHeight;

	// Where the avatar coordinate system (and body) is positioned and oriented in the virtual world
    // Modified by gamepad/mouse input
	Vector3f			BodyPos;
	Anglef				BodyYaw;

    // Where the player head is positioned and oriented in the real world
    Transformf          HeadPose;

    // Where the avatar head is positioned and oriented in the virtual world
    Vector3f            GetPosition();
    Quatf               GetOrientation(bool baseOnly = false);

    // Returns virtual world position based on a real world head pose.
    // Allows predicting eyes separately based on scanout time.
    Transformf          VirtualWorldTransformfromRealPose(const Transformf &sensorHeadPose);

    // Handle directional movement. Returns 'true' if movement was processed.
    bool                HandleMoveKey(OVR::KeyCode key, bool down);

    // Movement state; different bits may be set based on the state of keys.
    UByte               MoveForward;
    UByte               MoveBack;
    UByte               MoveLeft;
    UByte               MoveRight;
    Vector3f            GamepadMove, GamepadRotate;
    bool                bMotionRelativeToBody;

	Player();
	~Player();
	void HandleMovement(double dt, Array<Ptr<CollisionModel> >* collisionModels,
		                Array<Ptr<CollisionModel> >* groundCollisionModels, bool shiftDown);
};

#endif