JonTheBaller
Golden Member
I am writing an app in C# (VS.NET). I am using CsGL for some basic OpenGL stuff. I want to draw an x,y, and z axes in the control, and then rotate the view so that it looks 3D - if you draw the axes and don't rotate them, you wouldn't be able to see the Z axis.
Here's my code, which I based mainly on (http://www.componentsnotebook.com/notebooks/csharp/csgl.aspx). You will see that I called GL.glRotatef(10.0f, 1.0f, 1.0f, 0.0f); at one point. I picked 1.0 for the angle arbitrarily; however, no matter what angle I choose, it only seems to make the axes smaller. Please help, and if there are any questions ask away!
Btw, this is how the axes look before I rotate: http://www.terptrader.com/normalaxis.png
And after I rotate: http://www.terptrader.com/rotatedaxis.png
My goal is to have the axes look 3D, like in this picture: http://wonkosite.ausbone.net/vrml/axis.gif
Here's my code, which I based mainly on (http://www.componentsnotebook.com/notebooks/csharp/csgl.aspx). You will see that I called GL.glRotatef(10.0f, 1.0f, 1.0f, 0.0f); at one point. I picked 1.0 for the angle arbitrarily; however, no matter what angle I choose, it only seems to make the axes smaller. Please help, and if there are any questions ask away!
Btw, this is how the axes look before I rotate: http://www.terptrader.com/normalaxis.png
And after I rotate: http://www.terptrader.com/rotatedaxis.png
My goal is to have the axes look 3D, like in this picture: http://wonkosite.ausbone.net/vrml/axis.gif
protected override void InitGLContext()
{
GL.glClearColor( 1.0f, 1.0f, 1.0f, 0.0f );
GL.glColor3f( 0.0f, 0.0f, 0.0f );
GL.glPointSize( 4.0f );
}
protected override void OnSizeChanged(EventArgs e)
{
base.OnSizeChanged(e);
GL.glMatrixMode(GL.GL_PROJECTION);
GL.glLoadIdentity();
GL.glOrtho( 0.0, Size.Width, 0.0, Size.Height, 1.0, -1.0 );
}
public override void glDraw()
{
GL.glRotatef(10.0f, 1.0f, 1.0f, 0.0f);
drawAxis();
}
private void drawAxis()
{
double left = 0.05 * Size.Width;
double right = 0.95 * Size.Width;
double bottom = 0.05 * Size.Height;
double top = 0.95 * Size.Height;
double origin_x = Size.Width / 2;
double origin_y = Size.Height / 2;
// draw X axis
GL.glBegin( GL.GL_LINES );
GL.glVertex3d( left, origin_x, 0 );
GL.glVertex3d( right, origin_x, 0 );
GL.glEnd();
// draw Y axis
GL.glBegin( GL.GL_LINES );
GL.glVertex3d( origin_y, bottom, 0 );
GL.glVertex3d( origin_y, top, 0 );
GL.glEnd();
// draw Z axis
GL.glBegin( GL.GL_LINES );
GL.glVertex3d( origin_x, origin_y, 0.0 );
GL.glVertex3d( origin_x, origin_y, 1.0 );
GL.glEnd();
GL.glFlush();
}