コード例 #1
0
void CScene3D::m_TranslateCamera(float4 dx, float4 dy, float4 dz)
{
  AD_Vect3D x, y, z, sum;
  AD_Vect3D ptmp;
  AD_Matrix pretrans;

  if (!p_CurrentCamera) return;
   mat_get_row(&p_CurrentCamera->p_WorldMatrix, 0, &x);
   mat_get_row(&p_CurrentCamera->p_WorldMatrix, 1, &y);
   mat_get_row(&p_CurrentCamera->p_WorldMatrix, 2, &z);

  vect_auto_scale(&x, dx);
  vect_auto_scale(&y, dy);
  vect_auto_scale(&z, dz);
  vect_add(&x, &y, &sum);
  vect_auto_add(&sum, &z);

  vect_auto_add(&p_CurrentCamera->p_CurrentPosition, &sum);
  vect_auto_add(&p_CurrentCamera->p_CurrentTargetPosition, &sum);

  vect_neg(&p_CurrentCamera->p_CurrentPosition, &ptmp);
  mat_setmatrix_of_pretraslation(&pretrans, &ptmp);
  mat_mul(&p_CurrentCamera->p_CurrentRotationMatrix,
	      &pretrans,
		  &p_CurrentCamera->p_WorldMatrix);
}
コード例 #2
0
ファイル: Camera.cpp プロジェクト: ApocalypseDesign/ad_public
void CCamera::m_Ray (float4 screenX, float4 screenY, int32 space, Ray *out)
{
   // screenX e screenY vanno nel range [-1;1]
   AD_Vect3D cam_x, cam_y, cam_z;
   float4 fx, fy;

   if (!out) return;

   fx=(float4)tan(p_CurrentFov*0.5);
   fy=(float4)tan(p_CurrentFov*0.5);

   if (space==WORLDSPACE_RAY)
   {
      vect_copy(&p_CurrentPosition, &out->base);
      mat_get_row(&p_CurrentRotationMatrix, 0, &cam_x);
      mat_get_row(&p_CurrentRotationMatrix, 1, &cam_y);
      mat_get_row(&p_CurrentRotationMatrix, 2, &cam_z);
      vect_auto_scale(&cam_x, screenX*fx);
      vect_auto_scale(&cam_y, screenY*fy*480.0f/640.0f);
      vect_add(&cam_x, &cam_y, &out->direction);
      vect_auto_add(&out->direction, &cam_z);
      vect_auto_normalize(&out->direction);
   }
   else
   if (space==CAMERASPACE_RAY)
   {
      vect_set(&out->base, 0, 0, 0);
      vect_set(&out->direction, screenX*fx, screenY*fy, 1);
   }
   vect_auto_normalize(&out->direction);
}
コード例 #3
0
void CScene3D::m_RotateCamera(float4 ax, float4 ay, float4 az)
{
  AD_Vect3D cameradir, xAxis, yAxis, zAxis, v;
  AD_Vect3D vx, vy, vz, ptmp;
  AD_Quaternion q1, q2;
  AD_Matrix rot1, rot2, rot12, pretrans;

  if (!p_CurrentCamera) return;

  // estrazione assi locali
  mat_get_row(&p_CurrentCamera->p_CurrentRotationMatrix, 0, &xAxis);
  mat_get_row(&p_CurrentCamera->p_CurrentRotationMatrix, 1, &yAxis);
  mat_get_row(&p_CurrentCamera->p_CurrentRotationMatrix, 2, &zAxis);

  // creazioni delle matrici di rotazione
  quat_set(&q1, xAxis.x, xAxis.y, xAxis.z, ax);
  quat_set(&q2, yAxis.x, yAxis.y, yAxis.z, ay);

  quat_quat_to_rotquat(&q1); quat_rotquat_to_matrix(&q1, &rot1);
  quat_quat_to_rotquat(&q2); quat_rotquat_to_matrix(&q2, &rot2);
  mat_mul(&rot1, &rot2, &rot12);

  // ruoto la posizione
  vect_sub(&p_CurrentCamera->p_CurrentPosition,
           &p_CurrentCamera->p_CurrentTargetPosition,
		   &cameradir);
  mat_mulvect(&rot12, &cameradir, &v);
  vect_add(&v, &p_CurrentCamera->p_CurrentTargetPosition,
		   &p_CurrentCamera->p_CurrentPosition);
  
  // ruoto il target
  /*vect_sub(&p_CurrentCamera->p_CurrentTargetPosition,
           &p_CurrentCamera->p_CurrentPosition,
		   &cameradir);
  mat_mulvect(&rot12, &cameradir, &v);
  vect_add(&v, &p_CurrentCamera->p_CurrentPosition,
		   &p_CurrentCamera->p_CurrentTargetPosition);*/

  mat_mulvect(&rot12, &xAxis, &vx); vect_auto_normalize(&vx);
  mat_mulvect(&rot12, &yAxis, &vy); vect_auto_normalize(&vy);
  mat_mulvect(&rot12, &zAxis, &vz); vect_auto_normalize(&vz);
  mat_insert_row(&p_CurrentCamera->p_CurrentRotationMatrix, 0, &vx);
  mat_insert_row(&p_CurrentCamera->p_CurrentRotationMatrix, 1, &vy);
  mat_insert_row(&p_CurrentCamera->p_CurrentRotationMatrix, 2, &vz);
  vect_neg(&p_CurrentCamera->p_CurrentPosition, &ptmp);
  mat_setmatrix_of_pretraslation(&pretrans, &ptmp);
  mat_mul(&p_CurrentCamera->p_CurrentRotationMatrix,
	      &pretrans,
		  &p_CurrentCamera->p_WorldMatrix);
}
コード例 #4
0
ファイル: ga_math.c プロジェクト: fvdsn/gally
vec_t mat_vmult(const mat_t *a, vec_t b){
	vec_t r;
	int i = 4;
	while(i--){
		V_I(r,i) = vec_wdot(mat_get_row(i,a),b);
	}
	return r;
}
コード例 #5
0
ファイル: WSMobj.cpp プロジェクト: ApocalypseDesign/ad_public
void AD_WindModifier::build_objectmatrix (float4 framepos)
{
   AD_Vect3D postmp, stmp;
   AD_Quaternion objrot;
   AD_Matrix posttrans, scaling, maux;

   accum_scale.x=accum_scale.y=accum_scale.z=1.0f;
   mat_identity(&currentmatrix_rot);

   // estrazione dei dati col keyframer: niente di piu' facile col c++ !!!
   if (rotationtrack.numkey>0)
   {
     rotationtrack.get_data(framepos, &objrot);
     quat_rotquat_to_matrix(&objrot, &currentmatrix_rot);
   }
   mat_copy(&currentmatrix_rot, &currentmatrix);

   if (scaletrack.numkey>0)
   {
     scaletrack.get_data(framepos, &stmp);
     mat_setmatrix_of_scaling(&scaling, stmp.x, stmp.y, stmp.z);
	 accum_scale.x*=stmp.x;
	 accum_scale.y*=stmp.y;
	 accum_scale.z*=stmp.z;
   }
   else mat_identity(&scaling);
   
   if (positiontrack.numkey>0) positiontrack.get_data(framepos, &currentpos);
   mat_setmatrix_of_pretraslation(&posttrans, &currentpos);

   mat_mul(&scaling, &currentmatrix_rot, &maux);
   mat_mul(&posttrans, &maux, &currentmatrix);
 
   if (father!=(AD_Object3D *)NULL)
   {
     mat_mulaffine(&father->currentmatrix_rot, &currentmatrix_rot, &currentmatrix_rot);
	 mat_mul(&father->currentmatrix, &currentmatrix, &currentmatrix);
     mat_mulvect(&father->currentmatrix, &currentpos, &postmp);
	 vect_copy(&postmp, &currentpos);
	 
	 accum_scale.x*=father->accum_scale.x;
	 accum_scale.y*=father->accum_scale.y;
	 accum_scale.z*=father->accum_scale.z;
   }

   mat_transpose(&currentmatrix_rot, &inverse_rotmatrix);
   mat_get_row(&currentmatrix, 1, &forza);
   vect_auto_normalize(&forza);
   vect_scale(&forza, strenght*0.00016f*forceScaleFactor, &forza);
}
コード例 #6
0
ファイル: ga_math.c プロジェクト: fvdsn/gally
mat_t *mat_mult2(const mat_t*a, mat_t*b){
	int i = 4;
	int j = 4;
	mat_t *m = mat_new_zero();
	while(i--){
		j = 4;
		while(j--){
			M_IJ(m,i,j) = vec_wdot(	mat_get_row(i,a),
						mat_get_col(j,b)	);
		}
	}
	mat_cpy(b,m);
	mat_free(m);
	return b;
}
コード例 #7
0
Float palRevoluteLink::GetAngle() const {

	if (m_pParent==NULL) return 0.0f;
	if (m_pChild ==NULL) return 0.0f;

	//palMatrix4x4 a_PAL,b_PAL;
	palMatrix4x4 a,b;
	a=m_pParent->GetLocationMatrix();
	b=m_pChild->GetLocationMatrix();

	palVector3 fac0;
	mat_get_row(&m_frameA,&fac0,0);
	palVector3 refAxis0;
	vec_mat_mul(&refAxis0,&a,&fac0);

	palVector3 fac1;
	mat_get_row(&m_frameA,&fac1,1);
	palVector3 refAxis1;
	vec_mat_mul(&refAxis1,&a,&fac1);

	palVector3 fbc1;
	mat_get_row(&m_frameB,&fbc1,1);
	palVector3 swingAxis;
	vec_mat_mul(&swingAxis,&b,&fbc1);

	Float d0 = vec_dot(&swingAxis,&refAxis0);
	Float d1 = vec_dot(&swingAxis,&refAxis1);
	return std::atan2(d0,d1);
#if 0 //this method does not do +/-, just positive :(
	palVector3 pp,cp;
	m_pParent->GetPosition(pp);
	m_pChild->GetPosition(cp);
//	printf("pp:");
//	printvector(&pp);
//	printf("cp:");
//	printvector(&cp);
	palVector3 linkpos;
	linkpos.x=m_fRelativePosX;
	linkpos.y=m_fRelativePosY;
	linkpos.z=m_fRelativePosZ;
//	printf("lp:");
//	printvector(&linkpos);
	palVector3 newlp;
	vec_mat_mul(&newlp,&a,&linkpos);
	vec_add(&newlp,&newlp,&pp);
//	printf("nlp:");
//	printvector(&newlp);
	palVector3 la,lb;
	vec_sub(&la,&pp,&newlp);
	vec_sub(&lb,&cp,&newlp);
//	la = pp;
//	lb = cp;
	vec_norm(&la);
	vec_norm(&lb);
//	printvector(&la);
//	printvector(&lb);
	Float dot=vec_dot(&la,&lb);
	Float mag=vec_mag(&la)*vec_mag(&lb);
	return Float(acos(dot/mag));
#endif
}