Noob Problems using VS2005

Problems building or running the engine, queries about how to use features etc.
User avatar
KungFooMasta
OGRE Contributor
OGRE Contributor
Posts: 2087
Joined: Thu Mar 03, 2005 7:11 am
Location: WA, USA
x 16

Noob Problems using VS2005

Post by KungFooMasta »

I'm new to using windows forms, but I'm trying to make a windows application similar to the OgreDotNet demo application (but written in VC++).

I started my project by doing:
New->Project->Windows Forms Application

The following files are given to me:

Header Files:

MainWindow.h (I named this, instead of default Form1)
resource.h
stdafx.h

Resource Files:

app.ico
app.rc

Source Files:

AssemblyInfo.cpp
SceneCreator.cpp (I named this)
stdafx.cpp

So I played around with my main form and put in some buttons and what not, now I want to try and have Ogre render to a control.

Here is my SceneCreator.cpp:

Code: Select all

#include "stdafx.h"
#include "MainWindow.h"

#include <iostream>
#include <string>
#include <windows.h>

#include "Ogre.h"

using namespace SceneCreator;

[STAThreadAttribute]
int main(array<System::String ^> ^args)
{
	// Enabling Windows XP visual effects before any controls are created
	Application::BRAND NAME();
	Application::SetCompatibleTextRenderingDefault(false); 

	// Create the main window and run it
	Application::Run(gcnew MainWindow());

	return 0;
}
Here are the errors:

Code: Select all

1>------ Build started: Project: SceneCreator, Configuration: Release Win32 ------
1>Compiling...
1>SceneCreator.cpp
1>Linking...
1>SceneCreator.obj : error LNK2001: unresolved external symbol "public: __clrcall Ogre::Exception::Exception(class Ogre::Exception const &)" (??0Exception@Ogre@@$$FQAM@ABV01@@Z)
1>SceneCreator.obj : error LNK2001: unresolved external symbol "public: __clrcall Ogre::ParameterDef::~ParameterDef(void)" (??1ParameterDef@Ogre@@$$FQAM@XZ)
1>SceneCreator.obj : error LNK2001: unresolved external symbol "public: __clrcall Ogre::ParameterDef::ParameterDef(class Ogre::ParameterDef const &)" (??0ParameterDef@Ogre@@$$FQAM@ABV01@@Z)
1>SceneCreator.obj : error LNK2001: unresolved external symbol "public: __clrcall Ogre::ParamDictionary::ParamDictionary(class Ogre::ParamDictionary const &)" (??0ParamDictionary@Ogre@@$$FQAM@ABV01@@Z)
1>SceneCreator.obj : error LNK2001: unresolved external symbol "public: __clrcall Ogre::Exception::~Exception(void)" (??1Exception@Ogre@@$$FQAM@XZ)
1>SceneCreator.obj : error LNK2001: unresolved external symbol "public: __clrcall Ogre::GpuProgramParameters::~GpuProgramParameters(void)" (??1GpuProgramParameters@Ogre@@$$FQAM@XZ)
1>SceneCreator.obj : error LNK2001: unresolved external symbol "public: __clrcall Ogre::ParamDictionary::~ParamDictionary(void)" (??1ParamDictionary@Ogre@@$$FQAM@XZ)
1>SceneCreator.obj : error LNK2001: unresolved external symbol "public: __clrcall Ogre::Vector4::Vector4(class Ogre::Vector4 const &)" (??0Vector4@Ogre@@$$FQAM@ABV01@@Z)
1>C:\Documents and Settings\Ben\My Documents\Visual Studio 2005\Projects\SceneCreator\Release\SceneCreator.exe : fatal error LNK1120: 8 unresolved externals
1>Build log was saved at "file://c:\Documents and Settings\My Documents\Visual Studio 2005\Projects\SceneCreator\SceneCreator\Release\BuildLog.htm"
1>SceneCreator - 9 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
the problems occur when adding the "include "Ogre.h" line.

And yes, I have linked in Ogremain.lib. It's set to release, and I set all of the properties as described in
http://www.ogre3d.org/wiki/index.php/Newbie_Tutorial_2

Any help is appreciated
User avatar
Yaniv
Halfling
Posts: 65
Joined: Thu Mar 02, 2006 1:28 am
Location: Israel

Post by Yaniv »

Have you tried debug mode using OgreMain_d.lib? Does that work?
User avatar
KungFooMasta
OGRE Contributor
OGRE Contributor
Posts: 2087
Joined: Thu Mar 03, 2005 7:11 am
Location: WA, USA
x 16

Post by KungFooMasta »

I tried compiling on release and debug mode using OgreMain_d.lib and still didn't work =(. Has anybody been able to render to a windows form control?
User avatar
KungFooMasta
OGRE Contributor
OGRE Contributor
Posts: 2087
Joined: Thu Mar 03, 2005 7:11 am
Location: WA, USA
x 16

Post by KungFooMasta »

I found the answer in this thread:
http://www.ogre3d.org/phpBB2/viewtopic. ... rm+control

Just for clarification, does anybody know what the differences are between the options in Properties->General->"Common Language Runtime support"?
User avatar
KungFooMasta
OGRE Contributor
OGRE Contributor
Posts: 2087
Joined: Thu Mar 03, 2005 7:11 am
Location: WA, USA
x 16

Help rendering to a Window Form Control (VS2005, VC++)

Post by KungFooMasta »

I'm having problems rendering to a form control. I'm currently following the OgreDotNet example, although the code doesn't match up all the way, and I'm using Ogre 1.2.0 now.

Here is the code for the main Form. I'm trying to render it to a Panel

Code: Select all

#pragma once

#include "Ogre.h"

namespace SceneCreator {

	using namespace System;
	using namespace System::ComponentModel;
	using namespace System::Collections;
	using namespace System::Windows::Forms;
	using namespace System::Data;
	using namespace System::Drawing;

	public ref class MainWindow : public System::Windows::Forms::Form
	{
	public:
		MainWindow(void)
		{
			InitializeComponent();
			//
			//TODO: Add the constructor code here
			//

			// Initialize Ogre components
			mRoot = new Ogre::Root();
			
			Ogre::ConfigFile cf;
			cf.load("resources.cfg");

			// Go through all sections & settings in the file
			Ogre::ConfigFile::SectionIterator seci = cf.getSectionIterator();

			Ogre::String secName, typeName, archName;
			while (seci.hasMoreElements())
			{
				secName = seci.peekNextKey();
				Ogre::ConfigFile::SettingsMultiMap *settings = seci.getNext();
				Ogre::ConfigFile::SettingsMultiMap::iterator i;
				for (i = settings->begin(); i != settings->end(); ++i)
				{
					typeName = i->first;
					archName = i->second;
					Ogre::ResourceGroupManager::getSingleton().addResourceLocation(
						archName, typeName, secName);
				}
			}

			mRoot->showConfigDialog();

			System::Drawing::Size S = this->RenderPanel->ClientSize;

			mRenderWindow = mRoot->createRenderWindow("SceneWindow",S.Width,S.Height,true);
		}

	protected:
		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		~MainWindow()
		{
			if (components)
			{
				delete components;
			}
		}

	private: System::Windows::Forms::Panel^  RenderPanel;
	protected: 
		Ogre::Root*			mRoot;
		Ogre::RenderWindow* mRenderWindow;
. . .
I crashes after the line:

Code: Select all

mRenderWindow = mRoot->createRenderWindow("SceneWindow",S.Width,S.Height,true);
Anybody have a working example of rendering to a control? I'm using a Windows Form Application in VS2005.
User avatar
KungFooMasta
OGRE Contributor
OGRE Contributor
Posts: 2087
Joined: Thu Mar 03, 2005 7:11 am
Location: WA, USA
x 16

Post by KungFooMasta »

Any way to change the title? I wanted it renamed to

"Help rendering to a Windows Form Control (VS2005, VC++)"

and thought adding a new Subject line on my last post would have changed it or something...
Bekas
OGRE Expert User
OGRE Expert User
Posts: 253
Joined: Sat Oct 16, 2004 11:21 pm
x 1

Post by Bekas »

KungFooMasta wrote:I'm currently following the OgreDotNet example
You are following the wrong reference material. OgreDotNet is a .NET wrapper for Ogre, its examples are specific to OgreDotNet's usage.

You are using Ogre directly, so you should follow Ogre's API, tutorials, and wiki examples.

You should also take care of conversions between Ogre strings and .NET strings. Add this include file to your project:

Code: Select all

#pragma once

#include <vcclr.h>
#include "OgrePrerequisites.h"

using namespace System;
using namespace System::Runtime::InteropServices;

ref class AnsiString
{
	AnsiString() {}
	IntPtr _nPtr;
	char* _strPtr;

public:
	AnsiString(String^ mstr)
	{
	   _nPtr = Marshal::StringToHGlobalAnsi(mstr);
	   _strPtr = static_cast<char*>(_nPtr.ToPointer());
	}

	!AnsiString()
	{
		if (0 != (int)_nPtr)
		{
			Marshal::FreeHGlobal( _nPtr );
			_nPtr = (IntPtr)0;
		}
	}
	~AnsiString()
	{
		this->!AnsiString();
	}

	inline static operator Ogre::String (AnsiString% str)
	{
		return str._strPtr;
	}
};

//If Ogre is compiled with Unicode strings (OGRE_WCHAR_T_STRINGS=1) it will speed up
//string conversions
#if OGRE_WCHAR_T_STRINGS
	#define DECLARE_OGRE_STRING(nvar,mstr) pin_ptr<wchar_t> nvar = PtrToStringChars(mstr);
	#define TO_CLR_STRING(ogrestr) Marshal::PtrToStringUni((IntPtr)((wchar_t*)&ogrestr))
#else
	#define DECLARE_OGRE_STRING(nvar,mstr) AnsiString nvar(mstr);
	#define TO_CLR_STRING(ogrestr) Marshal::PtrToStringAnsi(static_cast<IntPtr>((char*)ogrestr.c_str()))
#endif
You can render to a panel like this:

Code: Select all

mRoot->initialise(false);
Ogre::NameValuePairList list;
DECLARE_OGRE_STRING(hndstr, this->RenderPanel->Handle->ToString())
list["externalWindowHandle"] = hndstr;
mRenderWindow = mRoot->createRenderWindow("", 0, 0, false, list);
User avatar
KungFooMasta
OGRE Contributor
OGRE Contributor
Posts: 2087
Joined: Thu Mar 03, 2005 7:11 am
Location: WA, USA
x 16

Post by KungFooMasta »

I added in the header file "AnsiString.h" and included it into my MainWindow. I also added the code, so it looks like this:

Code: Select all

#pragma once

#include "AnsiString.h"
#include "Ogre.h"

// Timer example online
#using <mscorlib.dll>
#using <System.dll>

namespace SceneCreator {

	// Timer example online
	using namespace System;
	using namespace System::Timers;

	using namespace System;
	using namespace System::ComponentModel;
	using namespace System::Collections;
	using namespace System::Windows::Forms;
	using namespace System::Data;
	using namespace System::Drawing;

	
	public ref class MainWindow : public System::Windows::Forms::Form
	{
	public:
		MainWindow(void)
		{
			InitializeComponent();
			//
			//TODO: Add the constructor code here
			//

			// Initialize Ogre components
			mRoot = new Ogre::Root();
			
			Ogre::ConfigFile cf;
			cf.load("resources.cfg");

			// Go through all sections & settings in the file
			Ogre::ConfigFile::SectionIterator seci = cf.getSectionIterator();

			Ogre::String secName, typeName, archName;
			while (seci.hasMoreElements())
			{
				secName = seci.peekNextKey();
				Ogre::ConfigFile::SettingsMultiMap *settings = seci.getNext();
				Ogre::ConfigFile::SettingsMultiMap::iterator i;
				for (i = settings->begin(); i != settings->end(); ++i)
				{
					typeName = i->first;
					archName = i->second;
					Ogre::ResourceGroupManager::getSingleton().addResourceLocation(
						archName, typeName, secName);
				}
			}

			mRoot->showConfigDialog();

			mRoot->initialise(false); 
			Ogre::NameValuePairList list; 
			DECLARE_OGRE_STRING(hndstr, this->RenderPanel->Handle->ToString())
			list["externalWindowHandle"] = hndstr; 
			mRenderWindow = mRoot->createRenderWindow("", 0, 0, false, list);

		}
I compiled and got the following errors:

Code: Select all

1>c:\documents and settings\ben\my documents\visual studio 2005\projects\scenecreator\scenecreator\MainWindow.h(70) : error C2819: type 'System::IntPtr' does not have an overloaded member 'operator ->'
1>        c:\windows\microsoft.net\framework\v2.0.50727\mscorlib.dll : see declaration of 'System::IntPtr'
1>        did you intend to use '.' instead?
1>c:\documents and settings\ben\my documents\visual studio 2005\projects\scenecreator\scenecreator\MainWindow.h(70) : error C2232: '->System::IntPtr::ToString' : left operand has 'class' type, use '.'
1>c:\documents and settings\ben\my documents\visual studio 2005\projects\scenecreator\scenecreator\MainWindow.h(72) : error C2664: 'Ogre::Root::createRenderWindow' : cannot convert parameter 5 from 'Ogre::NameValuePairList' to 'const Ogre::NameValuePairList *'
1>        No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
1>Build log was saved at "file://c:\Documents and Settings\Ben\My Documents\Visual Studio 2005\Projects\SceneCreator\SceneCreator\Release\BuildLog.htm"
1>SceneCreator - 3 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

I'm not sure what's wrong...and I'm not sure what "hndstr" is.
Bekas
OGRE Expert User
OGRE Expert User
Posts: 253
Joined: Sat Oct 16, 2004 11:21 pm
x 1

Post by Bekas »

Oops, my mistake. The code should be

Code: Select all

DECLARE_OGRE_STRING(hndstr, this->RenderPanel->Handle.ToString())
list["externalWindowHandle"] = hndstr;
mRenderWindow = mRoot->createRenderWindow("", 0, 0, false, &list); 
I can't verify the code, so if it still gives you trouble let me know.

And to explain the string conversions better:

The DECLARE_OGRE_STRING macro, sets up a variable suitable to be used as an Ogre string. This code

Code: Select all

DECLARE_OGRE_STRING(hndstr, this->RenderPanel->Handle.ToString())
is "kind of" writing:

Code: Select all

Ogre::String hndstr = this->RenderPanel->Handle.ToString();
So 'hndstr', is a variable that holds the Ogre string for RenderPanel's window handle.

The TO_CLR_STRING macro, accepts an Ogre string and converts it to a .NET string:

Code: Select all

String^ cam = TO_CLR_STRING(camera->getName());
User avatar
KungFooMasta
OGRE Contributor
OGRE Contributor
Posts: 2087
Joined: Thu Mar 03, 2005 7:11 am
Location: WA, USA
x 16

Post by KungFooMasta »

Hmm....I got some interesting results. At first, I inserted in the code and it compiled with no errors, but when I started the application the panel didn't change. I read up a really old thread and saw that they used a timer to update the render window, and so I threw in a timer and had it update every second. Now the panel has a different appearance, but its all blotchy, like black and garbage colored checker pattern, which doesn't change.

Here is the code right now:

Code: Select all

#pragma once

#include "AnsiString.h"
#include "Ogre.h"

// Timer example online
#using <mscorlib.dll>
#using <System.dll>

namespace SceneCreator {

	// Timer example online
	using namespace System;
	using namespace System::Timers;

	using namespace System;
	using namespace System::ComponentModel;
	using namespace System::Collections;
	using namespace System::Windows::Forms;
	using namespace System::Data;
	using namespace System::Drawing;

	/// <summary>
	/// Summary for Form1
	///
	/// WARNING: If you change the name of this class, you will need to change the
	///          'Resource File Name' property for the managed resource compiler tool
	///          associated with all .resx files this class depends on.  Otherwise,
	///          the designers will not be able to interact properly with localized
	///          resources associated with this form.
	/// </summary>
	public ref class MainWindow : public System::Windows::Forms::Form
	{
	public:
		MainWindow(void)
		{
			InitializeComponent();
			//
			//TODO: Add the constructor code here
			//

			// Initialize Ogre components
			mRoot = new Ogre::Root();
			
			Ogre::ConfigFile cf;
			cf.load("resources.cfg");

			// Go through all sections & settings in the file
			Ogre::ConfigFile::SectionIterator seci = cf.getSectionIterator();

			Ogre::String secName, typeName, archName;
			while (seci.hasMoreElements())
			{
				secName = seci.peekNextKey();
				Ogre::ConfigFile::SettingsMultiMap *settings = seci.getNext();
				Ogre::ConfigFile::SettingsMultiMap::iterator i;
				for (i = settings->begin(); i != settings->end(); ++i)
				{
					typeName = i->first;
					archName = i->second;
					Ogre::ResourceGroupManager::getSingleton().addResourceLocation(
						archName, typeName, secName);
				}
			}

			mRoot->showConfigDialog();

			mRoot->initialise(false); 
			Ogre::NameValuePairList list; 

			DECLARE_OGRE_STRING(hndstr, this->RenderPanel->Handle.ToString()) 
			list["externalWindowHandle"] = hndstr; 
			mRenderWindow = mRoot->createRenderWindow("", 0, 0, false, &list); 

			mTimer = gcnew System::Timers::Timer();

			mTimer->Elapsed += gcnew ElapsedEventHandler(this, &SceneCreator::MainWindow::OnTimer);

		    mTimer->Interval = 1000;
	        mTimer->Enabled = true;

		}

		void OnTimer(System::Object^ source, System::Timers::ElapsedEventArgs^ e)
		{
			mRoot->renderOneFrame();
			mRenderWindow->update();
		}

	protected:
		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		~MainWindow()
		{
			if (components)
			{
				delete components;
			}
		}

	private: System::Windows::Forms::Panel^  RenderPanel;
	protected: 
		Ogre::Root*				mRoot;
		Ogre::RenderWindow*		mRenderWindow;
		System::Timers::Timer^	mTimer;
Also reading the summary in the comment block, I remembered that I changed this class name from Form1 to MainWindow. Could that cause any major problems? I guess I'll try removing the form and adding it back in..
User avatar
KungFooMasta
OGRE Contributor
OGRE Contributor
Posts: 2087
Joined: Thu Mar 03, 2005 7:11 am
Location: WA, USA
x 16

Post by KungFooMasta »

I took out the double line "using namespace System;". Nothing changed.

What should my Ogre Settings be? or does it matter?
Currently the window pops up and I have the following settings:

Direct3D9 Rendering Subsystem

Allow NVPerfHUD: No
Anti aliasing: None
Floating-point mode: Fastest
Full Screen: No
Rendering Device: NVIDIA GeForce 7900 GT
VSync: No
Video Mode: 800 x 600 @ 32-bit colour

Description of Panel: Checker pattern with lots of brown and blue mixed up, some black tiles, looks very pixelated
Bekas
OGRE Expert User
OGRE Expert User
Posts: 253
Joined: Sat Oct 16, 2004 11:21 pm
x 1

Post by Bekas »

You have to set up a SceneManager, create a Viewport, etc.

The code below is actually tested, so it should work:

Code: Select all

	MainWindow(void)
	{
		InitializeComponent();
		//
		//TODO: Add the constructor code here
		//

		// Initialize Ogre components
		mRoot = new Ogre::Root();

		Ogre::ConfigFile cf;
		cf.load("resources.cfg");

		// Go through all sections & settings in the file
		Ogre::ConfigFile::SectionIterator seci = cf.getSectionIterator();

		Ogre::String secName, typeName, archName;
		while (seci.hasMoreElements())
		{
		secName = seci.peekNextKey();
		Ogre::ConfigFile::SettingsMultiMap *settings = seci.getNext();
		Ogre::ConfigFile::SettingsMultiMap::iterator i;
		for (i = settings->begin(); i != settings->end(); ++i)
		{
		   typeName = i->first;
		   archName = i->second;
		   Ogre::ResourceGroupManager::getSingleton().addResourceLocation(
			  archName, typeName, secName);
		}
		}

		mRoot->showConfigDialog();

		mRoot->initialise(false);
		Ogre::NameValuePairList list;

		DECLARE_OGRE_STRING(hndstr, this->RenderPanel->Handle.ToString())
		list["externalWindowHandle"] = hndstr;
		mRenderWindow = mRoot->createRenderWindow("", 0, 0, false, &list);

		mSceneMgr = mRoot->createSceneManager(Ogre::ST_GENERIC);
        mCamera = mSceneMgr->createCamera("Camera");

        // Position it at 500 in Z direction
		mCamera->setPosition(Ogre::Vector3(0, 50, 150));
        // Look back along -Z
		mCamera->lookAt(Ogre::Vector3(0, 0, -300));
        mCamera->setNearClipDistance(5);

        mViewport = mRenderWindow->addViewport(mCamera);

        // Load resources
		Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups();


		// Add content
		mEntity = mSceneMgr->createEntity("robot", "robot.mesh");
		mSceneMgr->getRootSceneNode()->attachObject(mEntity);
	}

protected:
	/// <summary>
	/// Clean up any resources being used.
	/// </summary>
	~Form1()
	{
		if (components)
		{
			delete components;
		}

		if (mRoot)
		{
			//clean exit for Ogre
			delete mRoot;
			mRoot = 0;
		}
	}
private: System::Windows::Forms::Panel^  RenderPanel;
protected: 
	Ogre::Root* mRoot;
	Ogre::RenderWindow* mRenderWindow;
	Ogre::SceneManager* mSceneMgr;
	Ogre::Camera* mCamera;
	Ogre::Viewport* mViewport;
	Ogre::Entity* mEntity;
If it's not a render loop that you want, how about, instead of using a timer, updating the Panel when it's necessary, meaning during its Paint event:

Code: Select all

private: System::Void RenderPanel_Paint(System::Object^  sender, System::Windows::Forms::PaintEventArgs^  e) {
			 mRenderWindow->update();
		 }
User avatar
KungFooMasta
OGRE Contributor
OGRE Contributor
Posts: 2087
Joined: Thu Mar 03, 2005 7:11 am
Location: WA, USA
x 16

Post by KungFooMasta »

As I woke up this morning I thought about my app, and I figured I needed a viewport and camera, lol. Thanks for showing me how to add those in, everything seems to be working.

Is there an easy way to pick objects in the rendering window? That is, clicking on the robot in the window and having his bounding box displayed.

I haven't gotten to key events and mouse events yet, but there should be tutorials floating around for me. Thanks for your help =)
User avatar
KungFooMasta
OGRE Contributor
OGRE Contributor
Posts: 2087
Joined: Thu Mar 03, 2005 7:11 am
Location: WA, USA
x 16

Post by KungFooMasta »

I tried to do mouse picking with the following code, but I don't think the Ray is being created properly, since nothing is detected. I took this code from Intermidiate Tutorial 3 off the wiki.

Code: Select all

private: System::Void RenderPanel_MouseUp(System::Object^  sender, System::Windows::Forms::MouseEventArgs^  e) {
			// Setup the ray scene query
			Ogre::Ray mouseRay = mCamera->getCameraToViewportRay( e->Location.X, e->Location.Y );
			mRaySceneQuery->setRay( mouseRay );

			// Execute query
			Ogre::RaySceneQueryResult &result = mRaySceneQuery->execute();
			Ogre::RaySceneQueryResult::iterator itr = result.begin( );

			// loop through the results
			for( itr = result.begin( ); itr != result.end(); itr++ )
			{
			   // Is this result a MovableObject?
			   if( itr->movable )
			   {
				   mSelectedSceneNode = mSceneManager->getSceneNode(itr->movable->getName());
				   mSelectedSceneNode->showBoundingBox(true);
			   }
			}
		}
Any ideas how to do it? =)
User avatar
KungFooMasta
OGRE Contributor
OGRE Contributor
Posts: 2087
Joined: Thu Mar 03, 2005 7:11 am
Location: WA, USA
x 16

Post by KungFooMasta »

Well if anybody is interested I thought I'd post how to do mouse picking and move the camera..not too complicated =)

Code: Select all

private: System::Void RenderPanel_MouseUp(System::Object^  sender, System::Windows::Forms::MouseEventArgs^  e) {
			// Setup the ray scene query

			this->mMouseXCoord = ((System::Double)(e->Location.X) / (System::Double)(this->ClientSize.Width));
			this->mMouseYCoord = ((System::Double)(e->Location.Y) / (System::Double)(this->ClientSize.Height));

			Ogre::Ray mouseRay = mCamera->getCameraToViewportRay( this->mMouseXCoord, this->mMouseYCoord );
			mRaySceneQuery->setRay( mouseRay );

			// Execute query
			Ogre::RaySceneQueryResult &result = mRaySceneQuery->execute();
			Ogre::RaySceneQueryResult::iterator itr = result.begin( );

			// loop through the results
			for( itr = result.begin( ); itr != result.end(); itr++ )
			{
			   // Is this result a MovableObject?
			   if( itr->movable )
			   {
				   this->mSelectedSceneNode = (mSceneManager->getEntity(itr->movable->getName()))->getParentSceneNode();
				   this->mSelectedSceneNode->showBoundingBox(true);
				   mRenderWindow->update();
			   }
			}
		}
		private: System::Void BaseForm_KeyPress(System::Object^  sender, System::Windows::Forms::KeyPressEventArgs^  e) {
			 if( e->KeyChar == (char)Keys::Escape )
			 {
				 if( this->mSelectedSceneNode != NULL )
				 {
					this->mSelectedSceneNode->showBoundingBox(false);
					this->mSelectedSceneNode = NULL;
					mRenderWindow->update();
					e->Handled = true;
				 }
			 }
		}
		private: System::Void BaseForm_KeyDown(System::Object^  sender, System::Windows::Forms::KeyEventArgs^  e) {
			 Ogre::Quaternion q = mCamPitchNode->getOrientation();

			 if( e->KeyCode == Keys::W )
			 {
				 mCamPitchNode->translate( q * Ogre::Vector3::NEGATIVE_UNIT_Z * TRANSLATESPEED );
			 }
			 if( e->KeyCode == Keys::S )
			 {
				 mCamPitchNode->translate( q * Ogre::Vector3::UNIT_Z * TRANSLATESPEED );
			 }
			 if( e->KeyCode == Keys::A )
			 {
				 mCamPitchNode->translate( q * Ogre::Vector3::NEGATIVE_UNIT_X * TRANSLATESPEED );
			 }
			 if( e->KeyCode == Keys::D )
			 {
				 mCamPitchNode->translate( q * Ogre::Vector3::UNIT_X * TRANSLATESPEED );
			 }

			 mRenderWindow->update();
		}
In the first function my renderPanel takes up the entire main form, so I used ClientSize/ClientWidth to get the X,Y positions.

Right now I'm manually updating the render window, but I think if I wanted to support animations I should just use a timer and update the window every X amount of time.
sunnybox
Kobold
Posts: 32
Joined: Thu Jul 27, 2006 5:35 am

Post by sunnybox »

hihi, i use these codes according to what described..

I open a new windows form application using VS 2005

Then , include "Ogre.h"
Addin the string converter header file
change project setting to /clr

Then addin the following code

mRoot = new Ogre::Root();

THen there are runtime error! Which is error while setting string value in ogre...

ex:

mConfigfile = configFile

The value which shown on the error is that it will get something funny character in front of the "config.cfg"

Am I doing this correctly? or have i miss out any things in my application?