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
142142 #define IDLE_SIMULATE_MSECS 8 // How often should call simulate and other stuff
143143 // in the idle loop?
144144
145−float yaw = 0.f; // The yaw, pitch for the avatar head
146−float pitch = 0.f;
147145 float startYaw = 122.f;
148−float renderPitch = 0.f;
149146 float renderYawRate = 0.f;
150147 float renderPitchRate = 0.f;
151148
@@ -357,8 +354,8 @@ void reset_sensors() · 205 unmodified lines
357354 //
358355 myAvatar.setRenderYaw(startYaw);
359356
360− yaw = renderYawRate = 0;
361− pitch = renderPitch = renderPitchRate = 0;
357+ renderYawRate = 0;
358+ renderPitchRate = 0;
362359 myAvatar.setPos(start_location);
363360 headMouseX = WIDTH/2;
364361 headMouseY = HEIGHT/2;
@@ -370,7 +367,7 @@ void reset_sensors() · 5 unmodified lines
370367 }
371368 }
372369
373−void simulateHand(float deltaTime) {
370+void updateAvatarHand(float deltaTime) {
374371 // If mouse is being dragged, send current force to the hand controller
375372 if (mousePressed == 1)
376373 {
@@ -384,28 +381,26 @@ void simulateHand(float deltaTime) { · 7 unmodified lines
384381 }
385382 }
386383
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)
389388 {
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);
398391
399392 myAvatar.UpdatePos(frametime, &serialPort, headMirror, &gravity);
400393
401− // Update head_mouse model
394+ //
395+ // Update gyro-based mouse (X,Y on screen)
396+ //
402397 const float MIN_MOUSE_RATE = 30.0;
403398 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)
406401 {
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;
409404 }
410405 headMouseX = max(headMouseX, 0);
411406 headMouseX = min(headMouseX, WIDTH);
@@ -415,7 +410,6 @@ void simulateHead(float frametime) · 3 unmodified lines
415410 // Update render direction (pitch/yaw) based on measured gyro rates
416411 const int MIN_YAW_RATE = 100;
417412 const int MIN_PITCH_RATE = 100;
418−
419413 const float YAW_SENSITIVITY = 0.02;
420414 const float PITCH_SENSITIVITY = 0.05;
421415
@@ -424,23 +418,22 @@ void simulateHead(float frametime) · 2 unmodified lines
424418 if (myAvatar.getDriveKeys(ROT_LEFT)) renderYawRate -= KEY_YAW_SENSITIVITY*frametime;
425419 if (myAvatar.getDriveKeys(ROT_RIGHT)) renderYawRate += KEY_YAW_SENSITIVITY*frametime;
426420
427− if (fabs(measured_yaw_rate) > MIN_YAW_RATE)
421+ if (fabs(gyroYawRate) > MIN_YAW_RATE)
428422 {
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;
431425 else
432− renderYawRate += (measured_yaw_rate + MIN_YAW_RATE) * YAW_SENSITIVITY * frametime;
426+ renderYawRate += (gyroYawRate + MIN_YAW_RATE) * YAW_SENSITIVITY * frametime;
433427 }
434− if (fabs(measured_pitch_rate) > MIN_PITCH_RATE)
428+ if (fabs(gyroPitchRate) > MIN_PITCH_RATE)
435429 {
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;
438432 else
439− renderPitchRate += (measured_pitch_rate + MIN_PITCH_RATE) * PITCH_SENSITIVITY * frametime;
433+ renderPitchRate += (gyroPitchRate + MIN_PITCH_RATE) * PITCH_SENSITIVITY * frametime;
440434 }
441435
442− renderPitch += renderPitchRate;
443−
436+ float renderPitch = myAvatar.getRenderPitch();
444437 // Decay renderPitch toward zero because we never look constantly up/down
445438 renderPitch *= (1.f - 2.0*frametime);
446439
@@ -448,9 +441,9 @@ void simulateHead(float frametime) · 1 unmodified line
448441 renderPitchRate *= (1.f - 5.0*frametime);
449442 renderYawRate *= (1.f - 7.0*frametime);
450443
451− // Update own head data
444+ // Update own avatar data
452445 myAvatar.setRenderYaw(myAvatar.getRenderYaw() + renderYawRate);
453− myAvatar.setRenderPitch(renderPitch);
446+ myAvatar.setRenderPitch(renderPitch + renderPitchRate);
454447
455448 // Get audio loudness data from audio input device
456449 float loudness, averageLoudness;
@@ -1358,8 +1351,10 @@ void idle(void) { · 901 unmodified lines
13581351 myAvatar.setTriggeringAction( false );
13591352 }
13601353
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 );
13631358
13641359
13651360 //test
@@ -1374,8 +1369,8 @@ void idle(void) { · 8 unmodified lines
13741369 }
13751370 */
13761371
1377− simulateHand(1.f/FPS);
1378−
1372+ updateAvatarHand(1.f/FPS);
1373+
13791374 field.simulate(1.f/FPS);
13801375 myAvatar.simulate(1.f/FPS);
13811376 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