예제 #1
0
// ------------- update
void EyeLinker::update(){
    updateVelocity();
    updateParameters();
    updatePhysics();
    updateEye();
    updateFading();
    updateFireworks();
}
예제 #2
0
Z3DCameraParameter::Z3DCameraParameter(const QString &name, const Z3DCamera &value, QObject *parent)
  : ZSingleValueParameter<Z3DCamera>(name, value, parent)
  , m_projectionType("Projection Type")
  , m_eye("Eye Position", value.getEye(), glm::vec3(-std::numeric_limits<float>::max()),
          glm::vec3(std::numeric_limits<float>::max()))
  , m_center("Center Position", value.getCenter(), glm::vec3(-std::numeric_limits<float>::max()),
             glm::vec3(std::numeric_limits<float>::max()))
  , m_upVector("Up Vector", value.getUpVector(), glm::vec3(-1.f), glm::vec3(1.f))
  , m_eyeSeparationAngle("Eye Separation Angle", value.getEyeSeparationAngle(), 1.f, 80.f)
  , m_fieldOfView("Field of View", value.getFieldOfView(), 10.f, 170.f)
  , m_nearDist("Near Distance", value.getNearDist(), 1e-10, std::numeric_limits<float>::max())
  , m_farDist("Far Distance", value.getFarDist(), 1e-10, std::numeric_limits<float>::max())
  , m_receiveWidgetSignal(true)
{
  m_projectionType.addOptions("Perspective", "Orthographic");
  if (value.isPerspectiveProjection())
    m_projectionType.select("Perspective");
  else
    m_projectionType.select("Orthographic");
  connect(&m_projectionType, SIGNAL(valueChanged()), this, SLOT(updateProjectionType()));

  m_eye.setSingleStep(1e-10);
  m_eye.setDecimal(10);
  //m_eye.setWidgetOrientation(Qt::Horizontal);
  m_eye.setStyle("SPINBOX");
  connect(&m_eye, SIGNAL(valueChanged()), this, SLOT(updateEye()));

  m_center.setSingleStep(1e-10);
  m_center.setDecimal(10);
  //m_center.setWidgetOrientation(Qt::Horizontal);
  m_center.setStyle("SPINBOX");
  connect(&m_center, SIGNAL(valueChanged()), this, SLOT(updateCenter()));

  m_upVector.setSingleStep(1e-10);
  m_upVector.setDecimal(10);
  m_upVector.setStyle("SPINBOX");
  connect(&m_upVector, SIGNAL(valueChanged()), this, SLOT(updateUpVector()));

  m_eyeSeparationAngle.setSingleStep(.1);
  m_eyeSeparationAngle.setDecimal(1);
  connect(&m_eyeSeparationAngle, SIGNAL(valueChanged()), this, SLOT(updateEyeSeparationAngle()));

  m_fieldOfView.setSingleStep(.1);
  m_fieldOfView.setDecimal(1);
  connect(&m_fieldOfView, SIGNAL(valueChanged()), this, SLOT(updateFieldOfView()));

  m_nearDist.setSingleStep(1e-10);
  m_nearDist.setDecimal(10);
  m_nearDist.setStyle("SPINBOX");
  m_nearDist.setRange(1e-10, value.getFarDist());
  connect(&m_nearDist, SIGNAL(valueChanged()), this, SLOT(updateNearDist()));

  m_farDist.setSingleStep(1e-10);
  m_farDist.setDecimal(10);
  m_farDist.setStyle("SPINBOX");
  m_farDist.setRange(value.getNearDist(), std::numeric_limits<float>::max());
  connect(&m_farDist, SIGNAL(valueChanged()), this, SLOT(updateFarDist()));
}
void MouseView3D::mouseWheel(float dx, float dy)
{
    (void)dx;

    float tmpRadius = m_radius - dy * 1.5f;

    if (tmpRadius > 0.0f) {
        m_radius = tmpRadius;
        updateEye();
    }
}
void MouseView3D::mouseMove(float x, float y)
{
    float pos[] = {x, y};

    if (m_mouseLeft) {
        // update deltaAngle
        m_angles[0] = m_startAngles[0] - 0.01f * (pos[0] - m_currentPos[0]);
        m_angles[1] = m_startAngles[1] + 0.01f * (pos[1] - m_currentPos[1]);

        // Limit the vertical angle (5 to 85 degrees)
        if (m_angles[1] > DEG2RAD(85))
            m_angles[1] = DEG2RAD(85);

        if (m_angles[0] < DEG2RAD(5))
            m_angles[0] = DEG2RAD(5);

        updateEye();
        updateMatrices();
    } else if (m_mouseRight) {
        //Translation
        float t[3];
        t[0] = 0.1f * (pos[0] - m_currentPos[0]);
        t[1] = 0;
        t[2] = 0.1f * (pos[1] - m_currentPos[1]);

        float mt[3];
        Mat4_Rtxp(mt, m_modelView, t);

        m_center[0] = m_startCenter[0] + mt[0];
        m_center[1] = m_startCenter[1] + mt[1];
        m_center[2] = m_startCenter[2] + mt[2];

        updateEye();
        updateMatrices();
    }
}
예제 #5
0
void StayingBlobSprite::onDraw(const cocos2d::Mat4 &transform, uint32_t transformFlags)
{
    if(_bodies.size() == 0)return;
    Vec2 vertices[NUM_SEGMENTS];
    
    Vec2 opos = this->getPosition();
    
    for(int i = 0; i < _bodies.size(); i++) {
        b2PolygonShape *shape = (b2PolygonShape *) _bodies[i]->GetFixtureList()->GetShape();
        b2Vec2 point;
        if(i < NUM_SEGMENTS / 4)
            point = _bodies[i]->GetWorldVector(shape->GetVertex(0));
        else if(i < NUM_SEGMENTS * 2/4)
            point = _bodies[i]->GetWorldVector(shape->GetVertex(1));
        else if(i < NUM_SEGMENTS * 3/4)
            point = _bodies[i]->GetWorldVector(shape->GetVertex(2));
        else if(i < NUM_SEGMENTS)
            point = _bodies[i]->GetWorldVector(shape->GetVertex(3));
        b2Vec2 pos = _bodies[i]->GetPosition();
        
        vertices[i].x = (point.x + pos.x)*PTM_RATIO - opos.x;
        vertices[i].y = (point.y + pos.y)*PTM_RATIO - opos.y;
    }
    Director* director = Director::getInstance();
    director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
    director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, transform);
    
    //glLineWidth( 5.0f );
    //ccDrawColor4F(1.f, 0.125f, 0.15625f, 1);
    // tiny side burns (...Guesss that one way to call it)
//    for(int i = 0; i < _bodies.size(); i++) {
//        Vec2 target = (center - vertices[i]) * nub_pos;
//        target += center;
//        DrawPrimitives::drawSolidCircle(vertices[i], nub_size, CC_DEGREES_TO_RADIANS(360), 30);
//    }
    
    // draw the body
    //DrawPrimitives::drawSolidPoly(vertices, NUM_SEGMENTS, blobColor);
    DrawPrimitives::drawSolidPoly(vertices, NUM_SEGMENTS, Color4F(1, 1, 1, 1));
    _face->setPosition(this->getCenter() + Vec2(-30, -100)*_face->getScale());
    updateEye();
    CHECK_GL_ERROR_DEBUG();
    
    director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
}
예제 #6
0
//--------------------------------------------------------------
// animate the system
BOOL SolarSystem::animate(
  double now,                       // current time (ms)
  double since)                     // milliseconds since last pass
{
  BOOL changed = m_planet->animate(now, since);
//  changed |= m_belt->animate(now, since);
  changed |= m_moon->animate(now, since);
  changed |= m_ring->animate(now, since);

  m_planetDay += (360.0 * (since/1000.0)) / m_planetDayLen;
  if (m_planetDay > 360.0)
    m_planetDay -= 360.0;

  m_moonDay += (360.0 * (since/1000.0)) / m_moonDayLen;
  if (m_moonDay > 360.0)
    m_moonDay -= 360.0;

  m_ringDay += (360.0 * (since/1000.0)) / m_ringDayLen;
  if (m_ringDay > 360.0)
    m_ringDay -= 360.0;

  m_moonMonth += (360.0 * (since/1000.0)) / m_moonMonthLen;
  if (m_moonMonth > 360.0)
    m_moonMonth -= 360.0;

  m_beltMonth += (360.0 * (since/1000.0)) / m_beltMonthLen;
  if (m_beltMonth > 360.0)
    m_beltMonth -= 360.0;

  // reduce eye rotation on z to zero
  double change = since/25.0;
  if (m_eyeRotZ < -1.0)
    m_eyeRotZ += min(-m_eyeRotZ, change);

  else if (m_eyeRotZ > 1.0)
    m_eyeRotZ -= min(m_eyeRotZ, change);

  else m_eyeRotZ = 0.0;

  updateEye();
  return true;
}
MouseView3D::MouseView3D()
    : m_windowAspect(1.0f)
    , m_fovRads(DEG2RAD(60.0f))
    , m_radius(8)
    , m_mouseLeft(false)
    , m_mouseRight(false)
{
    m_center[0] = 0;
    m_center[1] = 0;
    m_center[2] = 0;

    m_up[0] = 0;
    m_up[1] = 0;
    m_up[2] = 1;

    m_angles[0] = DEG2RAD(180.0f);
    m_angles[1] = DEG2RAD(30.0f);

    m_currentPos[0] = -1.0f;
    m_currentPos[1] = -1.0f;

    updateEye();
    updateMatrices();
}
예제 #8
0
//--------------------------------------------------------------
// change coordinate system
void SolarSystem::changeCoords(
  int newCoords)
{
  if (m_coordSystem == newCoords)
    return;

  // remap the eye angles
  updateEye();
  remapEyeAngles(newCoords);

  m_coordSystem = newCoords;

  // convert eye point to new local coordinates
  mgMatrix4 coords;
  mgPoint3 pt;

  switch (m_coordSystem)
  {
    case COORDS_PLANET:
    {
      coords.rotateYDeg(m_planetDay);

      coords.invertPt(m_eyePt, pt);

      // get height above center of planet
      double ht = pt.length();

      // figure longitude
      double lonRadius = sqrt(pt.z*pt.z + pt.x*pt.x);
      double lonAngle = asin(pt.z/lonRadius);
      if (pt.x < 0)
        lonAngle = PI-lonAngle;
                                                           
      // figure latitude
      double latAngle = asin(pt.y/ht);

      // compute local position from lat/lon
      m_coordPosn.x = ht*cos(latAngle)*cos(lonAngle);
      m_coordPosn.y = ht*sin(latAngle);
      m_coordPosn.z = ht*cos(latAngle)*sin(lonAngle);
      break;
    }

    case COORDS_MOON:
    {
      double angle = (2*PI*m_moonMonth)/360;
      mgPoint3 moonCenter(MOON_DISTANCE*sin(angle), 0, MOON_DISTANCE*cos(angle));
      coords.rotateYDeg(m_moonDay);
      coords.translate(moonCenter.x, moonCenter.y, moonCenter.z);

      coords.invertPt(m_eyePt, pt);

      // get height above center of planet
      double ht = pt.length();

      // figure longitude
      double lonRadius = sqrt(pt.z*pt.z + pt.x*pt.x);
      double lonAngle = asin(pt.z/lonRadius);
      if (pt.x < 0)
        lonAngle = PI-lonAngle;
                                                           
      // figure latitude
      double latAngle = asin(pt.y/ht);

      // compute local position from lat/lon
      m_coordPosn.x = ht*cos(latAngle)*cos(lonAngle);
      m_coordPosn.y = ht*sin(latAngle);
      m_coordPosn.z = ht*cos(latAngle)*sin(lonAngle);
      break;
    }

    case COORDS_RING:
    {
      double angle = (2*PI*m_moonMonth)/360;
      mgPoint3 moonCenter(MOON_DISTANCE*sin(angle), 0, MOON_DISTANCE*cos(angle));

      // get eye in ring-local coordinates
      coords.rotateYDeg(m_ringDay);
      coords.rotateZDeg(RING_ANGLE);
      coords.translate(moonCenter.x, moonCenter.y, moonCenter.z);

      coords.invertPt(m_eyePt, pt);

      double ht = sqrt(pt.z*pt.z + pt.x*pt.x);
      angle = asin(pt.z/ht);
      if (pt.x < 0)
        angle = PI-angle;

      // compute delta from old position
      m_coordPosn.x = ht*cos(angle);
      m_coordPosn.y = pt.y;
      m_coordPosn.z = ht*sin(angle);
      break;
    }

    case COORDS_BELT:
      break;

    case COORDS_SPACE:
      m_coordPosn = m_eyePt;
      break;
  }
}