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