Changeset 10379 in orxonox.OLD for trunk/src/world_entities/camera.cc
- Timestamp:
- Jan 26, 2007, 10:58:31 AM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/world_entities/camera.cc
r10368 r10379 18 18 #include "key_mapper.h" 19 19 #include "glincl.h" 20 //#include "util/loading/load_param.h"20 #include "util/loading/load_param.h" 21 21 #include "world_entity.h" 22 #include "vector.h" 23 #include "targets.h" 24 25 26 22 27 23 28 ObjectListDefinition(Camera); 29 24 30 25 31 /** … … 51 57 this->setName("camera"); 52 58 this->target = new CameraTarget(); 53 59 this->target->masta=this; 54 60 this->subscribeEvent(ES_GAME, KeyMapper::PEV_VIEW0); 55 61 this->subscribeEvent(ES_GAME, KeyMapper::PEV_VIEW1); … … 89 95 void Camera::lookAt(PNode* target) 90 96 { 97 this->target->setParentSoft(target,0.2); 98 } 99 100 /** 101 * @returns The PNode of the Target (from there you can get position and so on 102 */ 103 PNode* Camera::getTargetNode() const 104 { 105 return (PNode*)this->target; 106 } 107 108 void Camera::setTargetNode(PNode* target) 109 { 91 110 this->target->setParent(target); 92 }93 94 /**95 * @returns The PNode of the Target (from there you can get position and so on96 */97 PNode* Camera::getTargetNode() const98 {99 return (PNode*)this->target;100 111 } 101 112 … … 186 197 this->viewVector = (this->target->getAbsCoor() - this->getAbsCoor()).getNormalized(); 187 198 this->frustumPlane = Plane(this->viewVector, this->getAbsCoor() + this->viewVector * 0.1); 188 189 199 this->upVector = this->getAbsDirV(); 190 200 191 201 // iteration for fovy 192 202 float tmpFovy = (this->toFovy - this->fovy); 193 203 if (fabsf(tmpFovy) > 0.01) 194 204 this->fovy += tmpFovy * fabsf(dt); 205 206 207 208 209 //iterate(float dt, translate, target) 210 target->translate(dt); 195 211 } 196 212 … … 227 243 Vector targetPosition = this->target->getAbsCoor(); 228 244 229 //Setting the Camera Eye, lookAt and up Vectors245 //Setting the Camera Eye, lookAt and up Vectors 230 246 gluLookAt(cameraPosition.x, cameraPosition.y, cameraPosition.z, 231 247 targetPosition.x, targetPosition.y, targetPosition.z, … … 269 285 } 270 286 271 /* 287 272 288 void Camera::loadParams(const TiXmlElement* root) 273 289 { … … 289 305 LoadParam(root, "viewNormalDistance", this, Camera, setViewNormalDistance); 290 306 } 291 */ 307 292 308 293 309 void Camera::setViewTopFovy(float fovy) … … 350 366 this->viewNormalDistance = Distance; 351 367 } 368 369 370 371 372 void Camera::glLookAt(float eyex, float eyey, float eyez, float centerx, float centery, float centerz, float upx, float upy, float upz) 373 { 374 //Vector* eye=new Vector(eyex, eyey, eyez); 375 Vector* center=new Vector (centerx, centery, centerz); 376 Vector* up=new Vector(upx, upy, upz); 377 378 center->x-=eyex; 379 center->y-=eyey; 380 center->z-=eyez; 381 382 center->normalize(); 383 up->normalize(); 384 Vector* s = VectorProd(center, up); 385 Vector* u = VectorProd(s, center); 386 GLfloat Matrix[]={s->x, s->y, s->z, 0, u->x, u->y, u->z, 0, -center->x, -center->y, -center->z, 0, 0, 0, 0, 1}; 387 388 glMultMatrixf(Matrix); 389 glTranslated(-eyex, -eyey, -eyez); 390 delete center; 391 delete up; 392 delete s; 393 delete u; 394 395 } 396 397 398 399 400 Vector* Camera::VectorProd(Vector* v1, Vector* v2) 401 { 402 Vector* temp= new Vector(); 403 temp->x=v1->y * v2->z - v1->z * v2->y; 404 temp->y=v1->z * v2->x - v1->x * v2->z; 405 temp->z=v1->x * v2->y - v1->y * v2->x; 406 return temp; 407 } 408 409 410 411 412 413 414 415 416 417 418 419 352 420 353 421 … … 355 423 // CAMERA-TARGET // 356 424 /////////////////// 425 //REATE_FACTORY(CameraTarget); 426 357 427 358 428 ObjectListDefinition(CameraTarget); 429 430 359 431 CameraTarget::CameraTarget() 360 432 { 361 433 this->registerObject(this, CameraTarget::_objectList); 362 434 // this->setParentMode(PNODE_MOVEMENT); 363 } 364 435 this->speed=1; 436 translateTo.x=0; 437 translateTo.y=0; 438 translateTo.z=0; 439 rotateBy.x=0; 440 rotateBy.y=0; 441 rotateBy.z=0; 442 target=createStick(); 443 } 444 445 446 void CameraTarget::detach() 447 { 448 masta->setParentSoft(target); 449 masta->getTargetNode()->setParentSoft(target); 450 } 451 452 PNode* CameraTarget::createStick() 453 { 454 return new Targets(); 455 } 456 457 458 void CameraTarget::atach(PNode* object) 459 { 460 masta->setParentSoft(object); 461 masta->getTargetNode()->setParentSoft(object); 462 } 463 464 465 466 467 Vector CameraTarget::iterate(float dt, const Vector* Target, const Vector* cam) 468 { 469 470 471 Vector tmpVec; 472 tmpVec= (*Target - *cam); 473 tmpVec.normalize(); 474 return tmpVec; 475 476 } 477 478 479 void CameraTarget::translate(float dt) 480 { 481 if (fabs(translateTo.len() - (target->getAbsCoor()).len()) >= 11 ) 482 { 483 printf("translate\n"); 484 Vector tmpVec= iterate(dt, &translateTo, &(masta->getAbsCoor())); 485 target->shiftCoor(speed*tmpVec.x, speed*tmpVec.y, speed*tmpVec.z); 486 } 487 } 488 489 Vector * CameraTarget::rotate(Vector* newPos, float speed) 490 { 491 492 } 493 494 void CameraTarget::jump(float x, float y, float z) 495 { 496 target->setAbsCoor(x,y,z); 497 } 498 499 500 void CameraTarget::trans(float x, float y, float z) 501 { 502 Vector tmpVec=Vector(x,y,z); 503 if( this->getParent()) 504 this->getParent()->setRelCoor(this->getParent()->getRelCoor()); 505 translateNow(&tmpVec); 506 } 507 508 void CameraTarget::translateNow(Vector* vec) 509 { 510 translateTo=*vec; 511 } 512 513 void CameraTarget::changeSpeed(float speed) 514 { 515 if (speed!=0) 516 this->speed=speed; 517 return; 518 } 519 520 521 bool CameraTarget::isDone() 522 { 523 if (fabs(translateTo.len() - (target->getAbsCoor()).len()) >= 11 ) 524 return 0; 525 else 526 return 1; 527 }
Note: See TracChangeset
for help on using the changeset viewer.