History

Merge pull request #47 from PhilipRosedale/master

Cleanup and partial re-enabling of head gyros

ZappoMan committed 13 years ago

Commit 1408be02 parents 1cdeac0 5e5a7e04 files · +92 −80Browse files

Showing the changes to interface/src/main.cpp (1 of 4 files). Show all

Unified · Split

interface/src/main.cpp+33−38
@@ -142,10 +142,7 @@ Audio audio(&audioScope, &myAvatar); · 141 unmodified lines
142#define IDLE_SIMULATE_MSECS 8 // How often should call simulate and other stuff 142#define IDLE_SIMULATE_MSECS 8 // How often should call simulate and other stuff
143 // in the idle loop?143 // in the idle loop?
144 144
145float yaw = 0.f; // The yaw, pitch for the avatar head
146float pitch = 0.f;
147float startYaw = 122.f;145float startYaw = 122.f;
148float renderPitch = 0.f;
149float renderYawRate = 0.f;146float renderYawRate = 0.f;
150float renderPitchRate = 0.f; 147float renderPitchRate = 0.f;
151 148
@@ -357,8 +354,8 @@ void reset_sensors() · 205 unmodified lines
357 // 354 //
358 myAvatar.setRenderYaw(startYaw);355 myAvatar.setRenderYaw(startYaw);
359 356
360 yaw = renderYawRate = 0; 357 renderYawRate = 0;
361 pitch = renderPitch = renderPitchRate = 0;358 renderPitchRate = 0;
362 myAvatar.setPos(start_location);359 myAvatar.setPos(start_location);
363 headMouseX = WIDTH/2;360 headMouseX = WIDTH/2;
364 headMouseY = HEIGHT/2;361 headMouseY = HEIGHT/2;
@@ -370,7 +367,7 @@ void reset_sensors() · 5 unmodified lines
370 }367 }
371}368}
372 369
373void simulateHand(float deltaTime) {370void updateAvatarHand(float deltaTime) {
374 // If mouse is being dragged, send current force to the hand controller371 // If mouse is being dragged, send current force to the hand controller
375 if (mousePressed == 1)372 if (mousePressed == 1)
376 {373 {
@@ -384,28 +381,26 @@ void simulateHand(float deltaTime) { · 7 unmodified lines
384 }381 }
385}382}
386 383
387void simulateHead(float frametime)384//
388// Using serial data, update avatar/render position and angles385// Using gyro data, update both view frustum and avatar head position
386//
387void updateAvatar(float frametime)
389{388{
390// float measured_pitch_rate = serialPort.getRelativeValue(PITCH_RATE);389 float gyroPitchRate = serialPort.getRelativeValue(PITCH_RATE);
391// float measured_yaw_rate = serialPort.getRelativeValue(YAW_RATE);390 float gyroYawRate = serialPort.getRelativeValue(YAW_RATE);
392
393 float measured_pitch_rate = 0;
394 float measured_yaw_rate = 0;
395
396 //float measured_lateral_accel = serialPort.getRelativeValue(ACCEL_X);
397 //float measured_fwd_accel = serialPort.getRelativeValue(ACCEL_Z);
398 391
399 myAvatar.UpdatePos(frametime, &serialPort, headMirror, &gravity);392 myAvatar.UpdatePos(frametime, &serialPort, headMirror, &gravity);
400 393
401 // Update head_mouse model 394 //
395 // Update gyro-based mouse (X,Y on screen)
396 //
402 const float MIN_MOUSE_RATE = 30.0;397 const float MIN_MOUSE_RATE = 30.0;
403 const float MOUSE_SENSITIVITY = 0.1f;398 const float MOUSE_SENSITIVITY = 0.1f;
404 if (powf(measured_yaw_rate*measured_yaw_rate + 399 if (powf(gyroYawRate*gyroYawRate +
405 measured_pitch_rate*measured_pitch_rate, 0.5) > MIN_MOUSE_RATE)400 gyroPitchRate*gyroPitchRate, 0.5) > MIN_MOUSE_RATE)
406 {401 {
407 headMouseX += measured_yaw_rate*MOUSE_SENSITIVITY;402 headMouseX += gyroYawRate*MOUSE_SENSITIVITY;
408 headMouseY += measured_pitch_rate*MOUSE_SENSITIVITY*(float)HEIGHT/(float)WIDTH; 403 headMouseY += gyroPitchRate*MOUSE_SENSITIVITY*(float)HEIGHT/(float)WIDTH;
409 }404 }
410 headMouseX = max(headMouseX, 0);405 headMouseX = max(headMouseX, 0);
411 headMouseX = min(headMouseX, WIDTH);406 headMouseX = min(headMouseX, WIDTH);
@@ -415,7 +410,6 @@ void simulateHead(float frametime) · 3 unmodified lines
415 // Update render direction (pitch/yaw) based on measured gyro rates410 // Update render direction (pitch/yaw) based on measured gyro rates
416 const int MIN_YAW_RATE = 100;411 const int MIN_YAW_RATE = 100;
417 const int MIN_PITCH_RATE = 100;412 const int MIN_PITCH_RATE = 100;
418
419 const float YAW_SENSITIVITY = 0.02;413 const float YAW_SENSITIVITY = 0.02;
420 const float PITCH_SENSITIVITY = 0.05;414 const float PITCH_SENSITIVITY = 0.05;
421 415
@@ -424,23 +418,22 @@ void simulateHead(float frametime) · 2 unmodified lines
424 if (myAvatar.getDriveKeys(ROT_LEFT)) renderYawRate -= KEY_YAW_SENSITIVITY*frametime;418 if (myAvatar.getDriveKeys(ROT_LEFT)) renderYawRate -= KEY_YAW_SENSITIVITY*frametime;
425 if (myAvatar.getDriveKeys(ROT_RIGHT)) renderYawRate += KEY_YAW_SENSITIVITY*frametime;419 if (myAvatar.getDriveKeys(ROT_RIGHT)) renderYawRate += KEY_YAW_SENSITIVITY*frametime;
426 420
427 if (fabs(measured_yaw_rate) > MIN_YAW_RATE) 421 if (fabs(gyroYawRate) > MIN_YAW_RATE)
428 { 422 {
429 if (measured_yaw_rate > 0)423 if (gyroYawRate > 0)
430 renderYawRate += (measured_yaw_rate - MIN_YAW_RATE) * YAW_SENSITIVITY * frametime;424 renderYawRate += (gyroYawRate - MIN_YAW_RATE) * YAW_SENSITIVITY * frametime;
431 else 425 else
432 renderYawRate += (measured_yaw_rate + MIN_YAW_RATE) * YAW_SENSITIVITY * frametime;426 renderYawRate += (gyroYawRate + MIN_YAW_RATE) * YAW_SENSITIVITY * frametime;
433 }427 }
434 if (fabs(measured_pitch_rate) > MIN_PITCH_RATE) 428 if (fabs(gyroPitchRate) > MIN_PITCH_RATE)
435 {429 {
436 if (measured_pitch_rate > 0)430 if (gyroPitchRate > 0)
437 renderPitchRate += (measured_pitch_rate - MIN_PITCH_RATE) * PITCH_SENSITIVITY * frametime;431 renderPitchRate += (gyroPitchRate - MIN_PITCH_RATE) * PITCH_SENSITIVITY * frametime;
438 else 432 else
439 renderPitchRate += (measured_pitch_rate + MIN_PITCH_RATE) * PITCH_SENSITIVITY * frametime;433 renderPitchRate += (gyroPitchRate + MIN_PITCH_RATE) * PITCH_SENSITIVITY * frametime;
440 }434 }
441 435
442 renderPitch += renderPitchRate;436 float renderPitch = myAvatar.getRenderPitch();
443
444 // Decay renderPitch toward zero because we never look constantly up/down 437 // Decay renderPitch toward zero because we never look constantly up/down
445 renderPitch *= (1.f - 2.0*frametime);438 renderPitch *= (1.f - 2.0*frametime);
446 439
@@ -448,9 +441,9 @@ void simulateHead(float frametime) · 1 unmodified line
448 renderPitchRate *= (1.f - 5.0*frametime);441 renderPitchRate *= (1.f - 5.0*frametime);
449 renderYawRate *= (1.f - 7.0*frametime);442 renderYawRate *= (1.f - 7.0*frametime);
450 443
451 // Update own head data444 // Update own avatar data
452 myAvatar.setRenderYaw(myAvatar.getRenderYaw() + renderYawRate);445 myAvatar.setRenderYaw(myAvatar.getRenderYaw() + renderYawRate);
453 myAvatar.setRenderPitch(renderPitch);446 myAvatar.setRenderPitch(renderPitch + renderPitchRate);
454 447
455 // Get audio loudness data from audio input device448 // Get audio loudness data from audio input device
456 float loudness, averageLoudness;449 float loudness, averageLoudness;
@@ -1358,8 +1351,10 @@ void idle(void) { · 901 unmodified lines
1358 myAvatar.setTriggeringAction( false );1351 myAvatar.setTriggeringAction( false );
1359 }1352 }
1360 1353
1361 // Simulation1354 //
1362 simulateHead( 1.f/FPS );1355 // Sample hardware, update view frustum if needed, send avatar data to mixer/agents
1356 //
1357 updateAvatar( 1.f/FPS );
1363 1358
1364 1359
1365 //test1360 //test
@@ -1374,8 +1369,8 @@ void idle(void) { · 8 unmodified lines
1374 }1369 }
1375 */1370 */
1376 1371
1377 simulateHand(1.f/FPS);1372 updateAvatarHand(1.f/FPS);
1378 1373
1379 field.simulate(1.f/FPS);1374 field.simulate(1.f/FPS);
1380 myAvatar.simulate(1.f/FPS);1375 myAvatar.simulate(1.f/FPS);
1381 balls.simulate(1.f/FPS);1376 balls.simulate(1.f/FPS);

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t