PDA

View Full Version : Drawing lines in 3D space



ducle91
07-25-2013, 10:32 AM
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:


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!

tonyo_au
07-25-2013, 07:42 PM
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.

ducle91
07-26-2013, 08:15 AM
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/wrhr7frk2pn8pct/ScreenShot.png

tonyo_au
07-29-2013, 12:25 AM
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

ducle91
07-29-2013, 07:11 AM
i did implement GL.Ortho() but for some reason I cannot get the line to draw....