![]() |
How SolidWorks Xform relates to OpenGL transformation matrix
/*
Description: How SolidWorks Xform relates to OpenGL transformation matrix Problem: There are several SolidWorks APIs which return a transform: Body2::SetXform Component2::GetXform ModelView::Xform which all return an array of 16 doubles. The meaning of each of the values is documented but it is not clear how these values correspond to the "standard" OpenGL transformation matrix. Knowledge of this is typically needed when drawing directly into the SolidWorks OpenGL window. Solution: The relationship between the SolidWorks and OpenGL transformations is shown in the following code fragments. Note that there is an AutoMatrix class which automatically pushes and pops the OpenGL matrices. */ //------------------------------------------------------------------------ void swViewEvents::DoComponentDisplay(CComPtr <IComponent2> pComp) { double ChildXform[16]; GLdouble OpenGLmatrix[16]; GLdouble nScaling; AutoMatrix Matrix; hr = pChildComp->IGetXform(ChildXform); // convert from SW matrix to OpenGL matrix nScaling = ChildXform [12]; OpenGLmatrix[ 0] = nScaling * ChildXform[ 0]; OpenGLmatrix[ 1] = nScaling * ChildXform[ 1]; OpenGLmatrix[ 2] = nScaling * ChildXform[ 2]; OpenGLmatrix[ 3] = 0.0; OpenGLmatrix[ 4] = nScaling * ChildXform[ 3]; OpenGLmatrix[ 5] = nScaling * ChildXform[ 4]; OpenGLmatrix[ 6] = nScaling * ChildXform[ 5]; OpenGLmatrix[ 7] = 0.0; OpenGLmatrix[ 8] = nScaling * ChildXform[ 6]; OpenGLmatrix[ 9] = nScaling * ChildXform[ 7]; OpenGLmatrix[10] = nScaling * ChildXform[ 8]; OpenGLmatrix[11] = 0.0; OpenGLmatrix[12] = ChildXform[ 9]; OpenGLmatrix[13] = ChildXform[10]; OpenGLmatrix[14] = ChildXform[11]; OpenGLmatrix[15] = 1.0; // apply component Xform to OpenGL matrix glMultMatrixd(OpenGLmatrix); // do some OpenGL drawing } //------------------------------------------------------------------------ //------------------------------------------------------------------------ // class AutoMatrix // automatically pushes matrix on creation and pops matrix on destruction class AutoMatrix { private: GLint m_MatrixMode; public: AutoMatrix(); ~AutoMatrix(); }; //------------------------------------------------------------------------ //------------------------------------------------------------------------ // class AutoMatrix // automatically pushes matrix on creation and pops matrix on destruction AutoMatrix::AutoMatrix() { glGetIntegerv(GL_MATRIX_MODE, &m_MatrixMode); glPushMatrix(); glMatrixMode(GL_MODELVIEW); GLenum glErrCode = glGetError(); } //------------------------------------------------------------------------ AutoMatrix::~AutoMatrix() { glMatrixMode(m_MatrixMode); glPopMatrix(); GLenum glErrCode = glGetError(); } //------------------------------------------------------------------------ |
所有的时间均为北京时间。 现在的时间是 06:09 AM. |