void WASDCameraController::UpdateAngels(Camera * camera)
{
	if(NULL != camera)
	{
		Vector3 dir = camera->GetDirection();

		Vector2 dirXY(dir.x, dir.y);
		dirXY.Normalize();
		viewZAngle = -(RadToDeg(dirXY.Angle()) - 90.0);

		Vector3 dirXY0(dir.x, dir.y, 0.0f);
		dirXY0.Normalize();

		float32 cosA = dirXY0.DotProduct(dir);
		viewYAngle = RadToDeg(acos(cosA));

		if(viewYAngle > MAX_ANGLE)
			viewYAngle -= 360;

		if(viewYAngle < -MAX_ANGLE)
			viewYAngle += 360;
	}
	else
	{
		viewYAngle = 0;
		viewZAngle = 0;
	}
}
Пример #2
0
//
// Update the position of the moon image in the sky
//
void CMoonImage::Reposition (sgVec3 p, double theta, double lst, double lat,
               double ra, double dec, double spin)
{
  sgMat4 LST, LAT, RA, DEC, D, SCALE, ECLIPTIC, SPIN;
  sgVec3 axis;
  sgVec3 v;

  // Create scaling matrix for moon illusion (appears larger near horizon)
  float scale = 1.0f;
  sgMakeIdentMat4 (SCALE);
  float maxMagnification = 0.5f;
  float minThreshold = DegToRad (80.0f);
  float maxThreshold = DegToRad (95.0f);
  float span = maxThreshold - minThreshold;
  if ((theta >= minThreshold) && (theta <= maxThreshold)) {
    sgMat4 I;
    sgMakeIdentMat4 (I);
    scale = 1.0f + (maxMagnification * (theta - minThreshold) / span);
    sgScaleMat4 (SCALE, I, scale);
  }

  // Rotation matrix for latitude
  sgSetVec3 (axis, -1.0f, 0, 0);
  sgMakeRotMat4 (LAT, 90.0f-(float)lat, axis);

  // Rotation matrix for local sidereal time, converted from h to deg
  sgSetVec3 (axis, 0, 0, -1.0f);
  sgMakeRotMat4 (LST, ((float)lst * 15), axis);

  // Rotation matrix for right ascension
  sgSetVec3 (axis, 0, 0, 1);
  sgMakeRotMat4 (RA, RadToDeg ((float)ra), axis);

  // Rotation matrix for declination
  sgSetVec3 (axis, 1, 0, 0);
  sgMakeRotMat4 (DEC, 90.0f - RadToDeg ((float)dec), axis);

  // Translate moon distance
  sgSetVec3 (v, 0, 0, distance);
  sgMakeTransMat4 (D, v);

  // Rotate to align moon equator with ecliptic
  sgSetVec3 (axis, 1.0f, 0, 0);
  sgMakeRotMat4 (ECLIPTIC, 90.0f, axis);

  /// Rotate the moon image accurately towards the sun position
  sgSetVec3 (axis, 0, 0, 1);
  sgMakeRotMat4 (SPIN, spin, axis);

  // Combine all transforms
  sgMakeIdentMat4 (T);
  sgPreMultMat4 (T, LAT);
  sgPreMultMat4 (T, LST);
  sgPreMultMat4 (T, RA);
  sgPreMultMat4 (T, DEC);
  sgPreMultMat4 (T, D);
  sgPreMultMat4 (T, ECLIPTIC);
  sgPreMultMat4 (T, SPIN);

}
Пример #3
0
/****************************************************************************
* wtan_Graph_Arc
*/
void wtan_Graph_Arc( double center_x, double center_y, double radius,
                 double startangle, double deltaangle, double width )
{
   int sa,da;

   if (deltaangle < 0)
   {
      sa = round(RadToDeg(startangle) + RadToDeg(deltaangle));
      da = -round(RadToDeg(deltaangle));
   }
   else
   {
      sa = round(RadToDeg(startangle));
      da = round(RadToDeg(deltaangle));
   }
   if (abs(da) < 1)  da = 1;  // min 1
   if (sa >= 360)  sa = sa - 360;
   if (sa < 0)     sa = sa + 360;       

   if (da > 360)   da = da - 360;
   if (da < 0)     da = da + 360;

   fprintf(OFP,"ARC %ld %d %d %ld %d %ld %ld 0 0 0\n", cnv_tan(radius),sa,da,
      cnv_tan_width(width),cur_layer,cnv_tan(center_x),cnv_tan(center_y));
}
Пример #4
0
inline Vector3 QuaternionGetEulerAnglesInDegrees(const Quaternion &quat)
{
	const Vector3 inRads(QuaternionGetEulerAnglesInRadians(quat));

	const Vector3 inDegs = {RadToDeg(inRads.x), RadToDeg(inRads.y), RadToDeg(inRads.z)};
	return inDegs;
}
Пример #5
0
//---------------------------------------------------------------------------
void
GrProjection::RecomputeMatrix() const
{
	assert( m_bDirty );

	if ( IsOrtho() )
	{
		// orthographic.
		_glhOrthof2( (PxF32*)m.cProjMat.GetData(), m_fLeft, m_fRight, m_fBottom, m_fTop, m_fZNear, m_fZFar );
	}
	else
	{
		// TODO: incorporate left/right/bottom/top to perform offcenter projection!
		assert( (m_fLeft == -1.0F) && (m_fRight == 1.0F) && (m_fBottom == -1.0F) && (m_fTop == 1.0F) );

		if ( m_fZFar == 0.0F )
		{
			// infinite perspective projection matrix.
			_glhPerspectiveInfiniteFarPlanef2( (PxF32*)m.cProjMat.GetData(), RadToDeg(m_fFovY), m_fAspect, m_fZNear );
		}
		else
		{
			// regular perspective projection matrix.
			_glhPerspectivef2( (PxF32*)m.cProjMat.GetData(), RadToDeg(m_fFovY), m_fAspect, m_fZNear, m_fZFar );
		}
	}
}
Пример #6
0
  bool Si_Analyzer::ProcessFill(){
    Double32_t Prot_E_Arb(0) ;
    
    if(si_.size()>1){
      Prot_E_Arb= si_[0].front.E() + si_[1].front.E();
      h_ringsA_v_ringsB->Fill(si_[0].front.Ch(),si_[1].front.Ch());
      h_segmentsA_v_segmentsB->Fill(si_[0].back.Ch(),si_[1].back.Ch());
      hThetaA_vThetaB->Fill(si_array.Theta_A()*RadToDeg(),si_array.Theta_B()*RadToDeg());
      hPhiA_vPhiB->Fill(si_array.Phi_A()*RadToDeg(),si_array.Phi_B()*RadToDeg());
      hpede->Fill(si_array.E_AB(),si_array.E_A());
      hpede_arb_front->Fill(si_[0].front.E()+si_[1].front.E(),si_[0].front.E());
      hpede_arb_back->Fill(si_[0].back.E()+si_[1].back.E(),si_[0].back.E());
      hpede_arb->Fill(si_[0].front.E()+si_[1].back.E(),si_[0].front.E());
      hpede_cluster->Fill(si_array.E_AB(),si_array.E_A());
      hpede_arb_cluster->Fill(si_array.E_AB(),si_array.E_A());
    }
    

    for(unsigned int i=0;i<si_.size();i++){
      h_si_back_a[i]->Fill(si_[i].back.E());
      h_si_back[i]->Fill(si_[i].Back_E());
      h_si_front_a[i]->Fill(si_[i].front.E());
      h_si_front[i]->Fill(si_[i].Front_E());
      h_si_cluster_e[i]->Fill(si_cluster_[i].ERaw());
      
      h_si_fmult[i]->Fill(si_[i].front.Mult());
      h_si_bmult[i]->Fill(si_[i].back.Mult());
      h_si_cluster_mult[i]->Fill(si_cluster_[i].Mult());
      h_chlistf[i]->Fill(si_[i].front.Ch());
      h_chlistb[i]->Fill(si_[i].back.Ch());
      h_chlist_cluster_ring[i]->Fill(si_cluster_[i].ChRaw(0));
      h_chlist_cluster_segment[i]->Fill(si_cluster_[i].fChlist_b[0]);
      h_ch_f0vf1[i]->Fill(si_[i].front.Ch(0),si_[i].front.Ch(1));
      h_e_f0vf1[i]->Fill(si_[i].Front_E(0),si_[i].Front_E(1));
      
      int idx=(int)si_[i].front.ChRaw(0);
      if(idx>=0){
	front[i][idx]->Fill(si_[i].back.ChRaw(0),(si_[i].Back_E(0)/si_[i].Front_E(0))); 
      }
      h_theta[i]->Fill(si_cluster_[i].Theta()*180/TMath::Pi());
      h_evtheta_arb[i]->Fill(si_[i].front.Ch(),Prot_E_Arb);
      h_evtheta[i]->Fill(si_cluster_[i].Theta()*180/TMath::Pi(),si_array.E_AB());
      h_si_x_y[i]->Fill(si_cluster_[i].fPos[0].X(),si_cluster_[i].fPos[0].Y());
      h_t[i]->Fill(si_[i].Back_T());
      hsi_EvT[i]->Fill(si_[i].back.T(),si_[i].back.E());    
      rfvt_si[i]->Fill(rftime.TRaw(),si_[i].Back_T(0));
      rfvtrel_si[i]->Fill(rftime.TRaw(),si_[i].Back_T(0)); 
      
     if(protcheck){
	h_evtheta_protgated[i]->Fill(si_cluster_[i].Theta()*180/TMath::Pi(),si_array.E_AB());
	h_si_x_y_prot[i]->Fill(si_cluster_[i].fPos[0].X(),si_cluster_[i].fPos[0].Y());
	rfvt_prot_si_[i]->Fill(rftime.TRaw(),si_[i].Back_T(0));
	rfvtrel_prot_si[i]->Fill(rftime.TRaw(),rftime.TRaw() - si_[i].Back_T(0));
     }
    }
    
    return 1;
    
  }
Пример #7
0
void Robot::ConvertVecToRotation(Vec & coord, BODYPART part)
{
  joint j;
  j.look(coord);
  coord.x = RadToDeg(j.pitch) / 360 * 255;
  coord.y = RadToDeg(j.roll) / 360 * 255;
  coord.z = RadToDeg(j.yaw) / 360 * 255;
}
Пример #8
0
/*!
* \fn double ShootStatus::getAngle(double xa,double ya,double xb, double yb)
* \brief Calcul de l'angle d'une droite dont les points sont en parametres
* \param xa,ya point A
* \param xn,yb point B
* \return double l'angle en degres de la droite (AB)
*/
double getAngle(double xa,double ya,double xb, double yb) {
    if (xa==xb) {
        if (yb<ya) return 90;
        else return 270;
    }
    else {
        if (xb>=xa && yb>=ya) return 360-RadToDeg(atan ( (yb-ya) / (xb-xa) ));
        if (xb>=xa && yb<ya) return -RadToDeg(atan ( (yb-ya) / (xb-xa) ));
        if (xb<xa && yb>=ya) return 180 - RadToDeg(atan ( (yb-ya) / (xb-xa) ));
        if (xb<xa && yb<ya) return 180 - RadToDeg(atan ( (yb-ya) / (xb-xa) ));
    }
    return 0;
}
Пример #9
0
void AIFly::Update()
{
  Assert(m_npc);
  Assert(m_target);

  m_npc->SetAnim("fly"); // why not just in OnActivated?? TODO

  // Accelerate towards point above player's head
  Vec3f a = (m_target->GetPos() + Vec3f(0, 50.0f, 0)) - m_npc->GetPos();
  a.Normalise();
  a *= 50.0f; // TODO CONFIG
  m_npc->SetAcc(a);

  // Cap speed 
  a = m_npc->GetVel();
  float speedSq = a.SqLen();
  const float MAX_SPEED = 50.0f; // TODO CONFIG
  if (speedSq > MAX_SPEED * MAX_SPEED)
  {
    a.Normalise();
    a *= MAX_SPEED;
    m_npc->SetVel(a);
  }

  float degs = RadToDeg(atan2(a.x, a.z));
  m_npc->SetDir(degs);
}
Пример #10
0
void wtan_Graph_Text( char *text, double x, double y,
      double height, double width, double angle, int mirror )
{
   int   rot = round(RadToDeg(angle) / 90);
   double   x1,y1,x2,y2;

   if (strlen(text) == 0)  return;

   x1 = 0.0;y1 = 0.0;
   Rotate(height,strlen(text)*height*6.0/8.0,90.0*rot,&x2,&y2);
   sort_box(&x1,&y1,&x2,&y2);

   if (mirror) rot +=4;

   fprintf(OFP,"TEXT \"");

   for (unsigned int i=0;i<strlen(text);i++)
   {
      if (text[i] == '"')  fprintf(OFP,"\\");
      fprintf(OFP,"%c",text[i]);
   }

   fprintf(OFP,"\" %ld %d 10 %d %ld %ld %ld %ld %ld %ld 0 0\n",
      cnv_tan(height), rot, cur_layer,cnv_tan(x), cnv_tan(y),
      cnv_tan(x1+x), cnv_tan(y1+y), cnv_tan(x2+x), cnv_tan(y2+y) );
}
Пример #11
0
void Ve1ObjectChar::MoveTo(const Vec3f& newpos)
{
  m_newPos = newpos;
  m_isMoving = true;

  Vec3f dir = GetPos() - newpos;
  float sqLen = dir.SqLen();
  // TODO Check if distance is greater than last time - if so, we have missed the target!

  static const float STOP_DIST = ROConfig()->GetFloat("stop-dist", 10.0f);
  if (sqLen < STOP_DIST)
  {
    SetVel(Vec3f(0, 0, 0));
    m_isMoving = false; // Not sure why this wasn't here
  }
  // TODO enable this when we are reliably resetting sqLenLastTime, otherwise sometimes characters won't move
  /*
  else if (sqLen > sqLenLastTime)
  {
    SetVel(Vec3f(0, 0, 0));
    m_isMoving = false; // Not sure why this wasn't here
  }
  */
  else
  {
    dir.Normalise();
    SetVel(-dir * SPEED);

    // Work out direction to face
    SetDir(RadToDeg(atan2((double)m_vel.x, (double)m_vel.z)));
  }
  sqLenLastTime = sqLen;
}
Пример #12
0
float AngleBetween(const vec3 &a, const vec3 &b)
{
    float dotProd = a.dotProduct(b);
    float cosine = dotProd / (a.length() * b.length());

    return RadToDeg(acos(cosine));
}
Пример #13
0
    /// btMotionState override. Called when Bullet wants to tell us the body's current transform
    void setWorldTransform(const btTransform &worldTrans)
    {
        /// \todo For a large scene, applying the changed transforms of rigid bodies is slow (slower than the physics simulation itself,
        /// or handling collisions) due to the large number of signals being fired.
    
        // Cannot modify server-authoritative physics object, rather get the transform changes through placeable attributes
        const bool hasAuthority = rigidBody->HasAuthority();
        if (!hasAuthority && !clientExtrapolating)
            return;
    
        if (placeable.Expired())
            return;
        Placeable* p = placeable;
        // Important: disconnect our own response to attribute changes to not create an endless loop!
        disconnected = true;
    
        AttributeChange::Type changeType = hasAuthority ? AttributeChange::Default : AttributeChange::LocalOnly;

        // Set transform
        float3 position = worldTrans.getOrigin();
        Quat orientation = worldTrans.getRotation();
    
        // Non-parented case
        if (p->parentRef.Get().IsEmpty())
        {
            Transform newTrans = p->transform.Get();
            newTrans.SetPos(position.x, position.y, position.z);
            newTrans.SetOrientation(orientation);
            p->transform.Set(newTrans, changeType);
        }
        else
        // The placeable has a parent itself
        {
            Urho3D::Node* parent = p->UrhoSceneNode()->GetParent();
            if (parent)
            {
                position = parent->WorldToLocal(position);
                orientation = parent->GetWorldRotation().Inverse() * orientation;
                Transform newTrans = p->transform.Get();
                newTrans.SetPos(position);
                newTrans.SetOrientation(orientation);
                p->transform.Set(newTrans, changeType);
            }
        }
        // Set linear & angular velocity
        if (body)
        {
            // Performance optimization: because applying each attribute causes signals to be fired, which is slow in a large scene
            // (and furthermore, on a server, causes each connection's sync state to be accessed), do not set the linear/angular
            // velocities if they haven't changed
            float3 linearVel = body->getLinearVelocity();
            float3 angularVel = RadToDeg(body->getAngularVelocity());
            if (!linearVel.Equals(rigidBody->linearVelocity.Get()))
                rigidBody->linearVelocity.Set(linearVel, changeType);
            if (!angularVel.Equals(rigidBody->angularVelocity.Get()))
                rigidBody->angularVelocity.Set(angularVel, changeType);
        }
    
        disconnected = false;
    }
Пример #14
0
float3 RigidBody::GetAngularVelocity()
{
    if (impl->body)
        return RadToDeg(impl->body->getAngularVelocity());
    else
        return angularVelocity.Get();
}
Пример #15
0
// ============================================================================
void AngleControl::SetPoint(int x, int y, BOOL bNegative/*=FALSE*/)
{
   float rad = m_diameter * 0.5f;

   Point2 point;
   point.x = x - rad;
   point.y = y - rad;
   point = Normalize(point);
   if (!m_dirCCW) point.y = -point.y;

   float m_newDegrees;
   m_newDegrees = RadToDeg(acos(point.x));
   if (point.y > 0.f) m_newDegrees = 360.f-m_newDegrees;

   m_newDegrees -= m_startDegrees;
   if (m_newDegrees < 0.f) m_newDegrees += 360.f;

   if (m_min >= 0.f && m_max >= 0.f) bNegative=FALSE;
   if (m_min <= 0.f && m_max <= 0.f) bNegative=TRUE;
   if(bNegative) m_newDegrees -= 360.f;

   BOOL newVal = FALSE;
   if (m_newDegrees >= m_min && m_newDegrees <= m_max)
   {  newVal = TRUE;
   }
   else // if (m_degrees != m_min && m_degrees != m_max)
   {  // figure out if m_degrees should be m_min, m_max, or 0
      float lo_min=m_min;
      float lo_max=m_max;
      if (!bNegative && lo_min < 0.0f && lo_max > 0.0f) lo_min=0.0f;
      else if (bNegative && lo_min < 0.0f && lo_max > 0.0f) lo_max=0.0f;
      Point2 pnt_min;
      pnt_min.x = rad + cos(DegToRad(lo_min+m_startDegrees))*rad;
      pnt_min.y = sin(DegToRad(lo_min+m_startDegrees))*rad;
      if (m_dirCCW)
         pnt_min.y = rad - pnt_min.y;
      else
         pnt_min.y += rad;
      Point2 pnt_max;
      pnt_max.x = rad + cos(DegToRad(lo_max+m_startDegrees))*rad;
      pnt_max.y = sin(DegToRad(lo_max+m_startDegrees))*rad;
      if (m_dirCCW)
         pnt_max.y = rad - pnt_max.y;
      else
         pnt_max.y += rad;
      Point2 origPoint = Point2((float)x,(float)y);
      if (Length(origPoint-pnt_min) < Length(origPoint-pnt_max))
         m_newDegrees=lo_min;
      else
         m_newDegrees=lo_max;
      newVal = TRUE;
   }

   if (newVal && m_newDegrees != m_degrees)
   {  m_degrees = m_newDegrees;
      CallChangedHandler();
      SendMessage(m_hToolTip, TTM_UPDATETIPTEXT, 0, (LPARAM)GetToolInfo());
      Invalidate();
   }
}
Пример #16
0
/*
 S = C*cos(y)/2^(z+8)
 z = log2(C * cos(y) / S) - 8
*/
double View::currentMapZoom(const WhirlyKit::Point2f &frameSize,double latitude)
{
  double mapWidthInMeters = (2 * heightAboveSurface() *  tan(fieldOfView/2.0) * EarthRadius);
  double metersPerPizel = mapWidthInMeters/frameSize.x();
  double zoom = log(EarthRadius * RadToDeg(cos(latitude))/ metersPerPizel)/log(2.0) - 8;
  
  return zoom;
}
Пример #17
0
//---------------------------------------------------------------------
//	Edit values 
//---------------------------------------------------------------------
void CFuiCamControl::EditValues()
{	char edt[128];
	float a1 = cam->GetAzimuth();
	float e1 = cam->GetElevation();
	sprintf(edt," %.0f %.0f",RadToDeg(a1),RadToDeg(e1));
	lrot->SetText(edt);

	//----Range ---------------------------------------
	float rg = cam->GetRange();
	sprintf(edt," %.0fft",rg);
	lrng->SetText(edt);

	//----Field of view -------------------------------
	float zm = cam->GetFOV();
	sprintf(edt," %.0fd",zm);
	lzom->SetText(edt);
	return;
}
Пример #18
0
std::string MUST_USE_RESULT Quat::ToString2() const
{
	float3 axis;
	float angle;
	ToAxisAngle(axis, angle);
	char str[256];
	sprintf(str, "Quat(axis:(%.2f,%.2f,%.2f) angle:%2.f)", axis.x, axis.y, axis.z, RadToDeg(angle));
	return str;
}
Пример #19
0
// Mouse controls
void VoxGame::MouseCameraRotate()
{
	int x = m_pVoxWindow->GetCursorX();
	int y = m_pVoxWindow->GetCursorY();

	float changeX;
	float changeY;

	// The mouse hasn't moved so just return
	if ((m_currentX == x) && (m_currentY == y))
	{
		return;
	}

	// Calculate and scale down the change in position
	changeX = (x - m_currentX) / 5.0f;
	changeY = (y - m_currentY) / 5.0f;

	// Upside down
	if (m_pGameCamera->GetUp().y < 0.0f)
	{
		changeX = -changeX;
	}
	
	// First person mode
	if (m_cameraMode == CameraMode_FirstPerson)
	{
		changeY = -changeY;
	}

	// Limit the rotation, so we can't go 'over' or 'under' the player with out rotations
	vec3 cameraFacing = m_pGameCamera->GetFacing();
	float dotResult = acos(dot(cameraFacing, vec3(0.0f, 1.0f, 0.0f)));
	float rotationDegrees = RadToDeg(dotResult) - 90.0f;
	float limitAngle = 75.0f;
	if ((rotationDegrees > limitAngle && changeY < 0.0f) || (rotationDegrees < -limitAngle && changeY > 0.0f))
	{
		changeY = 0.0f;
	}

	if (m_cameraMode == CameraMode_FirstPerson)
	{
		m_pGameCamera->Rotate(changeY*0.75f, 0.0f, 0.0f);
		m_pGameCamera->RotateY(-changeX*0.75f);
	}
	else
	{
		m_pGameCamera->RotateAroundPoint(changeY*0.75f, 0.0f, 0.0f, true);
		m_pGameCamera->RotateAroundPointY(-changeX*0.75f, true);
	}

	m_currentX = x;
	m_currentY = y;
}
Пример #20
0
    /*
    * UTMXYToLatLon
    *
    * Converts x and y coordinates in the Universal Transverse Mercator
    * projection to a latitude/longitude pair.
    *
    * Inputs:
    *	x - The easting of the point, in meters.
    *	y - The northing of the point, in meters.
    *	zone - The UTM zone in which the point lies.
    *	southhemi - True if the point is in the southern hemisphere;
    *               false otherwise.
    *
    * Outputs:
    *	latlon - A 2-element array containing the latitude and
    *            longitude of the point, in radians.
    *
    * Returns:
    *	The function does not return a value.
    *
    */
    void UTMXYToLatLon (double x,double y,double zone,int southhemi,double &lat, double &lon)
    {
        double cmeridian;
        	
        x -= 500000.0;
        x /= UTMScaleFactor;
        	
        /* If in southern hemisphere, adjust y accordingly. */
        if (southhemi)
        y -= 10000000.0;
        		
        y /= UTMScaleFactor;
        
        cmeridian = UTMCentralMeridian (zone);
        MapXYToLatLon (x, y, cmeridian, lat,lon);
 		lat=RadToDeg(lat);
		lon=RadToDeg(lon);
       	
        return;
    }
Пример #21
0
float GetAngle(V3 v, V3 v2)
{
	float dot;

	//VectorNormalize(&v);
	//VectorNormalize(&v2);

    dot = Dot(v, v2);
    dot = dot / (VectorLength(v) * VectorLength(v2));

    return RadToDeg( acosf(dot) );
}
Пример #22
0
    /*
    * LatLonToUTMXY
    *
    * Converts a latitude/longitude pair to x and y coordinates in the
    * Universal Transverse Mercator projection.
    *
    * Inputs:
    *   lat - Latitude of the point, in radians.
    *   lon - Longitude of the point, in radians.
    *   zone - UTM zone to be used for calculating values for x and y.
    *          If zone is less than 1 or greater than 60, the routine
    *          will determine the appropriate zone from the value of lon.
    *
    * Outputs:
    *   xy - A 2-element array where the UTM x and y values will be stored.
    *
    * Returns:
    *   The UTM zone used for calculating the values of x and y.
    *
    */
    double LatLonToUTMXY (double lat,double lon,double &zone,double &x,double &y)
    {
	    zone = floor ((RadToDeg(lon) + 180.0) / 6) + 1;
        MapLatLonToXY (lat, lon, UTMCentralMeridian (zone), x,y);

        /* Adjust easting and northing for UTM system. */
        x = x * UTMScaleFactor + 500000.0;
        y = y * UTMScaleFactor;
        if (y < 0.0)
            y = y + 10000000.0;

        return zone;
    }
Пример #23
0
void VoxGame::JoystickCameraRotate(float dt)
{
	float axisX = m_pVoxWindow->GetJoystickAxisValue(0, 4);
	float axisY = m_pVoxWindow->GetJoystickAxisValue(0, 3);

	// Dead zones
	if (fabs(axisX) < m_pVoxWindow->GetJoystickAnalogDeadZone())
	{
		axisX = 0.0f;
	}
	if (fabs(axisY) < m_pVoxWindow->GetJoystickAnalogDeadZone())
	{
		axisY = 0.0f;
	}

	float changeX = axisX * 150.0f * dt;
	float changeY = axisY * 150.0f * dt;

	// Upside down
	if (m_pGameCamera->GetUp().y < 0.0f)
	{
		changeX = -changeX;
	}

	// First person mode
	if (m_cameraMode == CameraMode_FirstPerson)
	{
		changeY = -changeY;
	}

	// Limit the rotation, so we can't go 'over' or 'under' the player with out rotations
	vec3 cameraFacing = m_pGameCamera->GetFacing();
	float dotResult = acos(dot(cameraFacing, vec3(0.0f, 1.0f, 0.0f)));
	float rotationDegrees = RadToDeg(dotResult) - 90.0f;
	float limitAngle = 75.0f;
	if ((rotationDegrees > limitAngle && changeY < 0.0f) || (rotationDegrees < -limitAngle && changeY > 0.0f))
	{
		changeY = 0.0f;
	}

	if (m_cameraMode == CameraMode_FirstPerson)
	{
		m_pGameCamera->Rotate(changeY, 0.0f, 0.0f);
		m_pGameCamera->RotateY(-changeX);
	}
	else
	{
		m_pGameCamera->RotateAroundPoint(changeY, 0.0f, 0.0f, true);
		m_pGameCamera->RotateAroundPointY(-changeX, true);
	}
}
Пример #24
0
void TAnimContainer::UpdateModelIK()
{ // odwrotna kinematyka wyliczana dopiero po ustawieniu macierzy w submodelach
    if (pSubModel) // pozby� si� tego - sprawdza� wcze�niej
    {
        if (pSubModel->b_Anim & at_IK)
        { // odwrotna kinematyka
            float3 d, k;
            TSubModel *ch = pSubModel->ChildGet();
            switch (pSubModel->b_Anim)
            {
            case at_IK11: // stopa: ustawi� w kierunku czubka (pierwszy potomny)
                d = ch->Translation1Get(); // wektor wzgl�dem aktualnego uk�adu (nie uwzgl�dnia
                // obrotu)
                k = float3(RadToDeg(atan2(d.z, hypot(d.x, d.y))), 0.0,
                           -RadToDeg(atan2(d.y, d.x))); // proste skierowanie na punkt
                pSubModel->SetRotateIK1(k);
                // if (!strcmp(pSubModel->pName,"?Z?�?^?[")) //jak g��wna ko��
                // WriteLog("--> "+AnsiString(k.x)+" "+AnsiString(k.y)+" "+AnsiString(k.z));
                // Ra: to ju� jest dobrze, mo�e by� inna �wiartka i znak
                break;
            case at_IK22: // udo: ustawi� w kierunku pierwszej potomnej pierwszej potomnej (kostki)
                // pozycj� kostki nale�y okre�li� wzgl�dem ko�ci centralnej (+biodro mo�e by�
                // pochylone)
                // potem wyliczy� ewentualne odchylenie w tej i nast�pnej
                // w sumie to proste, jak wyznaczenie k�t�w w tr�jk�cie o znanej d�ugo�ci bok�w...
                d = ch->Translation2Get(); // wektor wzgl�dem aktualnego uk�adu (nie uwzgl�dnia
                // obrotu)
                // if ()
                { // ko�� IK jest dalej ni� pozycja spoczynkowa
                    k = float3(RadToDeg(atan2(d.z, hypot(d.x, d.y))), 0.0,
                               -RadToDeg(atan2(d.y, d.x))); // proste skierowanie na punkt
                    pSubModel->SetRotateIK1(k);
                }
                break;
            }
        }
    }
}
Пример #25
0
void Drawable::draw()
{
	glPushMatrix();
		glTranslated(Pos.x, Pos.y, 0); // translate to Drawable's location
		glPushMatrix();
			//Draw the scaled object
			glScaled(Scale.x, Scale.y, 1.0f);
			glRotated(RadToDeg(Rot), 0, 0, 1);
			draw2();
		glPopMatrix();
		//Draw all the children
		for (std::list<Drawable*>::iterator dPtr = Children.begin();dPtr != Children.end(); ++dPtr) {
			(*dPtr)->draw();
		}
	glPopMatrix();
}
Пример #26
0
/* angle between vectors - rad version */
static inline D3DVALUE AngleBetweenVectorsRad (const D3DVECTOR *a, const D3DVECTOR *b)
{
	D3DVALUE la, lb, product, angle, cos;
	/* definition of scalar product: a*b = |a|*|b|*cos... therefore: */
	product = ScalarProduct (a,b);
	la = VectorMagnitude (a);
	lb = VectorMagnitude (b);
	if (!la || !lb)
		return 0;

	cos = product/(la*lb);
	angle = acos(cos);
	TRACE("angle between (%f,%f,%f) and (%f,%f,%f) = %f radians (%f degrees)\n",  a->x, a->y, a->z, b->x,
	      b->y, b->z, angle, RadToDeg(angle));
	return angle;	
}
Пример #27
0
void SetUpCameraSymmetric(Eye eye, const Camera& camera)
{
    const int windowwidth = Screen::X();
    const int windowheight = Screen::Y();

    float aspectratio = (float)windowwidth / (float)windowheight / 2.0f;
    // Dividing by 2 for side-by-side stereo

    Vec3f cameraright = CrossProduct(camera.m_dir, camera.m_up);  // Each unit vectors
    cameraright *= camera.m_eyeSep / 2.0f;

    AmjuGL::SetMatrixMode(AmjuGL::AMJU_PROJECTION_MATRIX);
    AmjuGL::SetIdentity();
    AmjuGL::SetPerspectiveProjection(RadToDeg(camera.m_fovy), aspectratio,
                                     camera.m_neardist, camera.m_fardist);

    SetViewport(eye, camera.m_vpXOffset * windowwidth, camera.m_vpYOffset * windowheight);

    if (eye == LEFT)
    {
        AmjuGL::SetMatrixMode(AmjuGL::AMJU_MODELVIEW_MATRIX);
        AmjuGL::SetIdentity();
        AmjuGL::LookAt(
            camera.m_pos.x - cameraright.x,
            camera.m_pos.y - cameraright.y,
            camera.m_pos.z - cameraright.z,
            camera.m_pos.x - cameraright.x + camera.m_dir.x,
            camera.m_pos.y - cameraright.y + camera.m_dir.y,
            camera.m_pos.z - cameraright.z + camera.m_dir.z,
            camera.m_up.x, camera.m_up.y, camera.m_up.z);
    }
    else
    {
        AmjuGL::SetMatrixMode(AmjuGL::AMJU_MODELVIEW_MATRIX);
        AmjuGL::SetIdentity();
        AmjuGL::LookAt(
            camera.m_pos.x + cameraright.x,
            camera.m_pos.y + cameraright.y,
            camera.m_pos.z + cameraright.z,
            camera.m_pos.x + cameraright.x + camera.m_dir.x,
            camera.m_pos.y + cameraright.y + camera.m_dir.y,
            camera.m_pos.z + cameraright.z + camera.m_dir.z,
            camera.m_up.x, camera.m_up.y, camera.m_up.z);
    }
}
Пример #28
0
void AIChasePet::Update()
{
  AI::Update();
  Assert(m_npc);
  // Head towards target
  Vec3f aim = m_target->GetPos();
  Vec3f vel = aim - m_npc->GetPos();

  static const float MAX_DIST = ROConfig()->GetFloat("dino-chase-dist"); 
  static const float MAX_DIST_SQ = MAX_DIST * MAX_DIST;

  float sqlen = vel.SqLen();
  if (sqlen < 1.0f)
  {
std::cout << "AI chase: " << Describe(m_npc) << " has reached target " <<
  Describe(m_target) << "!\n";

    m_npc->DecideAI();
  }
  else if (sqlen < MAX_DIST_SQ) 
  {
    vel.Normalise();

    static const float SPEED = ROConfig()->GetFloat("dino-chase-speed"); 
    vel *= SPEED;
    Vec3f v = m_npc->GetVel();
    v.x = vel.x;
    v.z = vel.z;
    m_npc->SetVel(v);
    float degs = RadToDeg(atan2(vel.x, vel.z)); 

    m_npc->SetDir(degs);
    m_npc->SetIsControlled(true); 
    m_npc->SetAnim("run");
  }
  else
  {
#ifdef _DEBUG
    std::cout << m_npc->GetTypeName() << " giving up chase\n";
#endif
    m_npc->SetAI(AIIdle::NAME);
  }
}
Пример #29
0
bool CameraControl::OnCursorEvent(const CursorEvent& ce)
{
  static float oldx = ce.x;
  static float oldy = ce.y;
  float dx = ce.x - oldx;
  float dy = ce.y - oldy;
  oldx = ce.x;
  oldy = ce.y;

  if (!camKey)
  {
    return false; 
  }

  bool b = false;
  if (leftDrag)
  {
    static const float XROT_SCALE = ROConfig()->GetFloat("cam-xrot-scale", 10.0f);
    static const float YROT_SCALE = ROConfig()->GetFloat("cam-yrot-scale", 10.0f);

    yRotUser -= RadToDeg(dx) * YROT_SCALE;
    xRot -= dy * XROT_SCALE;
    b = false; // true means we can't move off a button we have pressed down
  }
  if (rightDrag)
  {
    zDist += dy * 1000.0f; // TODO sensitivity
    b = true;
  }
  if (midDrag)
  {
    float y = DegToRad(yRotAuto + yRotUser); 

    posOffset.x -= dx * cos(y) * 1000.0f;
    posOffset.z += dx * sin(y) * 1000.0f;

    posOffset.y -= dy * 1000.0f;
    b = true;
  }

  return b;
}
Пример #30
0
void BigBird::updatePos()
{
    b2Vec2 pos;
    pos = physicBody->GetPosition();
    setPos(MeterToPix_x(pos.x) , MeterToPix_y(pos.y));

    float angle;
    angle = physicBody->GetAngle();
    setRotation(-RadToDeg(angle));

    if(health<3)
    {
        setPixmap(QPixmap("./GameData/DefaultResources/Images/BirdImages/bigBirdHurt.png"));
    }
    if(health<=0)
    {
        inWorld->DestroyBody (physicBody);
        scene ()->removeItem (this);
        delete this;
        return;
    }
}