首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >疯狂的SharpGL

疯狂的SharpGL
EN

Stack Overflow用户
提问于 2009-09-10 21:12:12
回答 1查看 2.8K关注 0票数 1

我已经将这段代码从C++/OpenGL移植到了C# SharpGL:

代码语言:javascript
复制
float[] cameraAngle = { 0, 0, 0 };
        float[] cameraPosition = { 0, 0, 10 };
        float[] modelPosition = { 0, 0, 0 };
        float[] modelAngle = { 0, 0, 0 };

        float[] matrixView = new float[16];
        float[] matrixModel = new float[16];
        float[] matrixModelView = new float[16];

        // clear buffer
        gl.ClearColor(0.1f, 0.1f, 0.1f, 1);
        gl.Clear(OpenGL.COLOR_BUFFER_BIT | OpenGL.DEPTH_BUFFER_BIT | OpenGL.STENCIL_BUFFER_BIT);

        // initialze ModelView matrix
        gl.PushMatrix();
        gl.LoadIdentity();

        // ModelView matrix is product of viewing matrix and modeling matrix
        // ModelView_M = View_M * Model_M
        // First, transform the camera (viewing matrix) from world space to eye space
        // Notice all values are negated, because we move the whole scene with the
        // inverse of camera transform
        gl.Rotate(-cameraAngle[0], 1, 0, 0); // pitch
        gl.Rotate(-cameraAngle[1], 0, 1, 0); // heading
        gl.Rotate(-cameraAngle[2], 0, 0, 1); // roll
        gl.Translate(-cameraPosition[0], -cameraPosition[1], -cameraPosition[2]);

        // we have set viewing matrix upto this point. (Matrix from world space to eye space)
        // save the view matrix only
        gl.GetFloat(OpenGL.MODELVIEW_MATRIX, matrixView); // save viewing matrix
        //=========================================================================
        // always Draw the grid at the origin (before any modeling transform)
        //DrawGrid(10, 1);

        // In order to get the modeling matrix only, reset OpenGL.MODELVIEW matrix
        gl.LoadIdentity();

        // transform the object
        // From now, all transform will be for modeling matrix only. (transform from object space to world space)
        gl.Translate(modelPosition[0], modelPosition[1], modelPosition[2]);
        gl.Rotate(modelAngle[0], 1, 0, 0);
        gl.Rotate(modelAngle[1], 0, 1, 0);
        gl.Rotate(modelAngle[2], 0, 0, 1);

        // save modeling matrix
        gl.GetFloat(OpenGL.MODELVIEW_MATRIX, matrixModel);
        //=========================================================================
        // re-strore OpenGL.MODELVIEW matrix by multiplying matrixView and matrixModel before drawing the object
        // ModelView_M = View_M * Model_M
        gl.LoadMatrixf(matrixView);              // Mmv = Mv
        gl.MultMatrixf(matrixModel);             // Mmv *= Mm

        // save ModelView matrix
        gl.GetFloat(OpenGL.MODELVIEW_MATRIX, matrixModelView);
        //=========================================================================

        // Draw a teapot after ModelView transform
        // v' = Mmv * v
        //DrawAxis(4);
        //DrawTeapot();

        gl.PopMatrix();

看起来ModelView矩阵并没有被相乘,结果是单位矩阵!

会出什么问题??

谢谢

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2009-09-15 13:55:39

错误的glMatrixMode?

票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/1407759

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档