void BSplineSurfaceView::NewPickedObject()
{
    int cx = m_pickedName >> 16;
    int cy = m_pickedName & 0xFFFF;

    GLdouble model_view[16];
    glGetDoublev(GL_MODELVIEW_MATRIX, model_view);

    GLdouble projection[16];
    glGetDoublev(GL_PROJECTION_MATRIX, projection);

    GLint viewport[4];
    glGetIntegerv(GL_VIEWPORT, viewport);


    Vertex3d cpWorld = Vertex3d(m_controlPoints[cx][cy]); // control point in world coordinates
    Vertex3d cpScreen = Vertex3d(); // control point in screen coordinates
    gluProject(cpWorld.X(),cpWorld.Y(),cpWorld.Z(),model_view,projection,viewport,cpScreen.XRef(),cpScreen.YRef(),cpScreen.ZRef());

    // Mouse offset to control point to maintain relative distance. - NOT WORKING
    m_dragOffsetX = 0;//m_lastMouseX - cpScreen.X();
    m_dragOffsetY = 0;//(viewport[3]-m_lastMouseY) - cpScreen.Y();

    m_pickedZ = cpScreen.Z();
}
BSplineSurfaceView::BSplineSurfaceView(QWidget *parent) :
    ModelView(parent)
{
    m_maxFps = 0;

    int w=5,h=5;

    float cw = ((w-1)/2.0),ch = ((h-1)/2.0); // center w and h offsets

    for(int x=0;x<w;x++)
    {
        vector<Vertex3d> row;
        for(int z=0;z<h;z++)
        {
            Vertex3d v = Vertex3d(10*(x-cw),-((x-cw)*(x-cw)+(z-ch)*(z-ch))*2,10*(z-ch));
            row.push_back(v);
        }

        m_controlPoints.push_back(row);
    }

    m_bSpline.RefreshPoints(m_controlPoints);
    update();

     m_dragOffsetX = 0;
     m_dragOffsetY = 0;
}
void BSplineSurfaceView::UpdatePickedObject(double dx, double dy)
{
    int cx = m_pickedName >> 16;
    int cy = m_pickedName & 0xFFFF;

    GLdouble model_view[16];
    glGetDoublev(GL_MODELVIEW_MATRIX, model_view);

    GLdouble projection[16];
    glGetDoublev(GL_PROJECTION_MATRIX, projection);

    GLint viewport[4];
    glGetIntegerv(GL_VIEWPORT, viewport);

    Vertex3d cpWorld = Vertex3d(); // control point in world coordinates
    int x = m_lastMouseX - m_dragOffsetX;
    int y = (viewport[3] - m_lastMouseY) - m_dragOffsetY;
    gluUnProject(x,y,m_pickedZ,model_view,projection,viewport,cpWorld.XRef(),cpWorld.YRef(),cpWorld.ZRef());

    m_controlPoints[cx][cy] = cpWorld;

    //Vertex3d v = Vertex3d(dx*0.1, dy*0.1, 0);
    //m_controlPoints[cx][cy] += v;

    int resolution = 128;
    if(m_draggingPoint)
        resolution = 16;

    m_bSpline.RefreshPoints(m_controlPoints, resolution);
    update();
}
void BSplineSurfaceView::AddColumn()
{
    for(int z=0;z<m_controlPoints.size();z++)
    {
        Vertex3d v;

        Vertex3d neighbor = m_controlPoints[z][m_controlPoints[z].size()-1];
        v = Vertex3d(neighbor.X(),neighbor.Y(),neighbor.Z()+10);

        m_controlPoints[z].push_back(v);
    }

    m_bSpline.RefreshPoints(m_controlPoints);
    update();

}
void BSplineSurfaceView::AddRow()
{
    vector<Vertex3d> newRow;

    for(int x=0;x<m_controlPoints[0].size();x++)
    {
        Vertex3d v;

        Vertex3d neighbor = m_controlPoints[m_controlPoints.size()-1][x];
        v = Vertex3d(neighbor.X()+10,neighbor.Y(),neighbor.Z());

        newRow.push_back(v);
    }

    m_controlPoints.push_back(newRow);

    m_bSpline.RefreshPoints(m_controlPoints);
    update();
}
Exemple #6
0
////////////////////////////////////////////////////////////////
// P. 109
//int asdf = 0;
core::ResultCode Insert::restoreFull(ISchema& schema, DWGBuffer& buffer, const Colour& colour, const Handle& handle, const Version& version) const
{
  const double translationX = buffer.readBitDouble();
  const double translationY = buffer.readBitDouble();
  const double translationZ = buffer.readBitDouble();
//  LOG_DEBUG("[" << translationX << ", " << translationY << ", " << translationZ << "]");

  double scaleX = 1.;
  double scaleY = 1.;
  double scaleZ = 1.;

  if (version.isBetween(Version::R13, Version::R14))
  {
    scaleX = buffer.readBitDouble();
    scaleY = buffer.readBitDouble();
    scaleZ = buffer.readBitDouble();
  }

  if (version.isAtLeast(Version::R2000))
  {
    int flags = buffer.readBit2();
    if (!(flags & 0x01))
    {
      scaleX = buffer.readRawDouble();
      scaleY = scaleX;
      scaleZ = scaleX;
    }

    if (!(flags & 0x02))
    {
      buffer.readBitDouble(scaleY);
      buffer.readBitDouble(scaleZ);
    }
  }
//    LOG_DEBUG("[" << scaleX << ", " << scaleY << ", " << scaleZ << "]");

  // Rotation + axis
  const double rotation = buffer.readBitDouble();
  const double axisX = buffer.readBitDouble();
  const double axisY = buffer.readBitDouble();
  const double axisZ = buffer.readBitDouble();
//  LOG_ERROR(rotation << "[rad] [" << axisX << ", " << axisY << ", " << axisZ << "]");
  bool hasAttrib = buffer.readBit();
//  LOG_ERROR("Has attribute " << hasAttrib);

  if (version.isAtLeast(Version::R2004))
  {
    int numObj = buffer.readBit32();
    LOG_DEBUG(numObj);
  }

  Handle h = buffer.readHandle();
//  LOG_DEBUG("Handle: " << h.getCode() << " => " << h.getValue());

  try {
//    Handle i = buffer.readHandle();
//    LOG_DEBUG("H2: " << i.getCode() << " => " << i.getValue());
//    Handle j = buffer.readHandle();
//    LOG_DEBUG("H3: " << j.getCode() << " => " << j.getValue());
  } catch (...) {
  }

  schema.insert(h.getValue(), Vertex3d(axisX, axisY, axisZ), rotation,
                                 Vertex3d(scaleX, scaleY, scaleZ),
                                 Vertex3d(translationX, translationY, translationZ));
//LOG_ERROR(++asdf);
//if (++asdf > 138)
//return core::rcFailure;
  return core::rcSuccess;
}
Exemple #7
0
	void Vertex3d(double x, double y, double z)
	{
		Vertex3d((float)x, (float)y, (float)z);
	}