How to create 2D overlay?

nolver

26-02-2006 13:26:33

There's a way to create 2D overlays, as the Rectangle2D seems to be not available?

Thanks!

rastaman

27-02-2006 03:01:08

hi nolver
I haven't use Rectangle2D befor. I see it derives from SimpleRenderable. will there be functions that you need to override to customize it?

I will probubly have to copy all the SimpleRenderableDirector stuff over to a Rectangle2DDirector to allow overriding the functions. I may be able to create a Rectangle2DDirector that derives from SimpleRenderableDirector to simplify it, but not sure if that will work.

nolver

06-03-2006 10:39:18

rastaman:

hi! have you done any advance in the implementation of Rectangle2D?

thank you!

rastaman

06-03-2006 13:48:04

I'v looked at the implementation of Rectangle2D and it doesn't look like you should need to override any functions. so i just simply wrapped it no director. I've been messing with StaticGeometry and can't update cvs right now so here's a quick and dirty.

create a new file OgreNet/OgreRectangle2D.i %{
#include "OgreRectangle2D.h"
%}

%include "OgreRectangle2D.h"



create a new file OgreNet/OgreRectangle.i%{
#include "OgreRectangle.h"
%}

%include "OgreRectangle.h"



then edit OgreNet/OgreBindings.i and add these lines:
after line 85 %include OgreAutoParamDataSource.i add
%include OgreRectangle.i

after line 165 %include OgreSimpleRenderable.i add
%include OgreRectangle2D.i

Then rebuild OgreBindings, make sure it runs swig again.
In Solution Explorer click one of the files in project OgreNet.
Then at the top of the solution explorer window you will see 4 tool bar buttons. Click the third one "Show All Files".
Any file that has a yellow triangle icon with an exclamation mark(!). Right click it and select "Exclude From Project".
Then look for any *.CS file that does not have the greenish icon. Right click it and select "Include In Project".
Now build all the projects.

nolver

22-03-2006 20:00:10

I've been trying to put the Rectangle2D to use, but it produces an aplication exception when I try to create an instance.

I'm using the sources posted some days ago in the forums (because of source forge's downtime).

rastaman

22-03-2006 23:58:14

I ment to come back and make an example to make sure it works, but never got around to it. Anyway here a simple example of using it.
It's just a base ODN example with converted code from the wiki http://www.ogre3d.org/wiki/index.php/Displaying_2D_Backgrounds


using System;
using System.Collections;
using System.Xml;
using System.Drawing;

using Math3D;
using OgreDotNet;

namespace DemoRectangle2D
{

class cDemoRectangle2D : ExampleApplication
{
protected Rectangle2D mRect2d;

protected override void CreateScene()
{
//a ground plane to have something to look at
Entity e;
SceneNode n;
Plane plane = new Plane();
plane.Normal.x=0.0f;
plane.Normal.y=1.0f;
plane.Normal.z=0.0f;
plane.D = 0.0f;
MeshManager.GetSingleton().CreatePlane( "Myplane01", "General" , plane,
500.0f,500.0f, 10,10,true,1, 5.0f,5.0f, Vector3.UnitZ );
e = mSceneManager.CreateEntity( "plane01", "Myplane01" );
e.SetMaterialName("Examples/GrassFloor");
e.SetCastShadows(false);
n = mSceneManager.GetRootSceneNode().CreateChildSceneNode();
n.AttachObject(e);


// Create background material
ResourcePtr rcmaterial = MaterialManager.Instance.create("Background", "General");
MaterialPtr material = new MaterialPtr( ResourcePtr.getCPtr(rcmaterial).Handle , false );
material.GetTechnique(0).getPass(0).createTextureUnitState("rockwall.tga");
material.GetTechnique(0).getPass(0).setDepthCheckEnabled(false);
material.GetTechnique(0).getPass(0).setDepthWriteEnabled(false);

// Disable lighting on the background (it will show as fully lit)
material.GetTechnique(0).getPass(0).setLightingEnabled(false);

// Create background rectangle
mRect2d = new Rectangle2D(true);
// Cover the whole screen
mRect2d.setCorners(-1.0f, 1.0f, 1.0f, -1.0f);
// Hacky, but we need to set the bounding box to something big
mRect2d.setBoundingBox( new AxisAlignedBox(-100000.0f*Math3D.Vector3.UnitScale, 100000.0f*Math3D.Vector3.UnitScale));
mRect2d.setMaterial("Background");
// Render the background before everything else
mRect2d.SetRenderQueueGroup(RenderQueueGroupID.RENDER_QUEUE_BACKGROUND);

// Attach background to the scene
n = mSceneManager.GetRootSceneNode().CreateChildSceneNode("Background");
n.AttachObject(mRect2d);

// Example of background scrolling
material.GetTechnique(0).getPass(0).getTextureUnitState(0).setScrollAnimation(-0.25f, 0.0f);



mCamera.Move( new Vector3(0, 300, 600) );
mCamera.LookAt = new Vector3( 0, 0, 0 );
}

public override void Dispose()
{
mRect2d.Dispose();
mRect2d=null;
base.Dispose();
}

/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
cDemoRectangle2D app = new cDemoRectangle2D();
try
{
app.Start();
}
catch ( Exception ex)
{
Console.WriteLine( "### Exception {0}\n{1}\n{2}", ex.Message ,ex.Source , ex.StackTrace );
}
finally
{
try
{
app.Dispose();
}
catch ( Exception ex)
{
Console.WriteLine( "#### Exception {0}\n{1}\n{2}", ex.Message ,ex.Source , ex.StackTrace );
}
}
}
}
}