Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# OpenGL
Hi,
Im drawing a coordinate system in my viewport.
Everything is fine, until I change my view direction (ex. from top view to front view).
When I change my view direction, my bitmapped letters (X, y & Z) are misplacing.
Could anybody help me pls..
 
private void MakeCoordinateSystem()
        {
            double basedia = 0.0004;
            double dd = Math.Min(CurrentViewPortData.clipX, CurrentViewPortData.clipY) / 5.0;
            RemoveModelViewMatrixTranslation();
 
            double[] m = new double[16];
            gl.GetDoublev(gl.MODELVIEW_MATRIX, m);
            gl.LoadIdentity();
            gl.Translated(CurrentViewPortData.clipX - dd * 0.8, CurrentViewPortData.clipY - dd * 0.8, CurrentViewPortData.sphereRadius * 49.0);
            gl.MultMatrixd(m);
 
            IntPtr Qobj = glu.NewQuadric();
 
            gl.Color3f(0.0f, 0.0f, 0.0f);
            glu.Sphere(Qobj, basedia * 1.5 * dd * 100.0, 10, 10);
 
            gl.Color3f(1.0f, 0.0f, 0.0f);
            gl.Rotatef(90.0f, 0.0f, 1.0f, 0.0f);
            glu.Cylinder(Qobj, basedia * dd * 100.0, basedia * dd * 100.0, basedia * 10.0 * dd * 100.0, 10, 10);
            gl.Translated(0.0f, 0.0f, basedia * 10.0 * dd * 100.0);
            gl.Rotatef(180.0f, 0.0f, 1.0f, 0.0f);
            glu.Disk(Qobj, 0.0, basedia * dd * 100.0 * 2.0f, 10, 5);
            gl.Rotatef(-180.0f, 0.0f, 1.0f, 0.0f);
            glu.Cylinder(Qobj, basedia * 2.0 * dd * 100.0, 0.0, basedia * 3.0 * dd * 100.0, 10, 10);
 

            double[] xLocation = new double[3] { 0.0, -basedia * 1.5 * dd * 100.0, basedia * 4.0 * dd * 100.0 };
            double[] yLocation = new double[3] { -basedia * 1.5 * dd * 100.0, 0.0, basedia * 4.0 * dd * 100.0 };
            double[] zLocation = new double[3] { -basedia * dd * 100.0, -basedia * 1.5 * dd * 100.0, basedia * 4.5 * dd * 100.0 };
 
           // GetXYZPositions(ref xLocation, ref yLocation, ref zLocation);

           // double[] StringLoc = { 0.0, -basedia * 0.9*dd * 100.0, basedia * 4.0 * dd * 100.0 };
            byte[] xraster = new byte[] {
            0xc1, 0x80,
            0xc1, 0x80,
            0xc1, 0x80,
            0xc1, 0x80,
            0x63, 0x00,
            0x63, 0x00,
            0x36, 0x00,
            0x36, 0x00,
            0x1c, 0x00,
            0x1c, 0x00,
            0x36, 0x00,
            0x36, 0x00,
            0x63, 0x00,
            0x63, 0x00,
            0xc1, 0x80,
            0xc1, 0x80,
            0xc1, 0x80,
            0xc1, 0x80
            };
            gl.RasterPos3dv(xLocation);
            //GlUtility.GenXList(StringLoc);
            gl.PushMatrix();
            gl.Bitmap(9, 18, 0.0f, 0.0f, 0.0f, 0.0f, xraster);
            gl.PopMatrix();
            gl.Translated(0.0f, 0.0f, -basedia * 10.0 * dd * 100.0);
 

            gl.Color3f(0.0f, 1.0f, 0.0f);
            gl.Rotatef(-90.0f, 0.0f, 1.0f, 0.0f);
            gl.Rotatef(-90.0f, 1.0f, 0.0f, 0.0f);
            glu.Cylinder(Qobj, basedia * dd * 100.0, basedia * dd * 100.0, basedia * 10.0 * dd * 100.0, 10, 10);
            gl.Translated(0.0f, 0.0f, basedia * 10.0 * dd * 100.0);
            gl.Rotatef(180.0f, 1.0f, 0.0f, 0.0f);
            glu.Disk(Qobj, 0.0, basedia * dd * 100.0 * 2.0f, 10, 5);
            gl.Rotatef(-180.0f, 1.0f, 0.0f, 0.0f);
            glu.Cylinder(Qobj, basedia * 2.0 * dd * 100.0, 0.0, basedia * 3.0 * dd * 100.0, 10, 10);
 

            //StringLoc[0] = 0.0;
            //StringLoc[1] = -basedia * 0.9 * dd * 100.0; ;
            //StringLoc[2] = basedia * 4.0 * dd * 100.0;
            gl.RasterPos3dv(yLocation);
            byte[] yraster = new byte[] { 0x1c, 0x00, 0x1c, 0x00, 0x1c, 0x00, 0x1c, 0x00, 0x1c, 0x00, 0x1c, 0x00, 0x1c, 0x00, 0x1c, 0x00, 0x1c, 0x00,
                                          0x14,0x00, 0x36,0x00, 0x36,0x00, 0x63,0x00,0x63,0x00, 0xc1,0x80, 0xc1, 0x80};
 
            gl.PushMatrix();
            gl.Bitmap(9, 18, 0.0f, 0.0f, 0.0f, 0.0f, yraster);
            gl.PopMatrix();
            gl.Translated(0.0f, 0.0f, -basedia * 10.0 * dd * 100.0);
 

            gl.Color3f(0.0f, 0.0f, 1.0f);
            gl.Rotatef(-90.0f, 1.0f, 0.0f, 0.0f);
            gl.Rotatef(180.0f, 0.0f, 1.0f, 0.0f);
            glu.Cylinder(Qobj, basedia * dd * 100.0, basedia * dd * 100.0, basedia * 10.0 * dd * 100.0, 10, 10);
            gl.Translated(0.0f, 0.0f, basedia * 10.0 * dd * 100.0);
            gl.Rotatef(180.0f, 1.0f, 0.0f, 0.0f);
            glu.Disk(Qobj, 0.0, basedia * dd * 100.0 * 2.0f, 10, 5);
            gl.Rotatef(-180.0f, 1.0f, 0.0f, 0.0f);
            glu.Cylinder(Qobj, basedia * 2.0 * dd * 100.0, 0.0, basedia * 3.0 * dd * 100.0, 10, 10);
            gl.Rotatef(180.0f, 0.0f, 0.0f, 1.0f);
 
            //StringLoc[0] = -basedia * 0.5 * dd * 100.0;
            //StringLoc[1] = -basedia * 1.0 * dd * 100.0;
            //StringLoc[2] = basedia * 6.0 * dd * 100.0;
            zLocation[0] = 0.0;
            zLocation[1] = -basedia * 4.0 * dd * 100.0 * .5;
            zLocation[2] = basedia * 6.0 * dd * 100.0 * .866;
            gl.RasterPos3dv(zLocation);
            byte[] zraster = new byte[] {
                                        0xfe, 0x00,
                                        0xfe, 0x00,
                                        0xfe, 0x00,
                                        0xc0, 0x00,
                                        0xc0, 0x00,
                                        0x60, 0x00,
                                        0x60, 0x00,
                                        0x30, 0x00,
                                        0x30, 0x00,
                                        0x18, 0x00,
                                        0x18, 0x00,
                                        0x0c, 0x00,
                                        0x0c, 0x00,
                                        0x06, 0x00,
                                        0x06, 0x00,
                                        0xfe, 0x00,
                                        0xfe, 0x00,
                                        0xfe, 0x00,
                                        0xfe, 0x00
                                        };
            gl.PushMatrix();
            gl.Bitmap(9, 18, 0.0f, 0.0f, 0.0f, 0.0f, zraster);
            gl.PopMatrix();
            //Reset color to black
            gl.Color3f(0.0f, 0.0f, 0.0f);
        }
Posted 2-May-13 23:20pm

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



Advertise | Privacy | Mobile
Web04 | 2.8.141220.1 | Last Updated 3 May 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100