- Timestamp:
- Nov 30, 2008, 12:36:46 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/physics/src/orxonox/objects/worldentities/MovableEntity.cc
r2298 r2300 42 42 RegisterObject(MovableEntity); 43 43 44 this->velocity_ = Vector3::ZERO; 45 44 46 this->registerVariables(); 45 47 } … … 52 54 { 53 55 SUPER(MovableEntity, XMLPort, xmlelement, mode); 56 57 XMLPortParamTemplate(MovableEntity, "velocity", setVelocity, getVelocity, xmlelement, mode, const Vector3&); 54 58 } 55 59 … … 165 169 this->physicalBody_->setWorldTransform(transf); 166 170 } 167 else 168 { 169 // no physics, we do it ourselves 170 this->node_->setPosition(position); 171 } 171 172 this->node_->setPosition(position); 173 positionChanged(); 172 174 } 173 175 … … 180 182 this->physicalBody_->translate(btVector3(distance.x, distance.y, distance.z)); 181 183 } 182 else 183 { 184 // no physics, we do it ourselves 185 this->node_->translate(distance, relativeTo); 186 } 184 185 this->node_->translate(distance, relativeTo); 186 positionChanged(); 187 187 } 188 188 … … 195 195 this->physicalBody_->setWorldTransform(transf); 196 196 } 197 else 198 { 199 // no physics, we do it ourselves 200 this->node_->setOrientation(orientation); 201 } 197 198 this->node_->setOrientation(orientation); 199 orientationChanged(); 202 200 } 203 201 … … 211 209 this->physicalBody_->setWorldTransform(transf * btTransform(btQuaternion(rotation.w, rotation.x, rotation.y, rotation.z))); 212 210 } 213 else 214 { 215 // no physics, we do it ourselves 216 this->node_->rotate(rotation, relativeTo); 217 } 211 212 this->node_->rotate(rotation, relativeTo); 213 orientationChanged(); 218 214 } 219 215 … … 228 224 this->physicalBody_->setWorldTransform(transf * rotation); 229 225 } 230 else 231 { 232 // no physics, we do it ourselves 233 this->node_->yaw(angle, relativeTo); 234 } 226 227 this->node_->yaw(angle, relativeTo); 228 orientationChanged(); 235 229 } 236 230 … … 245 239 this->physicalBody_->setWorldTransform(transf * rotation); 246 240 } 247 else 248 { 249 // no physics, we do it ourselves 250 this->node_->pitch(angle, relativeTo); 251 } 241 242 this->node_->pitch(angle, relativeTo); 243 orientationChanged(); 252 244 } 253 245 … … 262 254 this->physicalBody_->setWorldTransform(transf * rotation); 263 255 } 264 else 265 { 266 // no physics, we do it ourselves 267 this->node_->roll(angle, relativeTo); 268 } 256 257 this->node_->roll(angle, relativeTo); 258 orientationChanged(); 269 259 } 270 260 … … 279 269 //this->physicalBody_->setWorldTransform(transf); 280 270 } 281 else 282 { 283 // no physics, we do it ourselves 284 this->node_->lookAt(target, relativeTo, localDirectionVector); 285 } 271 272 this->node_->lookAt(target, relativeTo, localDirectionVector); 273 orientationChanged(); 286 274 } 287 275 … … 290 278 if (this->isDynamic()) 291 279 { 292 ThrowException(NotImplemented, "ControllableEntity:: lookAt() is not yet supported for physical objects.");280 ThrowException(NotImplemented, "ControllableEntity::setDirection() is not yet supported for physical objects."); 293 281 OrxAssert(relativeTo == Ogre::Node::TS_LOCAL, "Cannot align physical object relative \ 294 282 to any other space than TS_LOCAL."); … … 296 284 //this->physicalBody_->setWorldTransform(transf); 297 285 } 298 else 299 { 300 // no physics, we do it ourselves 301 this->node_->setDirection(direction, relativeTo, localDirectionVector); 302 } 303 } 304 305 bool MovableEntity::isCollisionTypeLegal(WorldEntity::CollisionType type) 286 287 this->node_->setDirection(direction, relativeTo, localDirectionVector); 288 orientationChanged(); 289 } 290 291 void MovableEntity::setVelocity(const Vector3& velocity) 292 { 293 if (this->isDynamic()) 294 { 295 this->physicalBody_->setLinearVelocity(btVector3(velocity.x, velocity.y, velocity.z)); 296 } 297 298 this->velocity_ = velocity; 299 velocityChanged(); 300 } 301 302 bool MovableEntity::isCollisionTypeLegal(WorldEntity::CollisionType type) const 306 303 { 307 304 if (type == WorldEntity::Static) … … 320 317 this->node_->setOrientation(Quaternion(worldTrans.getRotation().w(), worldTrans.getRotation().x(), worldTrans.getRotation().y(), worldTrans.getRotation().z())); 321 318 const btVector3& velocity = this->physicalBody_->getLinearVelocity(); 322 internalSetVelocity(Vector3(velocity.x(), velocity.y(), velocity.z())); 319 this->velocity_ = Vector3(velocity.x(), velocity.y(), velocity.z()); 320 velocityChanged(); 323 321 positionChanged(); 324 322 orientationChanged(); … … 330 328 worldTrans.setOrigin(btVector3(node_->getPosition().x, node_->getPosition().y, node_->getPosition().z)); 331 329 worldTrans.setRotation(btQuaternion(node_->getOrientation().w, node_->getOrientation().x, node_->getOrientation().y, node_->getOrientation().z)); 330 if (this->isDynamic()) 331 { 332 // This function gets called only once for dynamic objects to set the initial conditions 333 // We have to set the velocity too. 334 this->physicalBody_->setLinearVelocity(btVector3(velocity_.x, velocity_.y, velocity_.z)); 335 } 332 336 } 333 337 }
Note: See TracChangeset
for help on using the changeset viewer.