Mogre line2d

se5a

01-01-2013 21:43:54

I got this working in a test
ogre3d.org/tikiwiki/tiki-index.php?page=MOGRE+Line+3D

then tried to convert this:
ogre3d.org/tikiwiki/tiki-index.php?page=ManualObject+2D
while referring to the above without success.
(removed prefix in attempt to not have to wait to get this post checked by a mod)

I created a bare bones demo using the tutorial framework as seen below.
as soon as I uncomment identity projection/view lines:
//lineobj.UseIdentityProjection = true;
//lineobj.UseIdentityView = true;

the 2d line does not show up.
what am I missing here?




using Mogre;
using Mogre.TutorialFramework;
using System;



namespace Mogre.Tutorials
{
class Tutorial : BaseApplication
{
public static void Main()
{
new Tutorial().Go();
}

protected override void CreateScene()
{

// create resource group
String resourceGroupName = "debugger";
if (ResourceGroupManager.Singleton.ResourceGroupExists(resourceGroupName) == false)
ResourceGroupManager.Singleton.CreateResourceGroup(resourceGroupName);

// create material (colour)
MaterialPtr moMaterialblue = MaterialManager.Singleton.Create("line_blue", resourceGroupName);
moMaterialblue.ReceiveShadows = false;
moMaterialblue.GetTechnique(0).SetLightingEnabled(true);
moMaterialblue.GetTechnique(0).GetPass(0).SetDiffuse(0, 0, 1, 0);
moMaterialblue.GetTechnique(0).GetPass(0).SetAmbient(0, 0, 1);
moMaterialblue.GetTechnique(0).GetPass(0).SetSelfIllumination(0, 0, 1);
moMaterialblue.Dispose(); // dispose pointer, not the material
MaterialPtr moMaterialred = MaterialManager.Singleton.Create("line_red", resourceGroupName);
moMaterialred.ReceiveShadows = false;
moMaterialred.GetTechnique(0).SetLightingEnabled(true);
moMaterialred.GetTechnique(0).GetPass(0).SetDiffuse(1, 0, 0, 0);
moMaterialred.GetTechnique(0).GetPass(0).SetAmbient(1, 0, 0);
moMaterialred.GetTechnique(0).GetPass(0).SetSelfIllumination(1, 0, 0);
moMaterialred.GetTechnique(0).GetPass(0).DepthCheckEnabled = false;
moMaterialred.GetTechnique(0).GetPass(0).DepthWriteEnabled = false;
moMaterialred.GetTechnique(0).GetPass(0).LightingEnabled = false;
moMaterialred.Dispose(); // dispose pointer, not the material


// create line object
ManualObject manOb = mSceneMgr.CreateManualObject("line");
manOb.Begin("line_blue", RenderOperation.OperationTypes.OT_LINE_LIST);
manOb.Position(0, 0, 0);
manOb.Position(100, 100, 0);
// ... maybe more points
manOb.End();

// create SceneNode and attach the line
SceneNode moNode = mSceneMgr.RootSceneNode.CreateChildSceneNode("line_node");
moNode.SetPosition(0,0,0);
moNode.AttachObject(manOb);



ManualObject lineobj = mSceneMgr.CreateManualObject("line2");
//lineobj.UseIdentityProjection = true;
//lineobj.UseIdentityView = true;
lineobj.Begin("line_red", RenderOperation.OperationTypes.OT_LINE_LIST);
lineobj.Position(5, 5, 5);
lineobj.Position(105, 105, 5);
// ... maybe more points
lineobj.End();

AxisAlignedBox aabInf = new AxisAlignedBox();
aabInf.SetInfinite();
lineobj.BoundingBox = aabInf;

//mNode = mSceneMgr.RootSceneNode.CreateChildSceneNode().CreateChildSceneNode("lineobj", new Vector3(0, 0, 0));
//SceneNode moNode2 = mSceneMgr.RootSceneNode.CreateChildSceneNode("line_node2");
//moNode.SetPosition(0, 0, 0);
//moNode.AttachObject(lineobj);
mSceneMgr.RootSceneNode.CreateChildSceneNode().AttachObject(lineobj);

}
protected override void CreateCamera()
{
mCamera = mSceneMgr.CreateCamera("PlayerCam");
mCamera.Position = new Vector3(0, 10, 500);
mCamera.LookAt(Vector3.ZERO);
mCamera.NearClipDistance = 5;
mCameraMan = new CameraMan(mCamera);
}
protected override void CreateViewports()
{
Viewport viewport = mWindow.AddViewport(mCamera);
viewport.BackgroundColour = ColourValue.Black;
mCamera.AspectRatio = viewport.ActualWidth / viewport.ActualHeight;
}
}
}

se5a

01-01-2013 21:51:57

Ok never mind I've just figured it out.
when using identity projection/view
the coords are from the center of the screen, ie camera. rather than the top left as I for some reason expected.

what are the units though? defiantly not pixels.

se5a

01-01-2013 22:02:50

What I'd like to do, is draw a line from an overlay (viewscreen coordinates) to an entity/node(world coordinates)
whats the best way to go about doing this?

I'm thinking I need to find the world coordinates of a specific spot on the viewport. then draw a line from that to the object.
but how would I go about finding the world coordinates of a spot on the viewport?
esp since I'm probably going to want to move the overly around.