materialDefender
26-01-2010 04:45:59
To all of you Mogre users out there using MogreNewt:
How did you learn how to use MogreNewt?
I've tried about every combination of Mogre/MogreNewt I could find, I've searched the forums, I've tried to find MogreNewt tutorials, and I've looked through many samples (they use some sort of sample application framework that I don't have).
My latest attempt gave me an Access Violation Exception at this line (using Mogre SDK 1.4.8 and its packaged version of MogreNewt):
I'd be wonderfully happy if you could point out some problem with this, I'd be just as happy if you could tell me a way to use MogreNewt with Mogre to detect convex hull collisions.
My entire code, for your perusal (much is commented due to constant revision):
How did you learn how to use MogreNewt?
I've tried about every combination of Mogre/MogreNewt I could find, I've searched the forums, I've tried to find MogreNewt tutorials, and I've looked through many samples (they use some sort of sample application framework that I don't have).
My latest attempt gave me an Access Violation Exception at this line (using Mogre SDK 1.4.8 and its packaged version of MogreNewt):
Body body = new Body(world, col, true);
I'd be wonderfully happy if you could point out some problem with this, I'd be just as happy if you could tell me a way to use MogreNewt with Mogre to detect convex hull collisions.
My entire code, for your perusal (much is commented due to constant revision):
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using System.Drawing;
using MogreNewt;
using Mogre;
namespace PuzzleSolver
{
static class Program
{
[STAThread]
static void Main()
{
OgreStartup ogre = new OgreStartup();
ogre.Go();
}
}
class OgreStartup
{
Root root = null;
World world; //MogreNewt
float ticks = 0;
public void Go()
{
CreateRoot();
DefineResources();
SetupRenderSystem();
CreateRenderWindow();
InitializeResourceGroups();
CreateScene();
StartRenderLoop();
}
void CreateRoot()
{
try
{
root = new Root();
}
catch (System.Runtime.InteropServices.SEHException)
{
if (OgreException.IsThrown)
MessageBox.Show(OgreException.LastException.FullDescription,
"An Ogre exception has occurred!");
else
throw;
}
world = new World(); //MogreNewt
}
void DefineResources()
{
ConfigFile configFile = new ConfigFile();
configFile.Load("resources.cfg", "\t:=", true);
ConfigFile.SectionIterator seci = configFile.GetSectionIterator();
String secName, typeName, archName;
while (seci.MoveNext())
{
secName = seci.CurrentKey;
ConfigFile.SettingsMultiMap settings = seci.Current;
foreach (KeyValuePair<string, string> pair in settings)
{
typeName = pair.Key;
archName = pair.Value;
ResourceGroupManager.Singleton.AddResourceLocation(archName, typeName, secName);
}
}
}
void SetupRenderSystem()
{
RenderSystem renderSystem = root.GetRenderSystemByName("Direct3D9 Rendering Subsystem");
root.RenderSystem = renderSystem;
renderSystem.SetConfigOption("Full Screen", "No");
renderSystem.SetConfigOption("Video Mode", "640 x 480 @ 32-bit colour");
}
void CreateRenderWindow()
{
root.Initialise(true, "3D Puzzle Solver");
}
void InitializeResourceGroups()
{
TextureManager.Singleton.DefaultNumMipmaps = 5;
ResourceGroupManager.Singleton.InitialiseAllResourceGroups();
}
private void CreateScene()
{
SceneManager mgr = root.CreateSceneManager(SceneType.ST_GENERIC);
Camera cam = mgr.CreateCamera("Camera");
cam.NearClipDistance = 2;
cam.FarClipDistance = 2000;
root.AutoCreatedWindow.AddViewport(cam);
//Each point in a piece is 2 Mogre units (1 BU = 2 MU)
Entity piece1 = mgr.CreateEntity("Piece1", "Piece1.mesh");
mgr.RootSceneNode.CreateChildSceneNode().AttachObject(piece1);
Entity piece2 = mgr.CreateEntity("Piece2", "Piece2.mesh");
mgr.RootSceneNode.CreateChildSceneNode().AttachObject(piece2);
/*Entity piece3 = mgr.CreateEntity("Piece3", "Piece3.mesh");
mgr.RootSceneNode.CreateChildSceneNode().AttachObject(piece3);
Entity piece4 = mgr.CreateEntity("Piece4", "Piece4.mesh");
mgr.RootSceneNode.CreateChildSceneNode().AttachObject(piece4);
Entity piece5 = mgr.CreateEntity("Piece5", "Piece5.mesh");
mgr.RootSceneNode.CreateChildSceneNode().AttachObject(piece5);
Entity piece6 = mgr.CreateEntity("Piece6", "Piece6.mesh");
mgr.RootSceneNode.CreateChildSceneNode().AttachObject(piece6);
Entity piece7 = mgr.CreateEntity("Piece7", "Piece7.mesh");
mgr.RootSceneNode.CreateChildSceneNode().AttachObject(piece7);//*/
cam.Position = new Vector3(0, 0, -20);
cam.LookAt(new Vector3(0,0,0));
root.FrameEnded += new FrameListener.FrameEndedHandler(FrameEnded);
ticks = Environment.TickCount;
Collision col = new Collision(world); //MogreNewt
Body body = new Body(world, col, true); //MogreNewt
//Body bod = new Body(world, col, true);
//bod.AttachToNode(piece1.ParentNode);
//MogreNewt.CollisionPrimitives.ConvexHull colHull = new MogreNewt.CollisionPrimitives.ConvexHull(world, piece1.ParentSceneNode);
// the last param is only for Newton 2, remove it if you use Newton 1.x
//bod.Collision = colHull;
/*MogreNewt.CollisionPrimitives.ConvexHull hull = new MogreNewt.CollisionPrimitives.ConvexHull(world, piece1.ParentSceneNode, 0.0f, 0);
MogreNewt.Body bod = new MogreNewt.Body(world, hull);
bod.AttachNode(piece1.ParentNode);//*/
}
void StartRenderLoop()
{
while (!root.AutoCreatedWindow.IsClosed && root.RenderOneFrame())
Application.DoEvents();
world.Dispose();
root.Dispose();
}
bool FrameEnded(FrameEvent evt)
{
return true;
}
}
}