view camera.cc @ 122:5219bf3d5e71

title_draw
author e085768
date Mon, 27 Jun 2011 19:44:46 +0900
parents c534f339ee8b
children 6ef3b0efdeaf
line wrap: on
line source

#include <stdlib.h>
#include <string.h>
#include "libps2.h"
#include "ps2util.h"
#include "car.h"
#include "game.h"
#include "controler.h"
#include "camera.h"

//大域変数、各部で共有
extern SGO_PAD pad;

static CAMERA camera, def_camera;


void
camera_init()
{
  
 //カメラの初期位置設定
 def_camera.xyz[0] = 0;
 def_camera.xyz[1] =-7;// -3;
 def_camera.xyz[2] =-14; //0;
 def_camera.xyz[3] = 1;

 def_camera.zd[0] = 0;
 def_camera.zd[1] = 2;
 def_camera.zd[2] = 7;
 def_camera.zd[3] = 1;

 def_camera.yd[0] = 0;
 def_camera.yd[1] = 1;
 def_camera.yd[2] = 0;
 def_camera.yd[3] = 1;

 def_camera.angle[0]=-0.2;//0;  //pich
 def_camera.angle[1]=0;     //yoh 
 def_camera.angle[2]=0;     //roll
 def_camera.angle[3]=0;

 //def_cameraをcameraにコピー
 memcpy( &camera, &def_camera, sizeof(CAMERA));
 set_camera(&def_camera);
  
}

/*
  ps2依存関係から拝借。
  自分が消したのか、元々無いのかは覚えていないけど
  呼ばれているのでとりあえず(空っぽにしておく)。
*/
// set_camera must be called if camera's parameters were moved                  
void set_camera(CAMERA *camera)
{
  //vu0_rot_camera_matrix(world_view, camera->xyz, camera->zd, camera->yd,camera->angle);
}


/**
 * pose: カメラの対象物(obj)の座標行列
 * カメラがobjについていくように(そのような動きに見せるため)
 * カメラの位置ベクトル、視点ベクトルを更新
 */
void
camera_update(Game *game, FMATRIX pose)
{
  FVECTOR location, eyes, vertical, angle;
    
  //int type = game->camera_type;

  ps2_vu0_apply_matrix(location, pose, def_camera.xyz);
  ps2_vu0_apply_matrix(eyes, pose, def_camera.zd);
  ps2_vu0_apply_matrix(vertical, pose, def_camera.yd);

  /**When the car bends, the angle of the camera is changed**/
  if(pad.left>0  && game->jiki->speed !=0){
    if(game->jiki->speed !=0){
      if(def_camera.angle[1]<=0.2){
	def_camera.angle[1]+=0.02;
      }
    }
  }
  else if(pad.right>0 && game->jiki->speed !=0){
    if(game->jiki->speed !=0){
      if(def_camera.angle[1]>=-0.2){
        def_camera.angle[1]-=0.02;
      }
    }
  }
  else {
    if(def_camera.angle[1]<-0.01){
      def_camera.angle[1]+=0.02;
    }
    else if(def_camera.angle[1]>0.01){
      def_camera.angle[1]-=0.02;
    }
  } 
  ps2_vu0_apply_matrix(angle, pose, def_camera.angle);
  ps2_vu0_copy_vector(camera.xyz, location);
  ps2_vu0_copy_vector(camera.zd,  eyes);
  ps2_vu0_copy_vector(camera.yd,  vertical);
  ps2_vu0_copy_vector(camera.angle, angle);
  set_camera(&camera);
    
}