Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 5 of 5

Thread: Drawing lines in 3D space

  1. #1
    Junior Member Newbie
    Join Date
    Jul 2013
    Posts
    8

    Drawing lines in 3D space using mouse

    Hello everyone!
    I'm having a bit of trouble figuring out how to draw a line in 3D space.
    What I want to do is allow the user to use their mouse to draw a line anywhere in the 3D space.
    They would left-click, hold it, and drag the mouse, as they drag the mouse the line would follow the cursor
    to where ever the new mouse position will be located.
    when they release the mouse button, the line should be created.
    here is a snippit of my codes:

    Code :
         public static void MousePos(System.Drawing.Point pt)
            {
                Vector mousePosInit = sceneCamera.LevelToLocal(new Vector(pt.X, pt.Y, .01));
                initialPosX = mousePosInit.X; 
                initialPosY = mousePosInit.Y; 
            }    
     
             public static void UpdatePos(System.Drawing.Point pt)
            {
                Vector mousePosFinal = sceneCamera.LevelToLocal(new Vector(pt.X, pt.Y, .01));
                finalVectorX = mousePosFinal.X; 
                finalVectorY = mousePosFinal.Y;
            }
     
            public static void Render()
            {
     
                GL.LineWidth(5.0f);
                GL.Enable(EnableCap.LineSmooth);
                GL.Begin(BeginMode.Lines); 
                GL.Vertex2(initialPosX, initialPosY);
                GL.Vertex2(finalVectorX, finalVectorY);
                GL.End();
                GL.LineWidth(1.0f);
            }
     
            private static ISE.Scenes.Camera sceneCamera = SceneManager.CurrentCamera;
            private static double initialPosX, initialPosY;
            private static double finalVectorX, finalVectorY;
    I'm using OpenTK as a wrapper since I'm coding it in C#.
    I also use Icarus Scene Engine 3 to do all the camera, and rendering work.
    Thanks for all the help!
    Last edited by ducle91; 07-25-2013 at 12:20 PM.

  2. #2
    Senior Member OpenGL Pro
    Join Date
    Jan 2012
    Location
    Australia
    Posts
    1,104
    Does Icarus Scene Engine 3 clear the clear before calling your render code? Also how do you control your projection? For your code to render as expected you need an orthogonal projection.

  3. #3
    Junior Member Newbie
    Join Date
    Jul 2013
    Posts
    8
    I did use ortho-projection, but i didn't have any luck either. I've been looking around online and most suggest use Matrix projection and Ortho-projection to allow the user to draw the lines. But when I used Matrix Projection, i just get an empty blue screen(my program uses a skybox texture) so i want to keep the skybox texture there as well.

    here is an attached image:
    I have a skybox, and I also have a grid that was all rendered. The thick white line you see can only be drawn at that certain angle and if I change my camera anywhere else, I can't draw. The lines can ONLY be drawn horizontally as well, I can't draw vertically at all.
    https://www.dropbox.com/s/wrhr7frk2p...ScreenShot.png
    Last edited by ducle91; 07-26-2013 at 03:08 PM.

  4. #4
    Senior Member OpenGL Pro
    Join Date
    Jan 2012
    Location
    Australia
    Posts
    1,104
    I would expect to see the ortho-projection matrix for the line render to be set inside the subroutine "Render()" since the skybox will be using a different projection matrix

  5. #5
    Junior Member Newbie
    Join Date
    Jul 2013
    Posts
    8
    i did implement GL.Ortho() but for some reason I cannot get the line to draw....

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •