Skip to content

Commit 82f397c

Browse files
author
Chun-Yi
committed
Merge pull request #9 from wingzero0/master
camera view
2 parents 4bd259e + ba9ff3f commit 82f397c

File tree

3 files changed

+73
-14
lines changed

3 files changed

+73
-14
lines changed

GameControl.cpp

Lines changed: 67 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -348,9 +348,7 @@ void GameControl::CamUpdate(){
348348

349349
float dis = (cameraTargetPos[0] - ly_pos[0]) * (cameraTargetPos[0] - ly_pos[0]) + (cameraTargetPos[1] - ly_pos[1]) * (cameraTargetPos[1] - ly_pos[1]);
350350

351-
if (dis <= RADIUS2 ){
352-
return;
353-
}else {
351+
if (dis > RADIUS2){
354352
//move the cameraTargetPos to reduce the dis. Let ly_pos go back to the cicrle.
355353
float deltaL = sqrt(dis) - RADIUS;
356354
float dir[3];
@@ -363,8 +361,65 @@ void GameControl::CamUpdate(){
363361
//update camerTargetPos
364362
cameraTargetPos[0] += deltaL * dir[0];
365363
cameraTargetPos[1] += deltaL * dir[1];
364+
}else if (dis <= RADIUS2){
365+
return;
366366
}
367367

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){
368423
FnObject cam;
369424
cam.Object(this->camera);
370425
float cam_pos[3];
@@ -383,11 +438,11 @@ void GameControl::CamUpdate(){
383438
cam.SetWorldDirection(tempFDir,tempUDir);
384439
cam.GetWorldPosition(cam_pos);
385440

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+
388443
if (dis > 129600) {
389444
// move forward
390-
cam.MoveForward(MOVE_LENGTH,FALSE, FALSE, 0.0, FALSE);
445+
cam.MoveForward(MOVE_LENGTH * skip,FALSE, FALSE, 0.0, FALSE);
391446
BOOL flag;
392447
if (cam_pos[2] - MOVE_LENGTH / 1.2 > CAM_MIN_HIGHT){
393448
flag = cam.PutOnTerrain(tID,FALSE, cam_pos[2] - MOVE_LENGTH / 1.2);
@@ -401,7 +456,11 @@ void GameControl::CamUpdate(){
401456
}
402457
firstBlock = TRUE;
403458
}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);
405464
BOOL flag;
406465
if (ret == 0){
407466
flag = cam.PutOnTerrain(tID,FALSE, CAM_MIN_HIGHT);
@@ -410,7 +469,7 @@ void GameControl::CamUpdate(){
410469
cam.MoveForward(-0.1, FALSE, FALSE, 0.0, TRUE); //prevent the actor be under the camera, or it can't go out there
411470
firstBlock = FALSE;
412471
}
413-
//sprintf(debug, "%s Camera is blocked\n", debug);
472+
sprintf(debug, "%s Camera is blocked\n", debug);
414473
float pos[3];
415474
cam.GetWorldPosition(pos);
416475
if (pos[2] > CAM_MAX_HIGHT) {
@@ -427,10 +486,4 @@ void GameControl::CamUpdate(){
427486
sprintf(debug, "%s backoff put on fail\n", debug);
428487
}
429488
}
430-
}
431-
432-
void GameControl::InitCamTargetPos(float pos[3]){
433-
for (int i = 0;i<3;i++){
434-
this->cameraTargetPos[i] = pos[i];
435-
}
436489
}

GameControl.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ class GameControl
4141
void InitCamTargetPos(float pos[3]);
4242
BOOL AppendAttackCode(ATTACK_CODE code);
4343
void PlayAction(int skip);
44+
void ResetCamView();
45+
protected:
46+
void CamMove(float skip);
4447
private:
4548
int dir_normalize(float pos[3]);
4649
BOOL CamInTop;

Main.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,8 @@ void KeyboardAttackCommand(WORLDid gID, BYTE code, BOOL value){
372372
kc->AppendAttackCode(HEAVY_ATT);
373373
}else if(code == FY_L && FyCheckHotKeyStatus(FY_L) == TRUE){
374374
kc->AppendAttackCode(ULTIMATE_ATT);
375+
}else if (code == FY_N && FyCheckHotKeyStatus(FY_N) == TRUE){
376+
kc->ResetCamView();
375377
}
376378
}
377379

@@ -429,6 +431,7 @@ BOOL BlindKeys(){
429431
FyDefineHotKey(FY_J, KeyboardAttackCommand, FALSE);
430432
FyDefineHotKey(FY_K, KeyboardAttackCommand, FALSE);
431433
FyDefineHotKey(FY_L, KeyboardAttackCommand, FALSE);
434+
FyDefineHotKey(FY_N, KeyboardAttackCommand, FALSE);
432435
return TRUE;
433436
}
434437

0 commit comments

Comments
 (0)