void Camera::UpdateRotation(float delta) { float m_sensitivity = 0.5f; if (Input::GetMouseDown(Input::RIGHT_MOUSE)) { Input::SetCursor(true); mouseLocked = false; } if (mouseLocked) { Vector2f centerPosition = Vector2f((float)Window::GetWidth() / 2.0f, (float)Window::GetHeight() / 2.0f); Vector2f deltaPos = Input::GetMousePosition() - centerPosition; bool rotY = deltaPos.GetX() != 0; bool rotX = deltaPos.GetY() != 0; if (rotY) m_transform.Rotate(Vector3f(0, 1, 0), ToRadians(deltaPos.GetX() * m_sensitivity)); if (rotX) m_transform.Rotate(m_transform.GetRot().GetRight(), ToRadians(deltaPos.GetY() * m_sensitivity)); if (rotY || rotX) Input::SetMousePosition(centerPosition); } if (Input::GetMouseDown(Input::LEFT_MOUSE)) { Vector2f centerPosition = Vector2f((float)Window::GetWidth() / 2.0f, (float)Window::GetHeight() / 2.0f); Input::SetCursor(false); Input::SetMousePosition(centerPosition); mouseLocked = true; } }
/***** * Initialize the controller via the XML configuration file. ARGoS typically * wants objects & variables initialized here instead of in the constructor(s). *****/ void DSA_controller::Init(TConfigurationNode& node) { /* Shorter names, please. #This_Is_Not_Java */ typedef CCI_PositioningSensor CCI_PS; typedef CCI_DifferentialSteeringActuator CCI_DSA; typedef CCI_FootBotProximitySensor CCI_FBPS; /* Initialize the robot's actuator and sensor objects. */ motorActuator = GetActuator<CCI_DSA>("differential_steering"); compass = GetSensor<CCI_PS> ("positioning"); proximitySensor = GetSensor<CCI_FBPS> ("footbot_proximity"); TConfigurationNode DSA_params = GetNode(node, "DSA_params"); GetNodeAttribute(DSA_params, "RobotForwardSpeed", RobotForwardSpeed); GetNodeAttribute(DSA_params, "RobotTurningSpeed", RobotTurningSpeed); GetNodeAttribute(DSA_params, "AngleToleranceInDegrees", angleInDegrees); GetNodeAttribute(DSA_params, "NumberOfRobots", NumberOfRobots); GetNodeAttribute(DSA_params, "NumberOfSpirals", NumberOfSpirals); AngleToleranceInRadians.Set(-ToRadians(angleInDegrees),ToRadians(angleInDegrees)); stepSize = 0.1; /* Assigns the robot's stepSize */ startPosition = CVector3(0.0, 0.0, 0.0); RNG = CRandom::CreateRNG("argos"); generatePattern(NumberOfSpirals, NumberOfRobots); }
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); }
/***** * Initialize the controller via the XML configuration file. ARGoS typically * wants objects & variables initialized here instead of in the constructor(s). *****/ void iAnt_controller::Init(TConfigurationNode& node) { /* Shorter names, please. #This_Is_Not_Java */ typedef CCI_PositioningSensor CCI_PS; typedef CCI_DifferentialSteeringActuator CCI_DSA; typedef CCI_FootBotProximitySensor CCI_FBPS; /* Initialize the robot's actuator and sensor objects. */ motorActuator = GetActuator<CCI_DSA>("differential_steering"); compass = GetSensor<CCI_PS> ("positioning"); proximitySensor = GetSensor<CCI_FBPS> ("footbot_proximity"); TConfigurationNode iAnt_params = GetNode(node, "iAnt_params"); GetNodeAttribute(iAnt_params, "RobotForwardSpeed", RobotForwardSpeed); GetNodeAttribute(iAnt_params, "RobotTurningSpeed", RobotTurningSpeed); ///////////////ADDED//////////////////// CDegrees angleInDegrees; GetNodeAttribute(iAnt_params, "AngleToleranceInDegrees", angleInDegrees); AngleToleranceInRadians.Set(-ToRadians(angleInDegrees), ToRadians(angleInDegrees)); tolerance.Set(-(CRadians::PI_OVER_TWO+x),-(CRadians::PI_OVER_TWO-x)); }
void SpriteAction_SineWave::Update(SpriteController* controller, Sprite* sprite, float deltaTime) { elapsedTime_+=deltaTime; if (!perpetual_ && elapsedTime_>time_) { ActionCompleted(); return; } float scale=1.0f; if (elapsedTime_<easeIn_) { scale=elapsedTime_/easeIn_; } else if (!perpetual_ && elapsedTime_>time_-easeOut_) { scale=1.0f-(elapsedTime_-(time_-easeOut_))/easeOut_; } float xOffset=Sin(elapsedTime_*frequencyX_+ToRadians(offsetX_))*amplitudeX_*scale; float yOffset=Sin(elapsedTime_*frequencyY_+ToRadians(offsetY_))*amplitudeY_*scale; controller->AddOffset(xOffset,yOffset); }
CBuzzControllerEFootBot::SWheelTurningParams::SWheelTurningParams() : TurningMechanism(NO_TURN), HardTurnOnAngleThreshold(ToRadians(CDegrees(90.0))), SoftTurnOnAngleThreshold(ToRadians(CDegrees(70.0))), NoTurnAngleThreshold(ToRadians(CDegrees(10.0))), MaxSpeed(10.0) { }
RenderingEngine::RenderingEngine(const Window& window) : m_plane(Mesh("plane.obj")), m_window(&window), m_tempTarget(window.GetWidth(), window.GetHeight(), 0, GL_TEXTURE_2D, GL_NEAREST, GL_RGBA, GL_RGBA, false, GL_COLOR_ATTACHMENT0), m_planeMaterial("renderingEngine_filterPlane", m_tempTarget, 1, 8), m_defaultShader("forward-ambient"), m_shadowMapShader("shadowMapGenerator"), m_nullFilter("filter-null"), m_gausBlurFilter("filter-gausBlur7x1"), m_fxaaFilter("filter-fxaa"), m_altCameraTransform(Vector3f(0,0,0), Quaternion(Vector3f(0,1,0),ToRadians(180.0f))), m_altCamera(Matrix4f().InitIdentity(), &m_altCameraTransform) { SetSamplerSlot("diffuse", 0); SetSamplerSlot("normalMap", 1); SetSamplerSlot("dispMap", 2); SetSamplerSlot("shadowMap", 3); SetSamplerSlot("roughMap", 4); SetSamplerSlot("filterTexture", 0); SetVector3f("ambient", Vector3f(0.2f, 0.2f, 0.2f)); SetFloat("fxaaSpanMax", 8.0f); SetFloat("fxaaReduceMin", 1.0f/128.0f); SetFloat("fxaaReduceMul", 1.0f/8.0f); SetFloat("fxaaAspectDistortion", 150.0f); SetTexture("displayTexture", Texture(m_window->GetWidth(), m_window->GetHeight(), 0, GL_TEXTURE_2D, GL_LINEAR, GL_RGBA, GL_RGBA, true, GL_COLOR_ATTACHMENT0)); glClearColor(0.0f, 0.0f, 0.0f, 0.0f); glFrontFace(GL_CW); glCullFace(GL_BACK); glEnable(GL_CULL_FACE); glEnable(GL_DEPTH_TEST); //glEnable(GL_DEPTH_CLAMP); //glEnable(GL_MULTISAMPLE); //glEnable(GL_FRAMEBUFFER_SRGB); //m_planeMaterial("renderingEngine_filterPlane", m_tempTarget, 1, 8); m_planeTransform.SetScale(1.0f); m_planeTransform.Rotate(Quaternion(Vector3f(1,0,0), ToRadians(90.0f))); m_planeTransform.Rotate(Quaternion(Vector3f(0,0,1), ToRadians(180.0f))); for(int i = 0; i < NUM_SHADOW_MAPS; i++) { int shadowMapSize = 1 << (i + 1); m_shadowMaps[i] = Texture(shadowMapSize, shadowMapSize, 0, GL_TEXTURE_2D, GL_LINEAR, GL_RG32F, GL_RGBA, true, GL_COLOR_ATTACHMENT0); m_shadowMapTempTargets[i] = Texture(shadowMapSize, shadowMapSize, 0, GL_TEXTURE_2D, GL_LINEAR, GL_RG32F, GL_RGBA, true, GL_COLOR_ATTACHMENT0); } m_lightMatrix = Matrix4f().InitScale(Vector3f(0,0,0)); }
void TestGame::Init() { GameObject* planeObject = new GameObject(); GameObject* pointLightObject = new GameObject(); GameObject* spotLightObject = new GameObject(); GameObject* directionalLightObject = new GameObject(); planeObject->AddComponent(new MeshRenderer(new Mesh("./res/models/plane3.obj"), new Material(new Texture("bricks.jpg"), 0.5f, 4, new Texture("bricks_normal.jpg"), new Texture("bricks_disp.png"), 0.03f, -0.5f))); planeObject->GetTransform().SetPos(Vector3f(0, -1, 5)); planeObject->GetTransform().SetScale(4.0f); pointLightObject->AddComponent(new PointLight(Vector3f(0,1,0),0.4f,Attenuation(0,0,1))); pointLightObject->GetTransform().SetPos(Vector3f(7,0,7)); spotLightObject->AddComponent(new SpotLight(Vector3f(0,1,1),0.4f,Attenuation(0,0,0.1f),0.7f)); spotLightObject->GetTransform().SetRot(Quaternion(Vector3f(0,1,0), ToRadians(90.0f))); directionalLightObject->AddComponent(new DirectionalLight(Vector3f(1,1,1), 0.4f)); GameObject* testMesh1 = new GameObject(); GameObject* testMesh2 = new GameObject(); //WARNING: bricks2_normal.jpg is reversed on the y axis. This is intentional, and demonstrates how normal maps are sometimes flipped. //If you want to fix this, the easiest solution is to flip it in an image editor. testMesh1->AddComponent(new MeshRenderer(new Mesh("./res/models/plane3.obj"), new Material(new Texture("bricks2.jpg"), 1, 8, new Texture("bricks2_normal.jpg"), new Texture("bricks2_disp.jpg"), 0.04f, -1.0f))); testMesh2->AddComponent(new MeshRenderer(new Mesh("./res/models/plane3.obj"), new Material(new Texture("bricks2.jpg"), 1, 8, new Texture("bricks2_normal.jpg")))); testMesh1->GetTransform().SetPos(Vector3f(0, 2, 0)); testMesh1->GetTransform().SetRot(Quaternion(Vector3f(0,1,0), 0.4f)); testMesh1->GetTransform().SetScale(1.0f); testMesh2->GetTransform().SetPos(Vector3f(0, 0, 25)); testMesh1->AddChild(testMesh2); AddToScene(planeObject); AddToScene(pointLightObject); AddToScene(spotLightObject); AddToScene(directionalLightObject); AddToScene(testMesh1); testMesh2->AddChild((new GameObject()) ->AddComponent(new Camera(Matrix4f().InitPerspective(ToRadians(70.0f), Window::GetAspect(), 0.1f, 1000.0f))) ->AddComponent(new FreeLook()) ->AddComponent(new FreeMove())); directionalLightObject->GetTransform().SetRot(Quaternion(Vector3f(1,0,0), ToRadians(-45))); }
void CFootBotForaging::SDiffusionParams::Init(TConfigurationNode& t_node) { try { CRange<CDegrees> cGoStraightAngleRangeDegrees(CDegrees(-10.0f), CDegrees(10.0f)); GetNodeAttribute(t_node, "go_straight_angle_range", cGoStraightAngleRangeDegrees); GoStraightAngleRange.Set(ToRadians(cGoStraightAngleRangeDegrees.GetMin()), ToRadians(cGoStraightAngleRangeDegrees.GetMax())); GetNodeAttribute(t_node, "delta", Delta); } catch(CARGoSException& ex) { THROW_ARGOSEXCEPTION_NESTED("Error initializing controller diffusion parameters.", ex); } }
void MazeMovement::ProcessInput(const Input& input, float delta) { if (!m_moving) { SetFrontTile(); if (input.GetKeyUp(Input::KEY_LEFT)) { GetTransform()->Rotate(PxQuat(ToRadians(-90.0f), PxVec3(0, 1, 0))); SetFrontTile(); } if (input.GetKeyUp(Input::KEY_RIGHT)) { GetTransform()->Rotate(PxQuat(ToRadians(90.0f), PxVec3(0, 1, 0))); SetFrontTile(); } if (input.GetKey(Input::KEY_UP)) { switch (m_frontTile) { case 2: m_ogPosition = *GetTransform()->GetPos(); m_desiredPosition = *GetTransform()->GetPos() + PxVec3(-GetTransform()->GetRot()->getBasisVector0().z, 0.0f, GetTransform()->GetRot()->getBasisVector0().x); m_gridPosition = PxVec2(m_gridPosition.x - (int)GetTransform()->GetRot()->getBasisVector0().z, m_gridPosition.y + (int)GetTransform()->GetRot()->getBasisVector0().x); SetFrontTile(); m_moving = true; break; } } if (input.GetKey(Input::KEY_DOWN)) { switch (m_maze[(int)m_gridPosition.x + (int)GetTransform()->GetRot()->getBasisVector0().z][(int)m_gridPosition.y - (int)GetTransform()->GetRot()->getBasisVector0().x]) { case 2: m_ogPosition = *GetTransform()->GetPos(); m_desiredPosition = (*GetTransform()->GetPos() - PxVec3(-GetTransform()->GetRot()->getBasisVector0().z, 0.0f, +GetTransform()->GetRot()->getBasisVector0().x)); m_gridPosition = PxVec2(m_gridPosition.x + (int)GetTransform()->GetRot()->getBasisVector0().z, m_gridPosition.y - (int)GetTransform()->GetRot()->getBasisVector0().x); SetFrontTile(); m_moving = true; break; } } if (input.GetKeyUp(Input::KEY_F) && m_frontTile == 3) { m_parent->GetEngine().Stop(); } } }
void FreeLook::ProcessInput(const Input& input, float delta) { if (input.GetKeyUp(Input::KEY_LEFT)) { GetTransform()->Rotate(PxQuat(ToRadians(-90.0f), PxVec3(0, 1, 0))); } if (input.GetKeyUp(Input::KEY_RIGHT)) { GetTransform()->Rotate(PxQuat(ToRadians(90.0f), PxVec3(0, 1, 0))); } }
G3D::Matrix4 Utils::GetTransformation(IDefinition def) { G3D::Matrix4 translation; if (def.Position.x == 0.0f && def.Position.y == 0.0f && def.Position.z == 0.0f) translation = G3D::Matrix4::identity(); else translation = G3D::Matrix4::translation(-(def.Position.z - Constants::MaxXY), -(def.Position.x - Constants::MaxXY), def.Position.y); G3D::Matrix4 rotation = RotationX(ToRadians(def.Rotation.z)) * RotationY(ToRadians(def.Rotation.x)) * RotationZ(ToRadians(def.Rotation.y + 180)); if (def.Scale() < 1.0f || def.Scale() > 1.0f) return G3D::Matrix4::scale(def.Scale()) * rotation * translation; return rotation * translation; }
void CRABEquippedEntity::Init(TConfigurationNode& t_tree) { try { /* * Init entity. * Here we explicitly avoid to call CPositionalEntity::Init() because that * would also initialize position and orientation, which, instead, must * be calculated from reference entity and offsets. */ CEntity::Init(t_tree); /* Get offsets */ GetNodeAttributeOrDefault(t_tree, "pos_offset", m_cPosOffset, m_cPosOffset); std::string strRotOffset; GetNodeAttributeOrDefault(t_tree, "rot_offset", strRotOffset, strRotOffset); if(strRotOffset != "") { CDegrees cRotOffsetEuler[3]; ParseValues(strRotOffset, 3, cRotOffsetEuler, ','); m_cRotOffset.FromEulerAngles(ToRadians(cRotOffsetEuler[0]), ToRadians(cRotOffsetEuler[1]), ToRadians(cRotOffsetEuler[2])); } /* Parse and look up the anchor */ std::string strAnchorId; GetNodeAttribute(t_tree, "anchor", strAnchorId); /* * NOTE: here we get a reference to the embodied entity * This line works under the assumption that: * 1. the RABEquippedEntity has a parent; * 2. the parent has a child whose id is "body" * 3. the "body" is an embodied entity * If any of the above is false, this line will bomb out. */ m_pcEntityBody = &GetParent().GetComponent<CEmbodiedEntity>("body"); m_psAnchor = &m_pcEntityBody->GetAnchor(strAnchorId); /* Get message size */ size_t unMsgSize; GetNodeAttribute(t_tree, "msg_size", unMsgSize); m_cData.Resize(unMsgSize); /* Get transmission range */ GetNodeAttribute(t_tree, "range", m_fRange); /* Set init position and orientation */ Update(); SetInitPosition(GetPosition()); SetInitOrientation(GetOrientation()); } catch(CARGoSException& ex) { THROW_ARGOSEXCEPTION_NESTED("Error initializing a range and bearing entity \"" << GetId() << "\"", ex); } }
void CBuzzControllerEFootBot::SWheelTurningParams::Init(TConfigurationNode& t_node) { try { TurningMechanism = NO_TURN; CDegrees cAngle; GetNodeAttribute(t_node, "hard_turn_angle_threshold", cAngle); HardTurnOnAngleThreshold = ToRadians(cAngle); GetNodeAttribute(t_node, "soft_turn_angle_threshold", cAngle); SoftTurnOnAngleThreshold = ToRadians(cAngle); GetNodeAttribute(t_node, "no_turn_angle_threshold", cAngle); NoTurnAngleThreshold = ToRadians(cAngle); GetNodeAttribute(t_node, "max_speed", MaxSpeed); } catch(CARGoSException& ex) { THROW_ARGOSEXCEPTION_NESTED("Error initializing controller wheel turning parameters.", ex); } }
void RenderingEngine::ApplyFilter(const Shader& filter, const Texture& source, const Texture* dest) { assert(&source != dest); if(dest == 0) { m_window->BindAsRenderTarget(); } else { dest->BindAsRenderTarget(); } SetTexture("filterTexture", source); m_altCamera.SetProjection(Matrix4f().InitIdentity()); m_altCamera.GetTransform()->SetPos(Vector3f(0,0,0)); m_altCamera.GetTransform()->SetRot(Quaternion(Vector3f(0,1,0),ToRadians(180.0f))); // const Camera* temp = m_mainCamera; // m_mainCamera = m_altCamera; glClear(GL_DEPTH_BUFFER_BIT); filter.Bind(); filter.UpdateUniforms(m_planeTransform, m_planeMaterial, *this, m_altCamera); m_plane.Draw(); // m_mainCamera = temp; SetTexture("filterTexture", 0); }
MALIB_API MAT4x4 Perspective(float fovAngleY, float aspectRatio, float nearZ, float farZ) { #if 0 float cosFov = cos(fovAngleY * 0.5f); float sinFov = sin(fovAngleY * 0.5f); float height = cosFov / sinFov; float width = height / aspectRatio; float zinterp = farZ / (farZ - nearZ); return MAT4x4( width, 0.f, 0.f, 0.f, 0.f, height, 0.f, 0.f, 0.f, 0.f, zinterp, -zinterp * nearZ, 0.f, 0.f, 0.f, 1.f ); #else float r = ToRadians(fovAngleY); float range = tan(r / 2.0f) * nearZ; float left = -range * aspectRatio; float right = -range * aspectRatio; float bottom = -range; float top = range; MAT4x4 result = MAT4x4(); result.r0c0 = (nearZ * 2.0f) / (right - left); result.r1c1 = (nearZ * 2.0f) / (top - bottom); result.r2c2 = (farZ + nearZ) / (farZ - nearZ); result.r2c3 = 1.0f; result.r3c2 = (2.0f * farZ * nearZ) / (farZ - nearZ); return result; #endif }
void Viewpoint::SetOrientation( double angle, Vector3 axis ) { Matrix3x3 m; SetRotationMatrix( m, ToRadians( angle ), axis ); SetOrientation( m ); }
void FreeLook::processInput(const InputManager& input, float delta) { if (input.GetThumbRPosition().x < -0.1f || input.GetThumbRPosition().x > 0.1f) { getTransform()->rotate(PxVec3(0.0f, 1.0f, 0.0f), ToRadians(input.GetThumbRPosition().x) * 2.0f); } if (input.GetThumbRPosition().y < -0.1f || input.GetThumbRPosition().y > 0.1f) { getTransform()->rotate(Utility::getRight(*getTransform()->getRotation()), ToRadians(-input.GetThumbRPosition().y) * 2.0f); } /*if (input.KeyDown(m_unlockMouseKey)) { input.SetCursor(true); m_mouseLocked = false; } if (m_mouseLocked) { PxVec2 deltaPos = input.GetMousePosition() - m_windowCenter; bool rotY = deltaPos.x != 0; bool rotX = deltaPos.y != 0; if (rotY) { getTransform()->rotate(PxVec3(0.0f, 1.0f, 0.0f), ToRadians(deltaPos.x * m_sensitivity)); } if (rotX) { getTransform()->rotate(Utility::getRight(*getTransform()->getRotation()), ToRadians(deltaPos.y * m_sensitivity)); } if (rotY || rotX) { input.SetMousePosition(m_windowCenter); } } if (input.MouseButtonDown(SDL_BUTTON_LEFT)) { input.SetCursor(false); input.SetMousePosition(m_windowCenter); m_mouseLocked = true; }*/ }
void ForwardRenderQueue::AddBillboards(int renderOrder, const Material* material, unsigned int count, SparsePtr<const Vector3f> positionPtr, SparsePtr<const float> sizePtr, SparsePtr<const float> anglePtr, SparsePtr<const float> alphaPtr) { NazaraAssert(material, "Invalid material"); ///DOC: sinCosPtr et alphaPtr peuvent être nuls, ils seont remplacés respectivement par Vector2f(0.f, 1.f) et Color::White float defaultRotation = 0.f; if (!anglePtr) anglePtr.Reset(&defaultRotation, 0); // L'astuce ici est de mettre le stride sur zéro, rendant le pointeur immobile float defaultAlpha = 1.f; if (!alphaPtr) alphaPtr.Reset(&defaultAlpha, 0); // Pareil auto& billboards = GetLayer(renderOrder).billboards; auto it = billboards.find(material); if (it == billboards.end()) { BatchedBillboardEntry entry; entry.materialReleaseSlot.Connect(material->OnMaterialRelease, this, &ForwardRenderQueue::OnMaterialInvalidation); it = billboards.insert(std::make_pair(material, std::move(entry))).first; } BatchedBillboardEntry& entry = it->second; auto& billboardVector = entry.billboards; unsigned int prevSize = billboardVector.size(); billboardVector.resize(prevSize + count); BillboardData* billboardData = &billboardVector[prevSize]; for (unsigned int i = 0; i < count; ++i) { float sin = std::sin(ToRadians(*anglePtr)); float cos = std::cos(ToRadians(*anglePtr)); anglePtr++; billboardData->center = *positionPtr++; billboardData->color = Color(255, 255, 255, static_cast<UInt8>(255.f * (*alphaPtr++))); billboardData->sinCos.Set(sin, cos); billboardData->size.Set(*sizePtr++); billboardData++; } }
void OpenGLObject::SetAttitude( double angle, const Vector3 axis ) { Matrix3x3 m; SetRotationMatrix( m, ToRadians( angle ), axis ); SetAttitude( m ); }
void CPFA_loop_functions::Init(argos::TConfigurationNode &node) { argos::CDegrees USV_InDegrees; argos::TConfigurationNode CPFA_node = argos::GetNode(node, "CPFA"); argos::GetNodeAttribute(CPFA_node, "ProbabilityOfSwitchingToSearching", ProbabilityOfSwitchingToSearching); argos::GetNodeAttribute(CPFA_node, "ProbabilityOfReturningToNest", ProbabilityOfReturningToNest); argos::GetNodeAttribute(CPFA_node, "UninformedSearchVariation", USV_InDegrees); argos::GetNodeAttribute(CPFA_node, "RateOfInformedSearchDecay", RateOfInformedSearchDecay); argos::GetNodeAttribute(CPFA_node, "RateOfSiteFidelity", RateOfSiteFidelity); argos::GetNodeAttribute(CPFA_node, "RateOfLayingPheromone", RateOfLayingPheromone); argos::GetNodeAttribute(CPFA_node, "RateOfPheromoneDecay", RateOfPheromoneDecay); argos::GetNodeAttribute(CPFA_node, "PrintFinalScore", PrintFinalScore); UninformedSearchVariation = ToRadians(USV_InDegrees); /****************************************************************************************************************************/ argos::TConfigurationNode settings_node = argos::GetNode(node, "settings"); argos::GetNodeAttribute(settings_node, "MaxSimTimeInSeconds", MaxSimTime); MaxSimTime *= GetSimulator().GetPhysicsEngine("dyn2d").GetInverseSimulationClockTick(); argos::GetNodeAttribute(settings_node, "MaxSimCounter", MaxSimCounter); argos::GetNodeAttribute(settings_node, "VariableFoodPlacement", VariableFoodPlacement); argos::GetNodeAttribute(settings_node, "OutputData", OutputData); argos::GetNodeAttribute(settings_node, "DrawIDs", DrawIDs); argos::GetNodeAttribute(settings_node, "DrawTrails", DrawTrails); argos::GetNodeAttribute(settings_node, "DrawTargetRays", DrawTargetRays); argos::GetNodeAttribute(settings_node, "FoodDistribution", FoodDistribution); argos::GetNodeAttribute(settings_node, "FoodItemCount", FoodItemCount); argos::GetNodeAttribute(settings_node, "NumberOfClusters", NumberOfClusters); argos::GetNodeAttribute(settings_node, "ClusterWidthX", ClusterWidthX); argos::GetNodeAttribute(settings_node, "ClusterLengthY", ClusterLengthY); argos::GetNodeAttribute(settings_node, "PowerRank", PowerRank); argos::GetNodeAttribute(settings_node, "FoodRadius", FoodRadius); argos::GetNodeAttribute(settings_node, "NestElevation", NestElevation); FoodRadiusSquared = FoodRadius*FoodRadius; // calculate the forage range and compensate for the robot's radius of 0.085m argos::CVector3 ArenaSize = GetSpace().GetArenaSize(); argos::Real rangeX = (ArenaSize.GetX() / 2.0) - 0.085; argos::Real rangeY = (ArenaSize.GetY() / 2.0) - 0.085; ForageRangeX.Set(-rangeX, rangeX); ForageRangeY.Set(-rangeY, rangeY); // Send a pointer to this loop functions object to each controller. argos::CSpace::TMapPerType& footbots = GetSpace().GetEntitiesByType("foot-bot"); argos::CSpace::TMapPerType::iterator it; for(it = footbots.begin(); it != footbots.end(); it++) { argos::CFootBotEntity& footBot = *argos::any_cast<argos::CFootBotEntity*>(it->second); BaseController& c = dynamic_cast<BaseController&>(footBot.GetControllableEntity().GetController()); CPFA_controller& c2 = dynamic_cast<CPFA_controller&>(c); c2.SetLoopFunctions(this); } SetFoodDistribution(); }
void TestGame::Init(const Window& window) { Material bricks("bricks", Texture("bricks.jpg"), 0.0f, 0, Texture("bricks_normal.jpg"), Texture("bricks_disp.png"), 0.03f, -0.5f); Material bricks2("bricks2", Texture("bricks2.jpg"), 0.0f, 0, Texture("bricks2_normal.png"), Texture("bricks2_disp.jpg"), 0.04f, -1.0f); //Material skin("humanFace", Texture("human.jpg"), 0.0f, 0, Texture("human_normal_inv.jpg")); //Material skin("humanFace", Texture("human.jpg"), 0.08f, 8, Texture("human_normal_inv.jpg")); IndexedModel square; { square.AddVertex(1.0f, -1.0f, 0.0f); square.AddTexCoord(Vector2f(1.0f, 1.0f)); square.AddVertex(1.0f, 1.0f, 0.0f); square.AddTexCoord(Vector2f(1.0f, 0.0f)); square.AddVertex(-1.0f, -1.0f, 0.0f); square.AddTexCoord(Vector2f(0.0f, 1.0f)); square.AddVertex(-1.0f, 1.0f, 0.0f); square.AddTexCoord(Vector2f(0.0f, 0.0f)); square.AddFace(0, 1, 2); square.AddFace(2, 1, 3); } Mesh customMesh("square", square.Finalize()); AddToScene((new Entity(Vector3f(0, -1, 5), Quaternion(), 32.0f)) ->AddComponent(new MeshRenderer(Mesh("terrain02.obj"), Material("bricks")))); AddToScene((new Entity(Vector3f(7,0,7))) ->AddComponent(new PointLight(Vector3f(0,1,0), 0.4f, Attenuation(0,0,1)))); AddToScene((new Entity(Vector3f(20,-11.0f,5), Quaternion(Vector3f(1,0,0), ToRadians(-60.0f)) * Quaternion(Vector3f(0,1,0), ToRadians(90.0f)))) ->AddComponent(new SpotLight(Vector3f(0,1,1), 0.4f, Attenuation(0,0,0.02f), ToRadians(91.1f), 7, 1.0f, 0.5f))); AddToScene((new Entity(Vector3f(), Quaternion(Vector3f(1,0,0), ToRadians(-45)))) ->AddComponent(new DirectionalLight(Vector3f(1,1,1), 0.4f, 10, 80.0f, 1.0f))); AddToScene((new Entity(Vector3f(0, 2, 0), Quaternion(Vector3f(0,1,0), 0.4f), 1.0f)) ->AddComponent(new MeshRenderer(Mesh("plane3.obj"), Material("bricks2"))) ->AddChild((new Entity(Vector3f(0, 0, 25))) ->AddComponent(new MeshRenderer(Mesh("plane3.obj"), Material("bricks2"))) ->AddChild((new Entity()) ->AddComponent(new CameraComponent(Matrix4f().InitPerspective(ToRadians(70.0f), window.GetAspect(), 0.1f, 1000.0f))) ->AddComponent(new FreeLook(window.GetCenter())) ->AddComponent(new FreeMove(10.0f))))); AddToScene((new Entity(Vector3f(24,-12,5), Quaternion(Vector3f(0,1,0), ToRadians(30.0f)))) ->AddComponent(new MeshRenderer(Mesh("sphere.obj"), Material("bricks")))); AddToScene((new Entity(Vector3f(0,0,7), Quaternion(), 1.0f)) ->AddComponent(new MeshRenderer(Mesh("square"), Material("bricks2")))); }
double GenerationMath::DistanceBetweenTwoCoordinates( GeographicCoordinate coord1, GeographicCoordinate coord2) { //a = sin²(Δφ/2) + cos φ1 ⋅ cos φ2 ⋅ sin²(Δλ/2) //c = 2 ⋅ atan2( √a, √(1−a) ) //d = R ⋅ c double lat1 = ToRadians(coord1.GetLatitude()); double lat2 = ToRadians(coord2.GetLatitude()); double d_lat = ToRadians(coord2.GetLatitude() - coord1.GetLatitude()); double d_long = ToRadians(coord2.GetLongitude() - coord1.GetLongitude()); double a = sin(d_lat/2) * sin(d_lat/2) + cos(lat1) * cos(lat2) * sin(d_long/2) * sin(d_long/2); double c = 2 * atan2(sqrt(a), sqrt(1-a)); //std::cout << "c: " << c << std::endl; //std::cout << "Result: " << (20,903,520 * c) << std::endl; return EARTH_RAD * c * 5280; }
MALIB_API MAT4x4 RotateX(float x) { x = ToRadians(x); return MAT4x4( 1.f, 0.f, 0.f, 0.f, 0.f, cos(x), -sin(x), 0.f, 0.f, sin(x), cos(x), 0.f, 0.f, 0.f, 0.f, 1.f ); }
MALIB_API MAT4x4 RotateY(float y) { y = ToRadians(y); return MAT4x4( cos(y), 0.f, sin(y), 0.f, 0.f, 1.f, 0.f, 0.f, -sin(y), 0.f, cos(y), 0.f, 0.f, 0.f, 0.f, 1.f ); }
MALIB_API MAT4x4 RotateZ(float z) { z = ToRadians(z); return MAT4x4( cos(z), -sin(z), 0.f, 0.f, sin(z), cos(z), 0.f, 0.f, 0.f, 0.f, 1.f, 0.f, 0.f, 0.f, 0.f, 1.f ); }
void Assignment2::Init() { GameObject* planeObject = new GameObject(); GameObject* pointLightObject = new GameObject(); GameObject* spotLightObject = new GameObject(); GameObject* directionalLightObject = new GameObject(); planeObject->AddComponent(new MeshRenderer(new Mesh("./res/models/plane3.obj"), new Material(new Texture("bricks.jpg"), 1, 8))); planeObject->GetTransform().SetPos(Vector3f(0, -1, 5)); planeObject->GetTransform().SetScale(4.0f); pointLightObject->AddComponent(new PointLight(Vector3f(0,1,0),0.4f,Attenuation(0,0,1))); pointLightObject->GetTransform().SetPos(Vector3f(7,0,7)); spotLightObject->AddComponent(new SpotLight(Vector3f(0,1,1),0.4f,Attenuation(0,0,0.1f),0.7f)); spotLightObject->GetTransform().SetRot(Quaternion(Vector3f(0,1,0), ToRadians(90.0f))); directionalLightObject->AddComponent(new DirectionalLight(Vector3f(1,1,1), 0.4f)); GameObject* testMesh1 = new GameObject(); GameObject* testMesh2 = new GameObject(); testMesh1->GetTransform().SetPos(Vector3f(0, 2, 0)); testMesh1->GetTransform().SetRot(Quaternion(Vector3f(0,1,0), 0.4f)); testMesh1->GetTransform().SetScale(1.0f); testMesh2->GetTransform().SetPos(Vector3f(0, 0, 25)); testMesh1->AddChild(testMesh2); AddToScene(planeObject); AddToScene(pointLightObject); AddToScene(spotLightObject); AddToScene(directionalLightObject); AddToScene(testMesh1); testMesh2->AddChild((new GameObject()) ->AddComponent(new Camera(Matrix4f().InitPerspective(ToRadians(70.0f), Window::GetAspect(), 0.1f, 1000.0f))) ->AddComponent(new FreeLook()) ->AddComponent(new FreeMove())); directionalLightObject->GetTransform().SetRot(Quaternion(Vector3f(1,0,0), ToRadians(-45))); }
void RigidBody2D::SetRotation(float rotation) { cpBodySetAngle(m_handle, ToRadians(rotation)); if (m_isStatic) { m_world->RegisterPostStep(this, [](Nz::RigidBody2D* body) { cpSpaceReindexShapesForBody(body->GetWorld()->GetHandle(), body->GetHandle()); }); } }
void CameraComponent::ProcessInput(const Event& event, float delta) { if (event.type == Event::Resized) { glViewport(0, 0, event.size.width, event.size.height); float aspect = static_cast<float>(event.size.width) / static_cast<float>(event.size.height); SetProjection(Matrix4f().InitPerspective(ToRadians(70.0f), aspect, 0.1f, 1000.0f)); } }
void CModelControl::UpdateMatrices() { // Rotation D3DXMATRIX matrixRotationX; D3DXMATRIX matrixRotationY; D3DXMATRIX matrixRotationZ; // Position D3DXMATRIX matrixTranslation; // Calculate the rotation of the camera. D3DXMatrixRotationX(&matrixRotationX, ToRadians(mRotation.x)); D3DXMatrixRotationY(&matrixRotationY, ToRadians(mRotation.y)); D3DXMatrixRotationZ(&matrixRotationZ, ToRadians(mRotation.z)); // Calculate the translation of the camera. D3DXMatrixTranslation(&matrixTranslation, mPosition.x, mPosition.y, mPosition.z); // Calculate the world matrix mWorldMatrix = matrixRotationZ * matrixRotationX * matrixRotationY * matrixTranslation; }