@@ -348,9 +348,7 @@ void GameControl::CamUpdate(){
348
348
349
349
float dis = (cameraTargetPos[0 ] - ly_pos[0 ]) * (cameraTargetPos[0 ] - ly_pos[0 ]) + (cameraTargetPos[1 ] - ly_pos[1 ]) * (cameraTargetPos[1 ] - ly_pos[1 ]);
350
350
351
- if (dis <= RADIUS2 ){
352
- return ;
353
- }else {
351
+ if (dis > RADIUS2){
354
352
// move the cameraTargetPos to reduce the dis. Let ly_pos go back to the cicrle.
355
353
float deltaL = sqrt (dis) - RADIUS;
356
354
float dir[3 ];
@@ -363,8 +361,65 @@ void GameControl::CamUpdate(){
363
361
// update camerTargetPos
364
362
cameraTargetPos[0 ] += deltaL * dir[0 ];
365
363
cameraTargetPos[1 ] += deltaL * dir[1 ];
364
+ }else if (dis <= RADIUS2){
365
+ return ;
366
366
}
367
367
368
+ this ->CamMove (1 .0f );
369
+ }
370
+
371
+ void GameControl::InitCamTargetPos (float pos[3 ]){
372
+ for (int i = 0 ;i<3 ;i++){
373
+ this ->cameraTargetPos [i] = pos[i];
374
+ }
375
+ }
376
+
377
+ void GameControl::ResetCamView (){
378
+ FnActor actor;
379
+ actor.Object (this ->mainChar ->character );
380
+ float pos[3 ];
381
+ float fDir [3 ];
382
+ float uDir[3 ];
383
+ actor.GetWorldDirection (fDir ,uDir);
384
+ actor.GetWorldPosition (pos);
385
+ this ->InitCamTargetPos (pos);
386
+
387
+ FnObject cam;
388
+ cam.Object (this ->camera );
389
+ float camPos[3 ];
390
+ camPos[0 ] = pos[0 ] - fDir [0 ] * 100 ;
391
+ camPos[1 ] = pos[1 ] - fDir [1 ] * 100 ;
392
+ camPos[2 ] = CAM_MIN_HIGHT; // no effect
393
+ cam.SetWorldPosition (camPos);
394
+ this ->CamInTop = FALSE ;
395
+ BOOL flag = cam.PutOnTerrain (tID,FALSE , CAM_MIN_HIGHT);
396
+ if (flag == FALSE ) {
397
+ sprintf (debug, " %s reset cam view put on fail\n " , debug);
398
+ }
399
+
400
+ // the camera should look at cameraTargetPos, not the actor.
401
+ float vec[3 ];
402
+ vec[0 ] = cameraTargetPos[0 ] - camPos[0 ];
403
+ vec[1 ] = cameraTargetPos[1 ] - camPos[1 ];
404
+ vec[2 ] = (cameraTargetPos[2 ] + 40 ) - camPos[2 ]; // the height of actor is about 40
405
+ dir_normalize (vec);
406
+ // vec[2] = -0.2;
407
+
408
+ float cp[3 ]; // aUDir cross to vec
409
+ cp[0 ] = uDir[1 ] * vec[2 ] - uDir[2 ] * vec[1 ];
410
+ cp[1 ] = uDir[2 ] * vec[0 ] - uDir[0 ] * vec[2 ];
411
+ cp[2 ] = uDir[0 ] * vec[1 ] - uDir[1 ] * vec[0 ];
412
+
413
+ float cUDir[3 ]; // vec cross to cp
414
+ cUDir[0 ] = vec[1 ] * cp[2 ] - vec[2 ] * cp[1 ];
415
+ cUDir[1 ] = vec[2 ] * cp[0 ] - vec[0 ] * cp[2 ];
416
+ cUDir[2 ] = vec[0 ] * cp[1 ] - vec[1 ] * cp[0 ];
417
+
418
+ cam.SetWorldDirection (vec, cUDir);
419
+ this ->CamMove (20 .0f );
420
+ }
421
+
422
+ void GameControl::CamMove (float skip){
368
423
FnObject cam;
369
424
cam.Object (this ->camera );
370
425
float cam_pos[3 ];
@@ -383,11 +438,11 @@ void GameControl::CamUpdate(){
383
438
cam.SetWorldDirection (tempFDir,tempUDir);
384
439
cam.GetWorldPosition (cam_pos);
385
440
386
- dis = (cam_pos[0 ] - cameraTargetPos[0 ]) * (cam_pos[0 ] - cameraTargetPos[0 ]) + (cam_pos[1 ] - cameraTargetPos[1 ]) * (cam_pos[1 ] - cameraTargetPos[1 ]);
387
- // sprintf(debug, "%s distance between camera and lyubu is %f\n", debug, dis);
441
+ float dis = (cam_pos[0 ] - cameraTargetPos[0 ]) * (cam_pos[0 ] - cameraTargetPos[0 ]) + (cam_pos[1 ] - cameraTargetPos[1 ]) * (cam_pos[1 ] - cameraTargetPos[1 ]);
442
+
388
443
if (dis > 129600 ) {
389
444
// move forward
390
- cam.MoveForward (MOVE_LENGTH,FALSE , FALSE , 0.0 , FALSE );
445
+ cam.MoveForward (MOVE_LENGTH * skip ,FALSE , FALSE , 0.0 , FALSE );
391
446
BOOL flag;
392
447
if (cam_pos[2 ] - MOVE_LENGTH / 1.2 > CAM_MIN_HIGHT){
393
448
flag = cam.PutOnTerrain (tID,FALSE , cam_pos[2 ] - MOVE_LENGTH / 1.2 );
@@ -401,7 +456,11 @@ void GameControl::CamUpdate(){
401
456
}
402
457
firstBlock = TRUE ;
403
458
}else if (dis < 122500 ){
404
- int ret = cam.MoveForward (-MOVE_LENGTH,TRUE , FALSE , 0.0 , TRUE );
459
+ /*
460
+ if (skip > 1.0){
461
+ sprintf(debug, "%s skip = %lf move = %lf\n", debug, skip,-MOVE_LENGTH * skip);
462
+ }*/
463
+ int ret = cam.MoveForward (-MOVE_LENGTH * skip,TRUE , FALSE , 0.0 , TRUE );
405
464
BOOL flag;
406
465
if (ret == 0 ){
407
466
flag = cam.PutOnTerrain (tID,FALSE , CAM_MIN_HIGHT);
@@ -410,7 +469,7 @@ void GameControl::CamUpdate(){
410
469
cam.MoveForward (-0.1 , FALSE , FALSE , 0.0 , TRUE ); // prevent the actor be under the camera, or it can't go out there
411
470
firstBlock = FALSE ;
412
471
}
413
- // sprintf(debug, "%s Camera is blocked\n", debug);
472
+ sprintf (debug, " %s Camera is blocked\n " , debug);
414
473
float pos[3 ];
415
474
cam.GetWorldPosition (pos);
416
475
if (pos[2 ] > CAM_MAX_HIGHT) {
@@ -427,10 +486,4 @@ void GameControl::CamUpdate(){
427
486
sprintf (debug, " %s backoff put on fail\n " , debug);
428
487
}
429
488
}
430
- }
431
-
432
- void GameControl::InitCamTargetPos (float pos[3 ]){
433
- for (int i = 0 ;i<3 ;i++){
434
- this ->cameraTargetPos [i] = pos[i];
435
- }
436
489
}
0 commit comments