GeographicCoordinate GenerationMath::DestinationPoint( GeographicCoordinate start, Velocity velocity, double current_bearing) { //φ2 = asin( sin φ1 ⋅ cos δ + cos φ1 ⋅ sin δ ⋅ cos θ ) //λ2 = λ1 + atan2( sin θ ⋅ sin δ ⋅ cos φ1, cos δ − sin φ1 ⋅ sin φ2 ) double distance = sqrt(velocity.east * velocity.east + velocity.north * velocity.north); //std::cout << "\ndistance traveled: " << distance << std::endl; double start_lat = ToRadians(start.GetLatitude()); double start_long = ToRadians(start.GetLongitude()); double angular_dist = (distance / EARTH_RAD2); /*std::cout << "lat: (actual)" << start.GetLatitude() << std::endl; std::cout << "start lat: " << start_lat << " start long: " << start_long << std::endl; std::cout << "angular dist: " << angular_dist << std::endl; std::cout << "current bearing: " << ToRadians(current_bearing) << std::endl;*/ double dest_lat = asin( sin(start_lat) * cos(angular_dist) + cos(start_lat) * sin(angular_dist) * cos(ToRadians(current_bearing))); double dest_long = start_long + atan2(sin(ToRadians(current_bearing)) * sin(angular_dist) * cos(start_lat), cos(angular_dist) - sin(start_lat) * sin(dest_lat)); //std::cout << "dest lat (radians): " << dest_lat << std::endl; dest_lat = ToDegrees(dest_lat); dest_long = ToDegrees(dest_long); return GeographicCoordinate (dest_lat, dest_long, start.GetAltitude()-velocity.down); }
CEPuckEntity& CLoopFunctions::AddEPuck(const std::string& str_id, const CVector3& c_position, const CQuaternion& c_orientation, const std::string& str_controller_id, const std::string& str_physics_id) { /* Get the angles in degrees from the quaternion */ CRadians cX, cY, cZ; c_orientation.ToEulerAngles(cZ, cY, cX); CVector3 cOrientationAngles(ToDegrees(cZ).GetValue(), ToDegrees(cY).GetValue(), ToDegrees(cX).GetValue()); /* Build the XML tree */ TConfigurationNode tRootNode("e-puck"); SetNodeAttribute(tRootNode, "id", str_id); SetNodeAttribute(tRootNode, "position", c_position); SetNodeAttribute(tRootNode, "orientation", cOrientationAngles); SetNodeAttribute(tRootNode, "controller", str_controller_id); /* Add the entity to the space */ CEPuckEntity& cEntity = AddEntityToSpace<CEPuckEntity>(tRootNode); /* Add the entity to physics */ AddEntityToPhysics(cEntity, std::vector<std::string>(1, str_physics_id)); /* Assign the controller */ AssignController(cEntity); /* Return the entity */ return cEntity; }
static void Rototranslate(const CVector3& c_position, const CQuaternion& c_orientation) { /* Get Euler angles */ CRadians cZAngle, cYAngle, cXAngle; c_orientation.ToEulerAngles(cZAngle, cYAngle, cXAngle); /* Translate */ glTranslatef(c_position.GetX(), c_position.GetY(), c_position.GetZ()); /* Rotate */ glRotatef(ToDegrees(cXAngle).GetValue(), 1.0f, 0.0f, 0.0f); glRotatef(ToDegrees(cYAngle).GetValue(), 0.0f, 1.0f, 0.0f); glRotatef(ToDegrees(cZAngle).GetValue(), 0.0f, 0.0f, 1.0f); }
CCylinderEntity& CLoopFunctions::AddCylinder(const std::string& str_id, const CVector3& c_position, const CQuaternion& c_orientation, Real f_radius, Real f_height, bool b_movable, Real f_mass, const std::vector<std::string>& str_physics_ids, const std::vector<SAdditionalLED>& vec_additional_leds, bool b_visible) { /* Get the angles in degrees from the quaternion */ CRadians cX, cY, cZ; c_orientation.ToEulerAngles(cZ, cY, cX); CVector3 cOrientationAngles(ToDegrees(cZ).GetValue(), ToDegrees(cY).GetValue(), ToDegrees(cX).GetValue()); /* Build the XML tree */ TConfigurationNode tRootNode("cylinder"); SetNodeAttribute(tRootNode, "id", str_id); SetNodeAttribute(tRootNode, "position", c_position); SetNodeAttribute(tRootNode, "orientation", cOrientationAngles); SetNodeAttribute(tRootNode, "radius", f_radius); SetNodeAttribute(tRootNode, "height", f_height); SetNodeAttribute(tRootNode, "movable", b_movable); SetNodeAttribute(tRootNode, "mass", f_mass); SetNodeAttribute(tRootNode, "visible", b_visible); /* Add LEDs, if any */ if(!vec_additional_leds.empty()) { TConfigurationNode tLEDNode("leds"); for(UInt32 i = 0; i < vec_additional_leds.size(); ++i) { TConfigurationNode tLED("led"); SetNodeAttribute(tLED, "position", vec_additional_leds[i].Position); SetNodeAttribute(tLED, "color", vec_additional_leds[i].Color); AddChildNode(tLEDNode, tLED); } AddChildNode(tRootNode, tLEDNode); } /* Add the entity to the space */ CCylinderEntity& cEntity = AddEntityToSpace<CCylinderEntity>(tRootNode); /* Add the entity to physics */ AddEntityToPhysics(cEntity, str_physics_ids); /* Return the entity */ return cEntity; }
void PicRender( const Pic *p, SDL_Renderer *r, const struct vec2i pos, const color_t mask, const double radians, const struct vec2 scale) { Rect2i dest = Rect2iNew(pos, p->size); // Apply scale to render dest // TODO: render with anchor at centre by default? if (!svec2_is_equal(scale, svec2_one())) { dest.Pos.x -= (mint_t)MROUND((scale.x - 1) * p->size.x / 2); dest.Pos.y -= (mint_t)MROUND((scale.y - 1) * p->size.y / 2); dest.Size.x = (mint_t)MROUND(p->size.x * scale.x); dest.Size.y = (mint_t)MROUND(p->size.y * scale.y); } const double angle = ToDegrees(radians); TextureRender(p->Tex, r, dest, mask, angle); }
double GenerationMath::AbsoluteBearingBetweenTwoCoordinates( GeographicCoordinate coord1, GeographicCoordinate coord2) { /* var y = Math.sin(λ2-λ1) * Math.cos(φ2); var x = Math.cos(φ1)*Math.sin(φ2) - Math.sin(φ1)*Math.cos(φ2)*Math.cos(λ2-λ1); var brng = Math.atan2(y, x).toDegrees(); θ = atan2( sin Δλ ⋅ cos φ2 , cos φ1 ⋅ sin φ2 − sin φ1 ⋅ cos φ2 ⋅ cos Δλ )*/ double lat1 = ToRadians(coord1.GetLatitude()); double lat2 = ToRadians(coord2.GetLatitude()); double long1 = ToRadians(coord1.GetLongitude()); double long2 = ToRadians(coord2.GetLongitude()); double y = sin(long2-long1) * cos(lat2); double x = cos(lat1) * sin(lat2) - sin(lat1) * cos(lat2) * cos(long2 - long1); //return ToDegrees(atan2(y, x)); return fmod(ToDegrees(atan2(y, x)) + 360, 360.0); }
void CalcChebyshevDistanceAndBearing( Vector2i origin, Vector2i target, int *distance, int *bearing) { // short circuit if origin and target same if (origin.x == target.x && origin.y == target.y) { *distance = 0; *bearing = 0; } else { double angle; *distance = CHEBYSHEV_DISTANCE(origin.x, origin.y, target.x, target.y); angle = ToDegrees(atan2(target.y - origin.y, target.x - origin.x)); // convert angle to bearings // first rotate so 0 angle = 0 bearing angle -= 90.0; // then reflect about Y axis angle = 360 - angle; *bearing = (int)floor(angle + 0.5); } }
void CQTOpenGLCamera::SSettings::CalculateYFieldOfView() { CRadians cAspectRatioAngle = ATan2(3.0f, 4.0f); YFieldOfView = ToDegrees(2.0f * ATan2(0.027f * 0.5f, LensFocalLength)); }
// // AngleBetweenDegrees // Returns the angle between this vector and another in degrees. // float Nixin::Point::AngleBetweenDegrees( const Point other ) const { return ToDegrees( acos( Point::Dot( *this, other ) ) ); }
void VisualLightDebugger::ShowLightInfo() { tstringstream stream; stream.precision(8); if (m_LightType == LightType_Spot) stream << _T("Spotlight selected:\n\n"); else stream << _T("Pointlight selected:\n\n"); tstringstream strm; strm << m_pLight->GetPosition().X; tstring t = strm.str(); stream << _T("X: ") << _T("\n\n"); if (!m_bTextBoxesSet || m_pPreviousLight != m_pLight) { tstringstream strmX; strmX << t.substr(0, t.find(_T(".")) + 4); m_pTextBoxX->SetText(strmX.str()); } strm.str(_T("")); strm << m_pLight->GetPosition().Y; t = strm.str(); stream << _T("Y: ") << _T("\n\n"); if (!m_bTextBoxesSet || m_pPreviousLight != m_pLight) { tstringstream strmY; strmY << t.substr(0, t.find(_T(".")) + 4); m_pTextBoxY->SetText(strmY.str()); } strm.str(_T("")); strm << m_pLight->GetPosition().Z; t = strm.str(); stream << _T("Z: ") << _T("\n\n\n"); if (!m_bTextBoxesSet || m_pPreviousLight != m_pLight) { tstringstream strmZ; strmZ << t.substr(0, t.find(_T(".")) + 4); m_pTextBoxZ->SetText(strmZ.str()); } m_bTextBoxesSet = true; stream << _T("R:") << static_cast<int>(m_pLight->GetColor().R * 255) << _T(" "); stream << _T("G:") << static_cast<int>(m_pLight->GetColor().G * 255) << _T(" "); stream << _T("B:") << static_cast<int>(m_pLight->GetColor().B * 255) << _T("\n\n\n\n\n\n"); stream << _T("Multiplier: ") << m_pLight->GetMulitplier() << _T("\n\n\n\n"); stream << _T("Attenuation end: ") << m_pLight->GetAttenuationEnd() << _T("\n\n\n\n"); if (m_LightType == LightType_Spot) { SpotLight* pSLight = dynamic_cast<SpotLight*>(m_pLight); float angle = ToDegrees(pSLight->GetOpeningsAngle()); //if (angle < 0.1f) angle = 0.0f; //would be weird for the debug -- should never be sub 0 stream << _T("Angle: ") << angle << _T("\n\n\n\n"); stream << _T("ShadowMaps enabled: ") << pSLight->HasShadowMap() << _T("\n"); stream << _T("ShadowMaps size: ") << pSLight->GetShadowMapType(); } BX2D->SetColor( static_cast<int>(m_pLight->GetColor().R * 255), static_cast<int>(m_pLight->GetColor().G * 255), static_cast<int>(m_pLight->GetColor().B * 255) ); BX2D->FillRect(20, 215, 60, 40); m_pTextBoxX->Show(); m_pTextBoxY->Show(); m_pTextBoxZ->Show(); m_pMultiplierAddButton->Show(); m_pMultiplierSubtractButton->Show(); m_pAttenuationAddButton->Show(); m_pAttenuationSubtractButton->Show(); BX2D->SetColor(40,40,40); BX2D->DrawLine(10,180,190,180); BX2D->DrawLine(10,270,190,270); BX2D->DrawLine(10,330,190,330); BX2D->DrawLine(10,387,190,387); if (m_LightType == LightType_Spot) { m_pPowerAddButton->Show(); m_pPowerSubtractButton->Show(); BX2D->DrawLine(10,445,190,445); } BX2D->SetColor(255, 255, 255); BX2D->SetFont(m_pLightInfoFont2); BX2D->DrawString(stream.str(),10,60); }
void Projectile::CalculateVelocities(float pDirection, float pVelocity) { VelX = ToDegrees(cos(ToRadians(pDirection))) * pVelocity; VelY = ToDegrees(sin(ToRadians(pDirection))) * pVelocity; }