Changeset 2442 for code/branches/physics_merge/src/orxonox/objects/worldentities/ControllableEntity.cc
- Timestamp:
- Dec 14, 2008, 4:16:52 PM (15 years ago)
- Location:
- code/branches/physics_merge
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/physics_merge
- Property svn:mergeinfo changed
-
code/branches/physics_merge/src/orxonox/objects/worldentities/ControllableEntity.cc
r2415 r2442 23 23 * Fabian 'x3n' Landau 24 24 * Co-authors: 25 * ...25 * Reto Grieder 26 26 * 27 27 */ … … 44 44 CreateFactory(ControllableEntity); 45 45 46 ControllableEntity::ControllableEntity(BaseObject* creator) : WorldEntity(creator)46 ControllableEntity::ControllableEntity(BaseObject* creator) : MobileEntity(creator) 47 47 { 48 48 RegisterObject(ControllableEntity); … … 57 57 this->bDestroyWhenPlayerLeft_ = false; 58 58 59 this-> velocity_= Vector3::ZERO;60 this-> acceleration_= Vector3::ZERO;61 62 this-> server_position_= Vector3::ZERO;63 this-> client_position_ = Vector3::ZERO;64 this-> server_velocity_ = Vector3::ZERO;65 this-> client_velocity_ = Vector3::ZERO;66 this-> server_orientation_ = Quaternion::IDENTITY;67 this->client_orientation_ = Quaternion::IDENTITY; 68 59 this->server_position_ = Vector3::ZERO; 60 this->client_position_ = Vector3::ZERO; 61 this->server_linear_velocity_ = Vector3::ZERO; 62 this->client_linear_velocity_ = Vector3::ZERO; 63 this->server_orientation_ = Quaternion::IDENTITY; 64 this->client_orientation_ = Quaternion::IDENTITY; 65 this->server_angular_velocity_ = Vector3::ZERO; 66 this->client_angular_velocity_ = Vector3::ZERO; 67 68 69 69 this->setPriority( priority::very_high ); 70 71 70 this->registerVariables(); 72 71 } … … 229 228 void ControllableEntity::tick(float dt) 230 229 { 230 MobileEntity::tick(dt); 231 231 232 if (this->isActive()) 232 233 { 233 this->velocity_ += (dt * this->acceleration_); 234 this->node_->translate(dt * this->velocity_, Ogre::Node::TS_LOCAL); 235 236 if (Core::isMaster()) 234 // Check whether Bullet doesn't do the physics for us 235 if (!this->isDynamic()) 237 236 { 238 this->server_velocity_ = this->velocity_; 239 this->server_position_ = this->node_->getPosition(); 237 if (Core::isMaster()) 238 { 239 this->server_position_ = this->getPosition(); 240 this->server_orientation_ = this->getOrientation(); 241 this->server_linear_velocity_ = this->getVelocity(); 242 this->server_angular_velocity_ = this->getAngularVelocity(); 243 } 244 else if (this->bControlled_) 245 { 246 this->client_position_ = this->getPosition(); 247 this->client_orientation_ = this->getOrientation(); 248 this->client_linear_velocity_ = this->getVelocity(); 249 this->client_angular_velocity_ = this->getAngularVelocity(); 250 } 240 251 } 241 else if (this->bControlled_)242 {243 // COUT(2) << "setting client position" << endl;244 this->client_velocity_ = this->velocity_;245 this->client_position_ = this->node_->getPosition();246 }247 252 } 248 253 } … … 251 256 { 252 257 registerVariable(this->cameraPositionTemplate_, variableDirection::toclient); 253 254 registerVariable(this->client_overwrite_, variableDirection::toserver); 255 256 registerVariable(this->server_position_, variableDirection::toclient, new NetworkCallback<ControllableEntity>(this, &ControllableEntity::processServerPosition)); 257 registerVariable(this->server_velocity_, variableDirection::toclient, new NetworkCallback<ControllableEntity>(this, &ControllableEntity::processServerVelocity)); 258 registerVariable(this->server_orientation_, variableDirection::toclient, new NetworkCallback<ControllableEntity>(this, &ControllableEntity::processServerOrientation)); 259 registerVariable(this->server_overwrite_, variableDirection::toclient, new NetworkCallback<ControllableEntity>(this, &ControllableEntity::processOverwrite)); 260 261 registerVariable(this->client_position_, variableDirection::toserver, new NetworkCallback<ControllableEntity>(this, &ControllableEntity::processClientPosition)); 262 registerVariable(this->client_velocity_, variableDirection::toserver, new NetworkCallback<ControllableEntity>(this, &ControllableEntity::processClientVelocity)); 263 registerVariable(this->client_orientation_, variableDirection::toserver, new NetworkCallback<ControllableEntity>(this, &ControllableEntity::processClientOrientation)); 264 265 266 registerVariable(this->playerID_, variableDirection::toclient, new NetworkCallback<ControllableEntity>(this, &ControllableEntity::networkcallback_changedplayerID)); 258 259 registerVariable(this->server_position_, variableDirection::toclient, new NetworkCallback<ControllableEntity>(this, &ControllableEntity::processServerPosition)); 260 registerVariable(this->server_linear_velocity_, variableDirection::toclient, new NetworkCallback<ControllableEntity>(this, &ControllableEntity::processServerLinearVelocity)); 261 registerVariable(this->server_orientation_, variableDirection::toclient, new NetworkCallback<ControllableEntity>(this, &ControllableEntity::processServerOrientation)); 262 registerVariable(this->server_angular_velocity_, variableDirection::toclient, new NetworkCallback<ControllableEntity>(this, &ControllableEntity::processServerAngularVelocity)); 263 264 registerVariable(this->server_overwrite_, variableDirection::toclient, new NetworkCallback<ControllableEntity>(this, &ControllableEntity::processOverwrite)); 265 registerVariable(this->client_overwrite_, variableDirection::toserver); 266 267 registerVariable(this->client_position_, variableDirection::toserver, new NetworkCallback<ControllableEntity>(this, &ControllableEntity::processClientPosition)); 268 registerVariable(this->client_linear_velocity_, variableDirection::toserver, new NetworkCallback<ControllableEntity>(this, &ControllableEntity::processClientLinearVelocity)); 269 registerVariable(this->client_orientation_, variableDirection::toserver, new NetworkCallback<ControllableEntity>(this, &ControllableEntity::processClientOrientation)); 270 registerVariable(this->client_angular_velocity_, variableDirection::toserver, new NetworkCallback<ControllableEntity>(this, &ControllableEntity::processClientAngularVelocity)); 271 272 registerVariable(this->playerID_, variableDirection::toclient, new NetworkCallback<ControllableEntity>(this, &ControllableEntity::networkcallback_changedplayerID)); 267 273 } 268 274 … … 270 276 { 271 277 if (!this->bControlled_) 272 this-> node_->setPosition(this->server_position_);273 } 274 275 void ControllableEntity::processServer Velocity()278 this->setPosition(this->server_position_); 279 } 280 281 void ControllableEntity::processServerLinearVelocity() 276 282 { 277 283 if (!this->bControlled_) 278 this-> velocity_ = this->server_velocity_;284 this->setVelocity(this->server_linear_velocity_); 279 285 } 280 286 … … 282 288 { 283 289 if (!this->bControlled_) 284 this->node_->setOrientation(this->server_orientation_); 290 this->setOrientation(this->server_orientation_); 291 } 292 293 void ControllableEntity::processServerAngularVelocity() 294 { 295 if (!this->bControlled_) 296 this->setAngularVelocity(this->server_angular_velocity_); 285 297 } 286 298 … … 290 302 { 291 303 this->setPosition(this->server_position_); 292 this->setVelocity(this->server_velocity_);293 304 this->setOrientation(this->server_orientation_); 305 this->setVelocity(this->server_linear_velocity_); 306 this->setAngularVelocity(this->server_angular_velocity_); 294 307 295 308 this->client_overwrite_ = this->server_overwrite_; … … 301 314 if (this->server_overwrite_ == this->client_overwrite_) 302 315 { 303 // COUT(2) << "callback: setting client position" << endl; 304 this->node_->setPosition(this->client_position_); 305 this->server_position_ = this->client_position_; 306 } 307 // else 308 // COUT(2) << "callback: not setting client position" << endl; 309 } 310 311 void ControllableEntity::processClientVelocity() 316 this->setPosition(this->client_position_); 317 // The call above increments the overwrite. This is not desired to reduce traffic 318 --this->server_overwrite_; 319 } 320 } 321 322 void ControllableEntity::processClientLinearVelocity() 312 323 { 313 324 if (this->server_overwrite_ == this->client_overwrite_) 314 325 { 315 this->velocity_ = this->client_velocity_; 316 this->server_velocity_ = this->client_velocity_; 326 this->setVelocity(this->client_linear_velocity_); 327 // The call above increments the overwrite. This is not desired to reduce traffic 328 --this->server_overwrite_; 317 329 } 318 330 } … … 322 334 if (this->server_overwrite_ == this->client_overwrite_) 323 335 { 324 this->node_->setOrientation(this->client_orientation_); 325 this->server_orientation_ = this->client_orientation_; 326 } 327 } 328 336 this->setOrientation(this->client_orientation_); 337 // The call above increments the overwrite. This is not desired to reduce traffic 338 --this->server_overwrite_; 339 } 340 } 341 342 void ControllableEntity::processClientAngularVelocity() 343 { 344 if (this->server_overwrite_ == this->client_overwrite_) 345 { 346 this->setAngularVelocity(this->client_angular_velocity_); 347 // The call above increments the overwrite. This is not desired to reduce traffic 348 --this->server_overwrite_; 349 } 350 } 329 351 330 352 void ControllableEntity::setPosition(const Vector3& position) … … 332 354 if (Core::isMaster()) 333 355 { 334 this->node_->setPosition(position);335 this->server_position_ = position;356 MobileEntity::setPosition(position); 357 this->server_position_ = this->getPosition(); 336 358 ++this->server_overwrite_; 337 359 } 338 360 else if (this->bControlled_) 339 361 { 340 this->node_->setPosition(position); 341 this->client_position_ = position; 362 MobileEntity::setPosition(position); 363 this->client_position_ = this->getPosition(); 364 } 365 } 366 367 void ControllableEntity::setOrientation(const Quaternion& orientation) 368 { 369 if (Core::isMaster()) 370 { 371 MobileEntity::setOrientation(orientation); 372 this->server_orientation_ = this->getOrientation(); 373 ++this->server_overwrite_; 374 } 375 else if (this->bControlled_) 376 { 377 MobileEntity::setOrientation(orientation); 378 this->client_orientation_ = this->getOrientation(); 342 379 } 343 380 } … … 347 384 if (Core::isMaster()) 348 385 { 349 this->velocity_ = velocity;350 this->server_ velocity_ = velocity;386 MobileEntity::setVelocity(velocity); 387 this->server_linear_velocity_ = this->getVelocity(); 351 388 ++this->server_overwrite_; 352 389 } 353 390 else if (this->bControlled_) 354 391 { 355 this->velocity_ = velocity;356 this->client_ velocity_ = velocity;357 } 358 } 359 360 void ControllableEntity:: translate(const Vector3& distance, Ogre::Node::TransformSpace relativeTo)392 MobileEntity::setVelocity(velocity); 393 this->client_linear_velocity_ = this->getVelocity(); 394 } 395 } 396 397 void ControllableEntity::setAngularVelocity(const Vector3& velocity) 361 398 { 362 399 if (Core::isMaster()) 363 400 { 364 this->node_->translate(distance, relativeTo);365 this->server_ position_ = this->node_->getPosition();401 MobileEntity::setAngularVelocity(velocity); 402 this->server_angular_velocity_ = this->getAngularVelocity(); 366 403 ++this->server_overwrite_; 367 404 } 368 405 else if (this->bControlled_) 369 406 { 370 this->node_->translate(distance, relativeTo); 371 this->client_position_ = this->node_->getPosition(); 372 } 373 } 374 375 void ControllableEntity::setOrientation(const Quaternion& orientation) 376 { 407 MobileEntity::setAngularVelocity(velocity); 408 this->client_angular_velocity_ = this->getAngularVelocity(); 409 } 410 } 411 412 void ControllableEntity::setWorldTransform(const btTransform& worldTrans) 413 { 414 MobileEntity::setWorldTransform(worldTrans); 377 415 if (Core::isMaster()) 378 416 { 379 this->node_->setOrientation(orientation); 380 this->server_orientation_ = orientation; 381 ++this->server_overwrite_; 417 this->server_position_ = this->getPosition(); 418 this->server_orientation_ = this->getOrientation(); 419 this->server_linear_velocity_ = this->getVelocity(); 420 this->server_angular_velocity_ = this->getAngularVelocity(); 382 421 } 383 422 else if (this->bControlled_) 384 423 { 385 this->node_->setOrientation(orientation); 386 this->client_orientation_ = orientation; 387 } 388 } 389 390 void ControllableEntity::rotate(const Quaternion& rotation, Ogre::Node::TransformSpace relativeTo) 391 { 392 if (Core::isMaster()) 393 { 394 this->node_->rotate(rotation, relativeTo); 395 this->server_orientation_ = this->node_->getOrientation(); 396 ++this->server_overwrite_; 397 } 398 else if (this->bControlled_) 399 { 400 this->node_->rotate(rotation, relativeTo); 401 this->client_orientation_ = this->node_->getOrientation(); 402 } 403 } 404 405 void ControllableEntity::yaw(const Degree& angle, Ogre::Node::TransformSpace relativeTo) 406 { 407 if (Core::isMaster()) 408 { 409 this->node_->yaw(angle, relativeTo); 410 this->server_orientation_ = this->node_->getOrientation(); 411 ++this->server_overwrite_; 412 } 413 else if (this->bControlled_) 414 { 415 this->node_->yaw(angle, relativeTo); 416 this->client_orientation_ = this->node_->getOrientation(); 417 } 418 } 419 420 void ControllableEntity::pitch(const Degree& angle, Ogre::Node::TransformSpace relativeTo) 421 { 422 if (Core::isMaster()) 423 { 424 this->node_->pitch(angle, relativeTo); 425 this->server_orientation_ = this->node_->getOrientation(); 426 ++this->server_overwrite_; 427 } 428 else if (this->bControlled_) 429 { 430 this->node_->pitch(angle, relativeTo); 431 this->client_orientation_ = this->node_->getOrientation(); 432 } 433 } 434 435 void ControllableEntity::roll(const Degree& angle, Ogre::Node::TransformSpace relativeTo) 436 { 437 if (Core::isMaster()) 438 { 439 this->node_->roll(angle, relativeTo); 440 this->server_orientation_ = this->node_->getOrientation(); 441 ++this->server_overwrite_; 442 } 443 else if (this->bControlled_) 444 { 445 this->node_->roll(angle, relativeTo); 446 this->client_orientation_ = this->node_->getOrientation(); 447 } 448 } 449 450 void ControllableEntity::lookAt(const Vector3& target, Ogre::Node::TransformSpace relativeTo, const Vector3& localDirectionVector) 451 { 452 if (Core::isMaster()) 453 { 454 this->node_->lookAt(target, relativeTo, localDirectionVector); 455 this->server_orientation_ = this->node_->getOrientation(); 456 ++this->server_overwrite_; 457 } 458 else if (this->bControlled_) 459 { 460 this->node_->lookAt(target, relativeTo, localDirectionVector); 461 this->client_orientation_ = this->node_->getOrientation(); 462 } 463 } 464 465 void ControllableEntity::setDirection(const Vector3& direction, Ogre::Node::TransformSpace relativeTo, const Vector3& localDirectionVector) 466 { 467 if (Core::isMaster()) 468 { 469 this->node_->setDirection(direction, relativeTo, localDirectionVector); 470 this->server_orientation_ = this->node_->getOrientation(); 471 ++this->server_overwrite_; 472 } 473 else if (this->bControlled_) 474 { 475 this->node_->setDirection(direction, relativeTo, localDirectionVector); 476 this->client_orientation_ = this->node_->getOrientation(); 424 this->client_position_ = this->getPosition(); 425 this->client_orientation_ = this->getOrientation(); 426 this->client_linear_velocity_ = this->getVelocity(); 427 this->client_angular_velocity_ = this->getAngularVelocity(); 477 428 } 478 429 }
Note: See TracChangeset
for help on using the changeset viewer.