查看单个帖子
旧 2007-03-13, 02:42 PM   #1
huangyhg
超级版主
 
huangyhg的头像
 
注册日期: 04-03
帖子: 18592
精华: 36
现金: 249466 标准币
资产: 1080358888 标准币
huangyhg 向着好的方向发展
默认 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();
}
//------------------------------------------------------------------------
__________________
借用达朗贝尔的名言:前进吧,你会得到信心!
[url="http://www.dimcax.com"]几何尺寸与公差标准[/url]
huangyhg离线中   回复时引用此帖
GDT自动化论坛(仅游客可见)