//------------------------------------------------------------------------------ //## CullMode TEST_F(Test_Visual_VisualComponent, CullMode) { auto texture1 = Texture2D::create(32, 32); auto texture2 = Texture2D::create(32, 32); texture1->clear(Color::Red); texture2->clear(Color::Green); //* [ ] CullMode { // Back(default), FrontFace -> Visible auto sprite1 = Sprite::create(texture1, 3, 3); sprite1->setShadingModel(ShadingModel::UnLighting); sprite1->setPosition(-1.5, 3, 0); // 裏面は Sprite と Mesh で異なるのでここではテストしない // Front, FrontFace -> Hide auto sprite3 = Sprite::create(texture1, 3, 3); sprite3->setShadingModel(ShadingModel::UnLighting); sprite3->setPosition(-1.5, 0, 0); sprite3->setCullMode(CullMode::Front); // Front, BackFace -> Hide auto sprite4 = Sprite::create(texture2, 3, 3); sprite4->setShadingModel(ShadingModel::UnLighting); sprite4->setPosition(1.5, 0, 0); sprite4->setCullMode(CullMode::Front); sprite4->setEulerAngles(0, Math::PI, 0); // None, FrontFace -> Visible auto sprite5 = Sprite::create(texture1, 3, 3); sprite5->setShadingModel(ShadingModel::UnLighting); sprite5->setPosition(-1.5, -3, 0); sprite5->setCullMode(CullMode::None); // None, BackFace -> Visible auto sprite6 = Sprite::create(texture2, 3, 3); sprite6->setShadingModel(ShadingModel::UnLighting); sprite6->setCullMode(CullMode::None); sprite6->setPosition(1.5, -3, 0); sprite6->setEulerAngles(0, Math::PI, 0); TestEnv::updateFrame(); ASSERT_SCREEN(LN_ASSETFILE("Visual/Result/Test_Visual_VisualComponent-CullMode-1.png")); LN_TEST_CLEAN_SCENE; } }
//------------------------------------------------------------------------------ //## DepthTest, DepthWrite TEST_F(Test_Visual_VisualComponent, DepthTest) { auto texture1 = Texture2D::create(32, 32); auto texture2 = Texture2D::create(32, 32); texture1->clear(Color::Red); texture2->clear(Color::Green); //* [ ] default (enabled depth test and write) { auto sprite1 = Sprite::create(texture1, 5, 5); sprite1->setPosition(0, 0, 0); sprite1->setEulerAngles(0, -Math::PI / 4, 0); sprite1->setShadingModel(ShadingModel::UnLighting); auto sprite2 = Sprite::create(texture2, 5, 5); sprite2->setPosition(0, 0, 0); sprite2->setEulerAngles(0, Math::PI / 4, 0); sprite2->setShadingModel(ShadingModel::UnLighting); TestEnv::updateFrame(); ASSERT_SCREEN(LN_ASSETFILE("Visual/Result/Test_Visual_VisualComponent-DepthTest-1.png")); LN_TEST_CLEAN_SCENE; } //* [ ] disable depth test { auto sprite1 = Sprite::create(texture1, 4, 4); sprite1->setPosition(0, 0, 0); sprite1->setEulerAngles(0, -Math::PI / 4, 0); sprite1->setShadingModel(ShadingModel::UnLighting); auto sprite2 = Sprite::create(texture2, 4, 4); sprite2->setPosition(0, 0, 0); sprite2->setEulerAngles(0, Math::PI / 4, 0); sprite2->setShadingModel(ShadingModel::UnLighting); sprite2->setDepthTestEnabled(false); TestEnv::updateFrame(); ASSERT_SCREEN(LN_ASSETFILE("Visual/Result/Test_Visual_VisualComponent-DepthTest-2.png")); LN_TEST_CLEAN_SCENE; } //* [ ] disable depth write { auto sprite1 = Sprite::create(texture1, 4, 4); sprite1->setPosition(0, 0, 0); sprite1->setEulerAngles(0, -Math::PI / 4, 0); sprite1->setShadingModel(ShadingModel::UnLighting); sprite1->setDepthWriteEnabled(false); auto sprite2 = Sprite::create(texture2, 4, 4); sprite2->setPosition(0, 0, 0); sprite2->setEulerAngles(0, Math::PI / 4, 0); sprite2->setShadingModel(ShadingModel::UnLighting); TestEnv::updateFrame(); ASSERT_SCREEN(LN_ASSETFILE("Visual/Result/Test_Visual_VisualComponent-DepthTest-3.png")); LN_TEST_CLEAN_SCENE; } }
Camera :: Camera ( const Vector3D& p, float yaw, float pitch, float roll, float aFov, float nearZ, float farZ, bool rHanded ) { fov = aFov; zNear = nearZ; zFar = farZ; pos = p; width = 640; // default view size height = 480; aspect = (float)width / (float) height; rightHanded = rHanded; infinite = false; setEulerAngles ( yaw, pitch, roll ); }
//------------------------------------------------------------------------------ // weaponDynamics -- default dynamics; using Robot Aircraft (RAC) dynamics //------------------------------------------------------------------------------ void Effects::weaponDynamics(const LCreal dt) { // Useful constant static const LCreal g = ETHG * Basic::Distance::FT2M; // Acceleration of Gravity (m/s/s) // --- // Compute & Set acceleration vector (earth) // --- // First drag osg::Vec3 tmp = getVelocity() * (-dragIndex); // then gravity osg::Vec3 ae1 = tmp; ae1[IDOWN] += g; setAcceleration(ae1); // --- // Comute & set new velocity vectory (earth) // --- osg::Vec3 ve1 = getVelocity() + (ae1 * dt); setVelocity(ve1); // --- // .. Only after setVelocity has been called ... // --- LCreal vp = getTotalVelocity(); LCreal vg = getGroundSpeed(); // --- // Set velocity vector (body) // (total velocity is along X) // --- setVelocityBody(vp, 0.0, 0.0); // --- // Sent angular values // --- LCreal newPsi = lcAtan2(ve1[IEAST],ve1[INORTH]); LCreal newTheta = lcAtan2( -ve1[IDOWN], vg ); setEulerAngles(0.0, newTheta, newPsi); setAngularVelocities(0.0, 0.0, 0.0); }
//------------------------------------------------------------------------------ // weaponDynamics() -- Bullet dynamics //------------------------------------------------------------------------------ void Bullet::weaponDynamics(const LCreal dt) { if (isMode(ACTIVE)) { updateBurstTrajectories(dt); checkForTargetHit(); // This weapon is slaved to the first burst! if (nbt > 0) { // We control the position and altitude! setPosition( bursts[0].bPos[0], bursts[0].bPos[1], bursts[0].bPos[2], true ); setVelocity( bursts[0].bVel ); setAcceleration( 0, 0, 0 ); setEulerAngles( 0, 0, getGroundTrack() ); setAngularVelocities( 0, 0, 0 ); setVelocityBody ( bursts[0].bVel.length(), 0, 0 ); } } }
EfpFragment::EfpFragment(QString const& name, Vec const& position, double const alpha, double const beta, double const gamma) : m_name(name), m_position(position) { setEulerAngles(alpha, beta, gamma); }
void C3X3Matrix::setEulerAngles(const C3Vector& v) { // v(0), v(1), v(2) are in radian! setEulerAngles(v(0),v(1),v(2)); }
Quaternion::Quaternion(const Float3& angles) { setEulerAngles(angles); }
void LifeForm::look(const LCreal up, const LCreal sdws) { if (getDamage() < 1) { if (lockMode != LOCKED) { lockMode = SEARCHING; // our up and sideways come in as -5 to 5, which is a rate to adjust heading const osg::Vec3 old = getEulerAngles(); LCreal hdg = old.z(); LCreal ptc = lookAngle; LCreal tempSdws = sdws; LCreal tempUp = up; if (lcAbs(tempSdws) < 0.00005) tempSdws = 0; if (lcAbs(tempUp) < 0.05) tempUp = 0; hdg += tempSdws; hdg = lcAepcRad(hdg); // we don't change our pitch when we look up and down, we only change our look angle, so we have to keep // that separate. WE do, however, change our heading based on where we are looking, so that is correct ptc += tempUp; if (ptc > 90) ptc = 90; else if (ptc < -90) ptc = -90; //std::cout << "HEADING = " << hdg << std::endl; setLookAngle(ptc); osg::Vec3 eul(0, 0, hdg); setEulerAngles(eul); // now based on this we need to know if we have a target in our crosshairs... tgtAquired = false; if (tgtPlayer != nullptr) tgtPlayer->unref(); tgtPlayer = nullptr; const osg::Vec3 myPos = getPosition(); osg::Vec3 tgtPos; osg::Vec3 vecPos; LCreal az = 0.0, el = 0.0, range = 0.0, diffAz = 0.0, diffEl = 0.0; const LCreal maxAz = (0.7f * static_cast<LCreal>(Basic::Angle::D2RCC)); const LCreal maxEl = (0.7f * static_cast<LCreal>(Basic::Angle::D2RCC)); //LCreal maxRange = 1500.0f; // long range right now const LCreal la = lookAngle * static_cast<LCreal>(Basic::Angle::D2RCC); Simulation* sim = getSimulation(); if (sim != nullptr) { Basic::PairStream* players = sim->getPlayers(); if (players != nullptr) { Basic::List::Item* item = players->getFirstItem(); while (item != nullptr && !tgtAquired) { Basic::Pair* pair = static_cast<Basic::Pair*>(item->getValue()); if (pair != nullptr) { Player* player = dynamic_cast<Player*>(pair->object()); if (player != nullptr && player != this && !player->isMajorType(WEAPON) && !player->isDestroyed()) { // ok, calculate our position from this guy tgtPos = player->getPosition(); vecPos = tgtPos - myPos; az = lcAtan2(vecPos.y(), vecPos.x()); range = (vecPos.x() * vecPos.x() + vecPos.y() * vecPos.y()); range = std::sqrt(range); // now get our elevation el = lcAtan2(-vecPos.z(), range); diffAz = lcAbs(lcAepcRad(az - static_cast<LCreal>(getHeadingR()))); diffEl = lcAbs(lcAepcRad(la - el)); if ((diffAz <= maxAz) && (diffEl <= maxEl)) { lockMode = TGT_IN_SIGHT; tgtAquired = true; if (tgtPlayer != player) { if (tgtPlayer != nullptr) tgtPlayer->unref(); tgtPlayer = player; tgtPlayer->ref(); } } } } item = item->getNext(); } players->unref(); players = nullptr; } } } // else we are locking on target, and need to follow our target player else { if (tgtPlayer == nullptr) lockMode = SEARCHING; else { const osg::Vec3 vecPos = tgtPlayer->getPosition() - getPosition(); const LCreal az = lcAtan2(vecPos.y(), vecPos.x()); LCreal range = (vecPos.x() * vecPos.x() + vecPos.y() * vecPos.y()); range = std::sqrt(range); // now get our elevation const LCreal el = lcAtan2(-vecPos.z(), range); // now force that on us setLookAngle(el * static_cast<LCreal>(Basic::Angle::R2DCC)); setEulerAngles(0, 0, az); } } } }
//------------------------------------------------------------------------------ // weaponDynamics -- default missile dynamics; using Robot Aircraft (RAC) dynamics //------------------------------------------------------------------------------ void Missile::weaponDynamics(const LCreal dt) { static const LCreal g = ETHG; // Acceleration of Gravity // --- // Max turning G (Missiles: Use Gmax) // --- LCreal gmax = maxG; // --- // Computer max turn rate, max/min pitch rates // --- // Turn rate base on vp and g,s LCreal ra_max = gmax * g / getTotalVelocity(); // Set max (pull up) pitch rate same as turn rate LCreal qa_max = ra_max; // Set min (push down) pitch rate LCreal qa_min = -qa_max; // --- // Get old angular values // --- const osg::Vec3 oldRates = getAngularVelocities(); //LCreal pa1 = oldRates[IROLL]; LCreal qa1 = oldRates[IPITCH]; LCreal ra1 = oldRates[IYAW]; // --- // Find pitch rate and update pitch // --- LCreal qa = lcAepcRad(cmdPitch - (LCreal) getPitchR()); if(qa > qa_max) qa = qa_max; if(qa < qa_min) qa = qa_min; // Using Pitch rate, integrate pitch LCreal newTheta = (LCreal) (getPitch() + (qa + qa1) * dt / 2.0); // Find turn rate LCreal ra = lcAepcRad(cmdHeading - (LCreal) getHeadingR()); if(ra > ra_max) ra = ra_max; if(ra < -ra_max) ra = -ra_max; // Use turn rate integrate heading LCreal newPsi = (LCreal) (getHeading() + (ra + ra1) * dt / 2.0); if(newPsi > 2.0f*PI) newPsi -= (LCreal)(2.0*PI); if(newPsi < 0.0f) newPsi += (LCreal)(2.0*PI); // Roll angle proportional to max turn rate - filtered LCreal pa = 0.0; LCreal newPhi = (LCreal) ( 0.98 * getRollR() + 0.02 * ((ra / ra_max) * (Basic::Angle::D2RCC * 60.0)) ); // Sent angular values setEulerAngles(newPhi, newTheta, newPsi); setAngularVelocities(pa, qa, ra); // Find Acceleration LCreal vpdot = (cmdVelocity - getTotalVelocity()); if(vpdot > maxAccel) vpdot = maxAccel; if(vpdot < -maxAccel) vpdot = -maxAccel; // Set acceleration vector osg::Vec3 aa(vpdot, 0.0, 0.0); osg::Vec3 ae = aa * getRotMat(); setAcceleration(ae); // Comute new velocity LCreal newVP = getTotalVelocity() + vpdot * dt; // Set acceleration vector osg::Vec3 ve0 = getVelocity(); osg::Vec3 va(newVP, 0.0, 0.0); osg::Vec3 ve1 = va * getRotMat(); setVelocity(ve1); setVelocityBody(newVP, 0.0, 0.0); }
void EulerWidget::angleChanged(double angle) { double e[3]; getGuiAngles(e); setEulerAngles(e[0], e[1], e[2]); }