-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCamera.cpp
More file actions
666 lines (527 loc) · 19.2 KB
/
Camera.cpp
File metadata and controls
666 lines (527 loc) · 19.2 KB
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
//================================================//
#include "Camera.hpp"
//================================================//
namespace Sparks
{
//================================================//
Camera::Camera(Ogre::SceneManager* mgr)
{
m_pSceneMgr = mgr;
Ogre::ConfigFile file;
file.loadDirect("C:/cam.cfg");
/* Current optimal settings:
moveSpeed=60650.0
maxVelocity=9.0
mass=340.0
grav=89.92
*/
m_mode = MODE_FIRST_PERSON;
m_moveSpeed = Ogre::StringConverter::parseReal(file.getSetting("moveSpeed", "cam"));
m_maxVelocity = Ogre::StringConverter::parseReal(file.getSetting("maxVelocity", "cam"));
m_sprintVelocity = Ogre::StringConverter::parseReal(file.getSetting("sprintVelocity", "cam"));
m_mass = Ogre::StringConverter::parseReal(file.getSetting("mass", "cam"));
m_specMoveSpeed = 70.0;
m_maxSpecVelocity = 10.0;
m_rotateSpeed = 0.06;
m_translateVector = Ogre::Vector3::ZERO;
m_velocityVector = Ogre::Vector3::ZERO;
m_acceleration = 0.3;
m_jumping = false;
m_jmpConstant = 500.0;
m_cameraHeight = 22.0;
m_capsuleRadius = 0.9;
m_maxYOffset = 6.5;
m_defGravity.setValue(0.0, -(Ogre::StringConverter::parseReal(file.getSetting("grav", "cam"))), 0.0);
m_moveForwardsPressed = false;
m_moveBackwardsPressed = false;
m_moveLeftPressed = false;
m_moveRightPressed = false;
m_moveUpPressed = false;
m_moveDownPressed = false;
m_shiftPressed = false;
m_spacePressed = false;
m_farClipDistance = Settings::getSingletonPtr()->graphics.farClip;
m_negativeYRayhit = nullptr;
m_negativeZRayhit = nullptr;
// nodes
m_pCameraNode = m_pSceneMgr->getRootSceneNode()->createChildSceneNode(NODE_CAMERA);
m_pCameraYawNode = m_pCameraNode->createChildSceneNode(NODE_CAMERA_YAW);
m_pCameraPitchNode = m_pCameraYawNode->createChildSceneNode(NODE_CAMERA_PITCH);
m_pCameraRollNode = m_pCameraPitchNode->createChildSceneNode(NODE_CAMERA_ROLL);
}
//================================================//
Camera::~Camera(void)
{
if(m_mode == MODE_FIRST_PERSON)
this->removeRigidBody();
// Remove scene nodes and camera object
m_pSceneMgr->destroySceneNode(m_pCameraNode);
m_pSceneMgr->destroySceneNode(m_pCameraPitchNode);
m_pSceneMgr->destroySceneNode(m_pCameraYawNode);
m_pSceneMgr->destroySceneNode(m_pCameraRollNode);
m_pSceneMgr->destroyCamera(m_pCamera);
delete m_negativeYRayhit;
delete m_negativeZRayhit;
delete m_physicsData;
}
//================================================//
void Camera::init(Physics* physics)
{
m_physics = physics;
// Ogre::Camera object
m_pSceneMgr->destroyCamera("PlayerCam");
m_pCamera = m_pSceneMgr->createCamera("PlayerCam");
m_pCamera->setAutoAspectRatio(true);
m_pCamera->setNearClipDistance(0.1);
m_pCamera->setFarClipDistance(m_farClipDistance);
m_pCameraRollNode->attachObject(m_pCamera);
// Setup data needed for physics callback
m_physicsData = new Physics::CAMERA_DATA();
m_physicsData->heightOffset = &m_capsuleHeightOffset;
m_physicsData->maxVelocity = &m_maxVelocity;
m_physicsData->sprintVelocity = &m_sprintVelocity;
m_physicsData->shift = &m_shiftPressed;
// Create physics body
this->createRigidBody();
// Setup rayhits now to avoid nullptrs
m_negativeYRayhit = new Rayhit();
m_negativeYRayhit->node = m_pCameraNode;
m_negativeYRayhit->distance = 0.0;
m_negativeZRayhit = new Rayhit();
m_negativeZRayhit->node = m_pCameraNode;
m_negativeZRayhit->distance = 0.0;
}
//================================================//
void Camera::createRigidBody(void)
{
// Add the camera to the physics world
Ogre::Vector3 camPos = m_pCameraNode->getPosition();
btScalar mass = m_mass;
btTransform transform;
transform.setIdentity();
transform.setOrigin(btVector3(camPos.x, camPos.y, camPos.z));
// set up rigid body
const Ogre::Real capsuleHeight = 5.0;
m_capsuleHeightOffset = capsuleHeight / 1.7;
btDefaultMotionState* motionState = new btDefaultMotionState(transform);
btCollisionShape* shape = new btCapsuleShape(m_capsuleRadius, capsuleHeight); // need changes
btVector3 localInertia;
shape->calculateLocalInertia(mass, localInertia);
m_btCamera = new btRigidBody(mass, motionState, shape, localInertia);
m_btCamera->setUserPointer((void*)m_pCameraNode);
// optimize the body
m_btCamera->setFriction(1.0);
m_btCamera->setDamping(0.9, 0.9);
m_btCamera->setAngularFactor(btVector3(0, 0, 0));
// this will prevent the camera from falling through elevators when they "take off"
m_btCamera->setActivationState(DISABLE_DEACTIVATION);
m_btCamera->setHitFraction(0.0);
m_btCamera->setContactProcessingThreshold(0.0);
//m_btCamera->setGravity(m_defGravity);
m_physics->getWorld()->setGravity(m_defGravity);
// add the rigid body to the dynamics world
//m_physics->setCameraBody(m_btCamera);
m_physicsData->body = m_btCamera;
m_physics->setCameraData(m_physicsData);
}
//================================================//
void Camera::createAltRigidBody(void)
{
// Add the camera to the physics world
Ogre::Vector3 camPos = m_pCameraNode->getPosition();
btScalar mass = 12.0;
btTransform transform;
transform.setIdentity();
transform.setOrigin(btVector3(camPos.x, camPos.y, camPos.z));
// set up rigid body
btDefaultMotionState* motionState = new btDefaultMotionState(transform);
btCollisionShape* shape = new btBoxShape(btVector3(3.0, 5.0, 3.0)); // need changes
btVector3 localInertia;
shape->calculateLocalInertia(mass, localInertia);
m_btCamera = new btRigidBody(mass, motionState, shape, localInertia);
m_btCamera->setUserPointer((void*)m_pCameraNode);
// optimize the body
m_btCamera->setFriction(1.0);
m_btCamera->setDamping(0.8, 0.8);
m_btCamera->setAngularFactor(btVector3(0, 0, 0));
m_btCamera->setHitFraction(0.0);
m_btCamera->setContactProcessingThreshold(0.0);
m_btCamera->setGravity(m_defGravity);
// add the rigid body to the dynamics world
//m_physics->setCameraBody(m_btCamera);
}
//================================================//
void Camera::removeRigidBody(void)
{
// Remove Bullet objects
m_physics->removeCameraBody();
delete m_btCamera->getMotionState();
delete m_btCamera;
}
//================================================//
void Camera::update(double timeSinceLastFrame)
{
switch(m_mode){
case MODE_FIRST_PERSON:
this->moveFirstPerson(timeSinceLastFrame);
return;
case MODE_SPECTATOR:
default:
this->moveSpectator(timeSinceLastFrame);
return;
}
}
//================================================//
void Camera::setPosition(Ogre::Vector3 pos)
{
btTransform transform = m_btCamera->getWorldTransform();
transform.setOrigin(btVector3(pos.x, pos.y, pos.z));
m_btCamera->setWorldTransform(transform);
}
//================================================//
void Camera::setOrientation(Ogre::Quaternion q)
{
btTransform transform = m_btCamera->getWorldTransform();
transform.setRotation(btQuaternion(q.x, q.y, q.z, q.w));
m_btCamera->setWorldTransform(transform);
}
//================================================//
void Camera::moveFirstPerson(double timeSinceLastFrame)
{
// Limit the pitch
Ogre::Real pitchAngle, pitchAngleSign;
pitchAngle = (2 * Ogre::Degree(Ogre::Math::ACos(m_pCameraPitchNode->getOrientation().w)).valueDegrees());
pitchAngleSign = m_pCameraPitchNode->getOrientation().x;
if(pitchAngle > 80.0f){
if(pitchAngleSign > 0){
m_pCameraPitchNode->setOrientation(Ogre::Quaternion(Ogre::Math::Sqrt(0.5f), Ogre::Math::Sqrt(0.5f) - 0.115f, 0, 0));
}
else{
m_pCameraPitchNode->setOrientation(Ogre::Quaternion(Ogre::Math::Sqrt(0.5f), -Ogre::Math::Sqrt(0.5f) + 0.115f, 0, 0));
}
}
this->updateRays();
// See if player is colliding against a wall in mid-air
// if so, stop the movement and let the player fall
// ...
m_translateVector = Ogre::Vector3::ZERO;
// Apply movements based on keys pressed
if(m_moveForwardsPressed){
m_translateVector.z = -m_moveSpeed;
}
else if(!m_moveBackwardsPressed){
m_translateVector.z = 0.0;
}
if(m_moveBackwardsPressed){
m_translateVector.z = m_moveSpeed;
}
else if(!m_moveForwardsPressed){
m_translateVector.z = 0.0;
}
if(m_moveLeftPressed){
//m_translateVector.x = -(m_moveSpeed * 0.90); // limit sideways movement to 90%
m_translateVector.x = -m_moveSpeed;
}
else if(!m_moveRightPressed){
m_translateVector.x = 0.0;
}
if(m_moveRightPressed){
//m_translateVector.x = (m_moveSpeed * 0.90);
m_translateVector.x = m_moveSpeed;
}
else if(!m_moveLeftPressed){
m_translateVector.x = 0.0;
}
m_translateVector = (m_pCameraYawNode->getOrientation() * m_pCameraPitchNode->getOrientation() * m_translateVector);
// Calculate the forwards vector and use it to keep the camera going the same speed, despite the pitch
// Note: this may allow wall climbing where not conceivable
Ogre::Vector3 forwards = m_pCamera->getDerivedUp();
forwards.crossProduct(m_pCamera->getDerivedRight());
forwards.normalise();
m_translateVector.x /= forwards.y;
m_translateVector.z /= forwards.y;
m_translateVector.y = 0.0;
// Stop if the user is not moving
if(m_translateVector == Ogre::Vector3::ZERO){
return;
}
// Update the jump physics
this->updateJump(timeSinceLastFrame);
// Update the camera by applying an impulse to the Bullet rigid body
btVector3 btTranslate(m_translateVector.x, m_translateVector.y, m_translateVector.z);
m_btCamera->activate();
m_btCamera->applyCentralForce(btTranslate);
}
//================================================//
void Camera::updateJump(double timeSinceLastFrame)
{
// Process falling
if(m_negativeYRayhit->distance > m_maxYOffset){
if(m_btCamera->getLinearVelocity().length() > (m_maxVelocity / 2.0))
m_translateVector *= 0.005;
}
return;
static bool allowAir = false;
static Ogre::Real jmpHeight = 0.0;
if(m_spacePressed){
if(!m_jumping){
// Prevent jumping if the player is falling
if(m_negativeYRayhit->distance > 1.0){ // 1.0 allows for leniency when climbing inclines, rather then only 90 degrees on a flat plane
return;
}
btVector3 jmp(m_translateVector.x * Boots::getSingletonPtr()->getXMultiplier(),
Boots::getSingletonPtr()->getYMultiplier(),
m_translateVector.z * Boots::getSingletonPtr()->getZMultiplier());
// set whether or not to allow movement in the air after jumping
if((Ogre::Math::Abs(jmp.getX()) > 0.0) || (Ogre::Math::Abs(jmp.getZ()) > 0.0))
allowAir = true;
else
allowAir = false;
// Save the height at which the player jumped
jmpHeight = m_pCameraNode->getPosition().y - m_capsuleHeightOffset;
// modify this variable if needed
switch(Boots::getSingletonPtr()->getEquippedType()){
case Boots::BOOTS_TYPE_NORMAL:
default:
//jmpHeight /= 1.5;
break;
}
m_btCamera->setGravity(Boots::getSingletonPtr()->getGravity());
m_btCamera->activate();
m_btCamera->applyCentralImpulse(jmp);
m_jumping = true;
return;
}
}
// Test if the player is on the ground, if so set jumping to false
if((m_negativeYRayhit->distance <= 1.0) && (m_jumping)){
m_btCamera->setGravity(m_defGravity);
m_jumping = false;
// TODO: Test here the difference between the camPos.y and original jump height for death upon impact of the ground
return;
}
// Apply jumping forces if still in the air--basically allows the player to move while in the air (most games do this to some extent)
if(m_jumping){
// stop movement in the air if the player just jumped straight up by multiplying by allowAir
btVector3 jmp(m_translateVector.x * Boots::getSingletonPtr()->getXAirMultiplier() * Ogre::Real(allowAir),
0.0,
m_translateVector.z * Boots::getSingletonPtr()->getZAirMultiplier() * Ogre::Real(allowAir));
//! OPTIMIZE! slow down movement after player has fallen below original jump height
if((m_pCameraNode->getPosition().y - m_capsuleHeightOffset) <= jmpHeight){
jmp /= 1.5;
// decrement the gravity until it's normal
btVector3 gravity = m_btCamera->getGravity();
if(gravity.getY() > m_defGravity.getY()){
gravity.setY(gravity.getY() - 0.01);
m_btCamera->setGravity(gravity);
}
}
m_btCamera->activate();
m_btCamera->applyCentralImpulse(jmp * timeSinceLastFrame / 10.0); // it perplexes me on why this must be frame-rate independent when the engine's time step already is
}
// Test if the player is falling and not jumping, to allow for some movement
else if(m_negativeYRayhit->distance > 0.1){
btVector3 move(m_translateVector.x * 0.01, -0.1, m_translateVector.z * 0.01);
if(m_btCamera->getGravity() != m_defGravity)
m_btCamera->setGravity(m_defGravity);
m_btCamera->activate();
m_btCamera->applyCentralImpulse(move / 10.0); // ^ Same as above call
}
}
//================================================//
void Camera::moveSpectator(double timeSinceLastFrame)
{
m_translateVector = Ogre::Vector3::ZERO;
// Apply movements based on keys pressed
// forwards
if(m_moveForwardsPressed){
if(m_velocityVector.z < m_maxSpecVelocity){
m_velocityVector.z += m_acceleration;
}
else if(m_velocityVector.z > m_maxSpecVelocity){
m_velocityVector.z -= m_acceleration;
}
m_translateVector.z = -(m_specMoveSpeed * m_velocityVector.z);
}
else if(!m_moveBackwardsPressed && m_translateVector.z < 0){
if(m_velocityVector.z > 0){
m_velocityVector.z -= (m_acceleration * 2);
if(m_velocityVector.z < 0){
m_velocityVector.z = 0;
}
}
m_translateVector.z = -(m_specMoveSpeed * m_velocityVector.z);
}
// backwards
if(m_moveBackwardsPressed){
if(m_velocityVector.z < m_maxSpecVelocity){
m_velocityVector.z += m_acceleration;
}
else if(m_velocityVector.z > m_maxSpecVelocity){
m_velocityVector.z -= m_acceleration;
}
m_translateVector.z = (m_specMoveSpeed * m_velocityVector.z);
}
else if(!m_moveForwardsPressed && m_translateVector.z > 0){
if(m_velocityVector.z > 0){
m_velocityVector.z -= (m_acceleration * 2);
if(m_velocityVector.z < 0){
m_velocityVector.z = 0;
}
}
m_translateVector.z = (m_specMoveSpeed * m_velocityVector.z);
}
// left
if(m_moveLeftPressed){
if(m_velocityVector.x < m_maxSpecVelocity){
m_velocityVector.x += m_acceleration;
}
else if(m_velocityVector.x > m_maxSpecVelocity){
m_velocityVector.x -= m_acceleration;
}
m_translateVector.x = -(m_specMoveSpeed * m_velocityVector.x / 2); // make left/right movement slower for realism
}
else if(!m_moveRightPressed && m_translateVector.x < 0){
if(m_velocityVector.x > 0){
m_velocityVector.x -= (m_acceleration * 2);
if(m_velocityVector.x < 0){
m_velocityVector.x = 0;
}
}
m_translateVector.x = -(m_specMoveSpeed * m_velocityVector.x / 2);
}
// right
if(m_moveRightPressed){
if(m_velocityVector.x < m_maxSpecVelocity){
m_velocityVector.x += m_acceleration;
}
else if(m_velocityVector.x > m_maxSpecVelocity){
m_velocityVector.x -= m_acceleration;
}
m_translateVector.x = (m_specMoveSpeed * m_velocityVector.x / 2);
}
else if(!m_moveLeftPressed && m_translateVector.x > 0){
if(m_velocityVector.x > 0){
m_velocityVector.x -= (m_acceleration * 2);
if(m_velocityVector.x < 0){
m_velocityVector.x = 0;
}
}
m_translateVector.x = (m_specMoveSpeed * m_velocityVector.x / 2);
}
// translate the camera node
m_translateVector = (m_pCameraYawNode->getOrientation() * m_pCameraPitchNode->getOrientation() * m_translateVector * timeSinceLastFrame / 240.0);
//m_translateVector = (m_pCamera->getOrientationForViewUpdate() * m_translateVector * timeSinceLastFrame / 300.0);
m_pCameraNode->translate(m_translateVector);
}
//================================================//
void Camera::pitch(Ogre::Degree x)
{
Ogre::Radian amount(x * -m_rotateSpeed); // * Profile::sensitivity * Profile::inverted
m_pCameraPitchNode->pitch(amount);
}
//================================================//
void Camera::yaw(Ogre::Degree y)
{
Ogre::Radian amount(y * -m_rotateSpeed);
m_pCameraYawNode->yaw(amount);
}
//================================================//
void Camera::roll(Ogre::Degree z)
{
m_pCameraRollNode->roll(z * -m_rotateSpeed);
}
//================================================//
void Camera::getRayhit(Ogre::Vector3& to, Rayhit* rayhit)
{
btVector3 btFrom(m_pCameraNode->getPosition().x, m_pCameraNode->getPosition().y, m_pCameraNode->getPosition().z);
btVector3 btTo(to.x, to.y, to.z);
btCollisionWorld::ClosestRayResultCallback res(btFrom, btTo);
m_physics->getWorld()->rayTest(btFrom, btTo, res);
if(res.hasHit()){
// Get scene node
rayhit->node = static_cast<Ogre::SceneNode*>(res.m_collisionObject->getUserPointer());
// Calculate distance
rayhit->hitPoint = Sparks::bulletToOgreVector3(res.m_hitPointWorld);
rayhit->distance = m_pCameraNode->getPosition().distance(rayhit->hitPoint);
rayhit->hasHit = true;
}
else{
rayhit->hasHit = false;
}
}
//================================================//
void Camera::getRayhit(Ogre::Vector3& from, Ogre::Vector3& to, Rayhit* rayhit)
{
btVector3 btFrom(from.x, from.y, from.z);
btVector3 btTo(to.x, to.y, to.z);
btCollisionWorld::ClosestRayResultCallback res(btFrom, btTo);
m_physics->getWorld()->rayTest(btFrom, btTo, res);
if(res.hasHit()){
// Get scene node
rayhit->node = static_cast<Ogre::SceneNode*>(res.m_collisionObject->getUserPointer());
// Calculate distance
rayhit->hitPoint = Sparks::bulletToOgreVector3(res.m_hitPointWorld);
rayhit->distance = m_pCameraNode->getPosition().distance(rayhit->hitPoint);
rayhit->hasHit = true;
}
else{
rayhit->hasHit = false;
}
}
//================================================//
void Camera::updateRays(void)
{
// Update rayhits
// Negative Y
this->getRayhit(Ogre::Vector3(m_pCameraNode->getPosition().x, -10000.0, m_pCameraNode->getPosition().z), m_negativeYRayhit);
// Negative Z Varies
this->getRayhit((m_pCameraNode->getPosition() + (this->getDirection() * 10000.0)), m_negativeZRayhit);
}
//================================================//
//void Camera::updateFooting(double timeSinceLastFrame)
//{
// // Cast a ray straight down from the camera's position
// btVector3 from(m_pCameraNode->getPosition().x, m_pCameraNode->getPosition().y, m_pCameraNode->getPosition().z);
// btVector3 to(m_pCameraNode->getPosition().x, -5000.0, m_pCameraNode->getPosition().z);
//
// btCollisionWorld::ClosestRayResultCallback res(from, to);
//
// Base::getSingletonPtr()->m_btWorld->rayTest(from, to, res);
//
// if(res.hasHit()){
// // update the y difference from the camera to the ground
// m_negativeYRayhit->distance = (m_pCameraNode->getPosition().y - Ogre::Math::Abs(res.m_hitPointWorld.getY()) - m_cameraHeight);
//
//
// // get the rigid body pointer of the object hit
///// * This may be causing the world to disappear, because V: #! or something is displayed when it happens
// // use isKinematicObject()
// //btRigidBody* body = static_cast<btRigidBody*>(res.m_collisionObject);
// //if(body){
// // btVector3 velocity = body->getLinearVelocity();
//
// // // adjust the movement speed to compensate for the movement of the object below
// // if(m_btCamera->getLinearVelocity().length() < velocity.length()){
// // m_btCamera->applyCentralImpulse(velocity);
// // printf("V: %.2f\n", velocity.length());
// // }
// //}
// }
//}
//================================================//
void Camera::setMode(unsigned mode)
{
if(mode != m_mode){
m_mode = mode;
if(m_mode == MODE_FIRST_PERSON){
createRigidBody();
}
else if(m_mode == MODE_SPECTATOR){
removeRigidBody();
}
}
}
//================================================//
} // namespace Sparks
//================================================//