3d - opentk pitch rotation deforms the shape -


i'm using opentk in c# render 3d surface , rotate it. yaw works fine, pitch rotation (tilting object towards camera) causes surface deform. enter image description here

the image on left i'm rendering deformed , 1 one right correct. note when pitch zero, looks fine. here gist of code:

private void glcontrol1_paint(object sender, painteventargs e) {     gl.clear(clearbuffermask.colorbufferbit | clearbuffermask.depthbufferbit);     matrix4 perspective = matrix4.createperspectivefieldofview(1.0f, aspect_ratio, 1.0f, 10000.0f); //setup perspective [fovy, aspect, znear, zfar]     matrix4 lookat = matrix4.lookat(eye_pos.x, eye_pos.y, eye_pos.z, 0, 0, 0, 0, 0, 1); //setup camera   [eyex, eyey, eyez, targetx, targety, targetz, upx, upy, upz)]      gl.matrixmode(matrixmode.projection); //load perspective     gl.loadidentity();     gl.viewport(0, 0, this.clientsize.width, this.clientsize.height);     gl.loadmatrix(ref perspective);     gl.matrixmode(matrixmode.modelview); //load camera     gl.loadidentity();     gl.loadmatrix(ref lookat);     gl.viewport(0, 0, glcontrol1.width, glcontrol1.height); //size of window     gl.enable(enablecap.depthtest); //enable correct z drawings     gl.depthfunc(depthfunction.less); //enable correct z drawings      //rotating     vector2 xy_view_vector = new vector2(eye_pos.x, eye_pos.y);     xy_view_vector.normalize();     vector2 fold_vec = xy_view_vector.perpendicularleft; // line on you'd tilt view forward towards camera     gl.rotate((float)numericupdown2.value, fold_vec.x, fold_vec.y, 0.0f);// pitch (tilt forward)     gl.rotate((float)numericupdown1.value, 0.0f, 0.0f, 1.0f);// yaw rotation - z       // axes     gl.begin(primitivetype.lines);     gl.color3(color.white);     gl.vertex3(-10, 0, 0);     gl.vertex3(10, 0, 0);     gl.vertex3(0, -10, 0);     gl.vertex3(0, 10, 0);     gl.vertex3(0, 0, -10);     gl.vertex3(0, 0, 10);     gl.end();      int i2, j2;     float z1, z2, z3, z4;     gl.begin(primitivetype.quads);     (int = 0; < data.x.count - 2; i++)     {         (int j = 0; j < data.y.count - 2; j++)         {             i2 = + 1;             j2 = j + 1;             z1 = data.z[i.tostring() + "," + j.tostring()];             z2 = data.z[i2.tostring() + "," + j.tostring()];             z3 = data.z[i2.tostring() + "," + j2.tostring()];             z4 = data.z[i.tostring() + "," + j2.tostring()];             gl.color4(color_map.getcolor((z1 + z3) / 2, data.minz, data.maxz, opacity));              gl.vertex3(new vector3(data.x[i], data.y[j], z1));             gl.vertex3(new vector3(data.x[i2], data.y[j], z2));             gl.vertex3(new vector3(data.x[i2], data.y[j2], z3));             gl.vertex3(new vector3(data.x[i], data.y[j2], z4));         }     }     gl.end();      graphicscontext.currentcontext.vsync = true; //caps frame rate not on run gpu     glcontrol1.swapbuffers(); //takes 'gl' , puts control } 

i wondering if has clue why happening. having simple pitch/yaw rotation sample - if know opentk sample can help, i'd appreciate linking it.

i can not tell doing wrong, can paste code use rotate camera around object @ origin:

void setupperspective() {     var aspectratio = width / (float)height;     projection = matrix4.createperspectivefieldofview(mathhelper.piover4, aspectratio, 0.1f, 10);     modelview = matrix4.identity;     // apply camera transform     camera.applycamera(ref modelview); }  void applycamera(ref matrix4 modelview) {     modelview = matrix4.createrotationy(yaw)         * matrix4.createrotationx(pitch)         * matrix4.createrotationz(roll)         * matrix4.createtranslation(-position)         * modelview; } 

i don't use fixed-function pipeline set resulting projection , modelview matrices you're doing it.


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -