aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/newview/head.cpp
diff options
context:
space:
mode:
authorJacek Antonelli2008-08-15 23:44:46 -0500
committerJacek Antonelli2008-08-15 23:44:46 -0500
commit38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4 (patch)
treeadca584755d22ca041a2dbfc35d4eca01f70b32c /linden/indra/newview/head.cpp
parentREADME.txt (diff)
downloadmeta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.zip
meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.gz
meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.bz2
meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.xz
Second Life viewer sources 1.13.2.12
Diffstat (limited to 'linden/indra/newview/head.cpp')
-rw-r--r--linden/indra/newview/head.cpp149
1 files changed, 149 insertions, 0 deletions
diff --git a/linden/indra/newview/head.cpp b/linden/indra/newview/head.cpp
new file mode 100644
index 0000000..527170b
--- /dev/null
+++ b/linden/indra/newview/head.cpp
@@ -0,0 +1,149 @@
1/**
2 * @file head.cpp
3 * @brief Head class implementation
4 *
5 * Copyright (c) 2000-2007, Linden Research, Inc.
6 *
7 * The source code in this file ("Source Code") is provided by Linden Lab
8 * to you under the terms of the GNU General Public License, version 2.0
9 * ("GPL"), unless you have obtained a separate licensing agreement
10 * ("Other License"), formally executed by you and Linden Lab. Terms of
11 * the GPL can be found in doc/GPL-license.txt in this distribution, or
12 * online at http://secondlife.com/developers/opensource/gplv2
13 *
14 * There are special exceptions to the terms and conditions of the GPL as
15 * it is applied to this Source Code. View the full text of the exception
16 * in the file doc/FLOSS-exception.txt in this software distribution, or
17 * online at http://secondlife.com/developers/opensource/flossexception
18 *
19 * By copying, modifying or distributing this software, you acknowledge
20 * that you have read and understood your obligations described above,
21 * and agree to abide by those obligations.
22 *
23 * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
24 * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
25 * COMPLETENESS OR PERFORMANCE.
26 */
27
28// implementation of a class that models the motion of a human head.
29// The physics aren't quite right, but it will suffice for right now.
30
31#include "llviewerprecompiledheaders.h"
32
33#include "head.h"
34
35#ifndef PI
36 #define PI ((F32) 3.14159265358979323846264338327)
37#endif
38
39// The friction force of the neck is modeled as:
40// friction = -E*phi_dot - F*phi_dot (for positive phi_dot)
41#define E1 0.75
42#define F1 0.0
43
44// TODO -- use the other PI defined in the math libs somewhere.
45
46// --------------------------------------------------
47// Misc. function delclarations...
48// --------------------------------------------------
49F32 phi_spring(F32 phi, F32 theta);
50F32 theta_spring(F32 theta, F32 phi);
51
52
53// --------------------------------------------------
54// Class Head member functions...
55// --------------------------------------------------
56
57Head::Head() {
58 mass = 1.0f;
59 radius = 1.0f;
60 inertia = 2.0f * mass * radius * radius / 5.0f;
61 phi = 0.0f;
62 theta = 0.0f;
63 //gettimeofday(&t, &tz);
64}
65
66Head::Head(F32 m, F32 r) {
67 mass = m;
68 radius = r;
69 inertia = 2.0f * mass * radius * radius / 5.0f;
70 phi = 0.0f;
71 theta = 0.0f;
72 //gettimeofday(&t, &tz);
73}
74
75F32 Head::setMass(F32 m) {
76 mass = m;
77 inertia = 2.0f * mass * radius * radius / 5.0f;
78 return mass;
79}
80
81F32 Head::setRadius(F32 r) {
82 radius = r;
83 inertia = 2.0f * mass * radius * radius / 5.0f;
84 return radius;
85}
86
87F32 Head::getMass() { return mass; }
88F32 Head::getRadius() { return radius; }
89F32 Head::getInertia() { return inertia; }
90
91void Head::propagate(F32 horizontal_force, F32 vertical_force, F32 dt) {
92 //struct timeval t1;
93 //F32 dt, temp;
94 F32 phi_torque, theta_torque;
95 F32 phi_dot, theta_dot;
96
97 //gettimeofday(&t1, &tz);
98 //dt = ((t1.tv_sec - t.tv_sec) * 1000000.0 + (t1.tv_usec - t.tv_usec)) / 1000000.0;
99 //dt = 0.033; // This is a kluge to prevent instabilities when using a stepper
100
101 // Calculate the return forces...
102 // Note: horizontal_force is positive toward right, so it's resultant torque
103 // is negative, since the phi spin angle is out the top of the head (using
104 // right-hand rule).
105 phi_torque = radius * (phi_spring(phi, theta) - horizontal_force);
106 theta_torque = radius * (theta_spring(phi, theta) + vertical_force);
107
108 // Propagate phi...
109 phi_dot = dt * phi_torque / inertia;
110
111 phi += dt * phi_dot;
112 if (phi >= PI/2.0f) {
113 phi = PI/2.0f;
114 }
115 else if (phi <= -PI/2.0f) {
116 phi = -PI/2.0f;
117 }
118
119 // Propagate theta...
120 theta_dot = dt * theta_torque / inertia;
121 theta += dt * theta_dot;
122 if (theta >= PI/2.0f) {
123 theta = PI/2.0f;
124 }
125 else if (theta <= -PI/2.0f) {
126 theta = -PI/2.0f;
127 }
128
129 //t = t1;
130 return;
131}
132
133
134F32 phi_spring(F32 phi, F32 theta) {
135// The srping force is linear with -phi and the magnitude of theta.
136 F32 phi_force;
137 phi_force = - 30 * phi;
138 phi_force = phi_force * (1.0f + (F32)fabs(theta) / PI);
139 return phi_force;
140}
141
142
143F32 theta_spring(F32 phi, F32 theta) {
144 return phi_spring(theta, phi);
145}
146
147
148
149