Changeset 10655 in orxonox.OLD for branches/vs-enhencements/src/world_entities/npcs/actionbox_enemy.cc
- Timestamp:
- May 13, 2007, 1:27:37 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/vs-enhencements/src/world_entities/npcs/actionbox_enemy.cc
r10651 r10655 83 83 { 84 84 Vector targetPos = State::getPlayer()->getPlayable()->getAbsCoor(); 85 Vector targetDir = targetPos - this->getAbsCoor(); 85 86 86 Vector fw = this->getAbsDir().apply( Vector( 0, 0, -1 ) );87 fw.normalize();88 87 89 Vector dv = targetPos - this->getAbsCoor();90 dv.normalize();88 Quaternion cur = this->getAbsDir(); 89 Quaternion rx( 5*dt, Vector( 0, 0, 1 ) ); 91 90 92 Vector up = fw.cross( dv )*-1; 91 Quaternion tmp1 = cur * rx; 92 Quaternion tmp2 = cur * rx.inverse(); 93 93 94 Quaternion rot(up, 10.0*dt); 95 rot.normalize(); 96 Quaternion cur = this->getAbsDir(); 97 Quaternion ne = rot * cur; 98 this->setAbsDir( ne ); 94 if ( tmp1.apply( Vector(1, 0, 0) ).dot(targetDir) > tmp2.apply( Vector(1, 0, 0)).dot(targetDir) ) 95 cur = tmp1; 96 else 97 cur = tmp2; 99 98 100 // 1, 0, 0 101 // 0, 1, 0 102 return; 103 Vector k = ne.apply( Vector( 1, 0, 0 ) ); 104 k.normalize(); 99 Quaternion ry( 5*dt, cur.inverse().apply( Vector( 0, 1, 0 ) ) ); 105 100 106 Vector vr = k.cross( Vector( 0, 1, 0) ); 101 tmp1 = cur * ry; 102 tmp2 = cur * ry.inverse(); 107 103 108 rot = Quaternion(vr, 10.0*dt); 109 rot.normalize(); 110 cur = ne; 111 ne = rot * cur; 112 ne.normalize(); 113 114 this->setAbsDir( ne ); 104 if ( tmp1.apply( Vector(1, 0, 0) ).dot(targetDir) > tmp2.apply( Vector(1, 0, 0)).dot(targetDir) ) 105 cur = tmp1; 106 else 107 cur = tmp2; 108 109 this->setAbsDir( cur ); 115 110 } 116 111 … … 130 125 dv += mp; 131 126 132 Vector up = fw.cross( dv )*-1; 127 Vector spUp = this->getAbsDir().inverse().apply( this->getAbsDir().apply( Vector( 0, 1, 0 ) ) ); 128 spUp.normalize(); 129 spUp *= 100; 130 spUp += mp; 131 132 Vector up = fw.cross( dv ); 133 133 up += mp; 134 134 … … 154 154 glEnd(); 155 155 156 glColor3f(0.0, 1.0, 0.0 ); 156 157 glBegin(GL_LINE_STRIP); 157 158 glVertex3f(mp.x, mp.y, mp.z); … … 159 160 glEnd(); 160 161 162 glColor3f(0.0, 0.0, 1.0 ); 161 163 glBegin(GL_LINE_STRIP); 162 164 glVertex3f(mp.x, mp.y, mp.z); 163 165 glVertex3f(up.x, up.y, up.z); 166 glEnd(); 167 168 glColor3f(1.0, 1.0, 1.0 ); 169 glBegin(GL_LINE_STRIP); 170 glVertex3f(mp.x, mp.y, mp.z); 171 glVertex3f(spUp.x, spUp.y, spUp.z); 164 172 glEnd(); 165 173
Note: See TracChangeset
for help on using the changeset viewer.