Using Irrlicht and Newton... Again.

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
Delee
Posts: 18
Joined: Sat Apr 14, 2007 8:36 am

Using Irrlicht and Newton... Again.

Post by Delee »

Please bear with me as it has been a couple of years since I last touched C++. In addition, I am using Visual Studio 2005 and I also have very little experience with that program.

In any case, I have tried working through the tutorials with respect to Newton, but I have not been able to find any that work. I believe some are out of date, others just don't compile and I have no idea why.

The following is my code. It compiles and works... I can wonder around the map and bash into walls. Therefore, it is my belief that both Irrlicht and Newton are correctly installed and linked.

Code: Select all

#include "stdafx.h"

#include <irrlicht.h>
#include <newton.h>
#include <iostream>

using namespace irr;

#pragma comment(lib, "Irrlicht.lib")
#pragma comment(lib, "Newton.lib")

int main() {
	IrrlichtDevice* device = createDevice(video::EDT_DIRECT3D9, core::dimension2d<s32>(640, 480), 16, false, false, false);
		
	// Could not create selected driver.
	if (device == 0) { return 1; }

	video::IVideoDriver*  driver = device -> getVideoDriver();
	scene::ISceneManager* smgr   = device -> getSceneManager();
	
	// Load the map.
	device -> getFileSystem() -> addZipFileArchive("media/map-20kdm2.pk3");

	scene::IAnimatedMesh* level = smgr -> getMesh("20kdm2.bsp");
	scene::ISceneNode*    node  = smgr -> addOctTreeSceneNode(level -> getMesh(0), 0, -1, 128);

	scene::ITriangleSelector* selector = smgr -> createOctTreeTriangleSelector(level -> getMesh(0), node, 128);
	
	node     -> setTriangleSelector(selector);
	selector -> drop();

	// Load the camera.
	scene::ICameraSceneNode* camera = smgr -> addCameraSceneNodeFPS(0, 100.0f, 300.0f, -1, 0, 4, true);	
	
	node   -> setPosition(core::vector3df(-1350, -130, -1400));
	camera -> setPosition(core::vector3df(-100, 50, -150));

	scene::ISceneNodeAnimator* anim = smgr -> createCollisionResponseAnimator(
												selector, camera, core::vector3df(30, 50, 30),
												core::vector3df(0, -1.5f, 0),
												core::vector3df(0, 50, 0));

	camera -> addAnimator(anim);
	anim   -> drop();
	device -> getCursorControl() -> setVisible(false);

	while (device -> run()) {
		if (device -> isWindowActive()) {
			driver -> beginScene(true, true, 0);
			smgr   -> drawAll();
			driver -> endScene();
		}
	}

	device -> drop();
	return 0;
}
All I want to do is add an object to the scene. For simplicity, let us say one of the default faeries. I want this object to have collision detection that is handled by Newton. If I add it high up in the air, I expect that it will fall down until it hits something.

About all I have accomplished with Newton is the use of ...

Code: Select all

NewtonWorld nWorld = NewtonCreate(NULL, NULL);
Any advice is appreciated. I have no idea what I am doing... even a pointer to the Newton API would be great, since I have only found the unofficial one and that is incomplete.

My thanks in advance.
agi_shi
Posts: 122
Joined: Mon Feb 26, 2007 12:46 am

Re: Using Irrlicht and Newton... Again.

Post by agi_shi »

Delee wrote:Please bear with me as it has been a couple of years since I last touched C++. In addition, I am using Visual Studio 2005 and I also have very little experience with that program.

In any case, I have tried working through the tutorials with respect to Newton, but I have not been able to find any that work. I believe some are out of date, others just don't compile and I have no idea why.

The following is my code. It compiles and works... I can wonder around the map and bash into walls. Therefore, it is my belief that both Irrlicht and Newton are correctly installed and linked.

Code: Select all

#include "stdafx.h"

#include <irrlicht.h>
#include <newton.h>
#include <iostream>

using namespace irr;

#pragma comment(lib, "Irrlicht.lib")
#pragma comment(lib, "Newton.lib")

int main() {
	IrrlichtDevice* device = createDevice(video::EDT_DIRECT3D9, core::dimension2d<s32>(640, 480), 16, false, false, false);
		
	// Could not create selected driver.
	if (device == 0) { return 1; }

	video::IVideoDriver*  driver = device -> getVideoDriver();
	scene::ISceneManager* smgr   = device -> getSceneManager();
	
	// Load the map.
	device -> getFileSystem() -> addZipFileArchive("media/map-20kdm2.pk3");

	scene::IAnimatedMesh* level = smgr -> getMesh("20kdm2.bsp");
	scene::ISceneNode*    node  = smgr -> addOctTreeSceneNode(level -> getMesh(0), 0, -1, 128);

	scene::ITriangleSelector* selector = smgr -> createOctTreeTriangleSelector(level -> getMesh(0), node, 128);
	
	node     -> setTriangleSelector(selector);
	selector -> drop();

	// Load the camera.
	scene::ICameraSceneNode* camera = smgr -> addCameraSceneNodeFPS(0, 100.0f, 300.0f, -1, 0, 4, true);	
	
	node   -> setPosition(core::vector3df(-1350, -130, -1400));
	camera -> setPosition(core::vector3df(-100, 50, -150));

	scene::ISceneNodeAnimator* anim = smgr -> createCollisionResponseAnimator(
												selector, camera, core::vector3df(30, 50, 30),
												core::vector3df(0, -1.5f, 0),
												core::vector3df(0, 50, 0));

	camera -> addAnimator(anim);
	anim   -> drop();
	device -> getCursorControl() -> setVisible(false);

	while (device -> run()) {
		if (device -> isWindowActive()) {
			driver -> beginScene(true, true, 0);
			smgr   -> drawAll();
			driver -> endScene();
		}
	}

	device -> drop();
	return 0;
}
All I want to do is add an object to the scene. For simplicity, let us say one of the default faeries. I want this object to have collision detection that is handled by Newton. If I add it high up in the air, I expect that it will fall down until it hits something.

About all I have accomplished with Newton is the use of ...

Code: Select all

NewtonWorld nWorld = NewtonCreate(NULL, NULL);
Any advice is appreciated. I have no idea what I am doing... even a pointer to the Newton API would be great, since I have only found the unofficial one and that is incomplete.

My thanks in advance.
The first thing you posted is pure Irrlicht, and it's simply collision detection. It has nothing to do with Newton.

Adding a falling object won't be as simple as just adding a fairy. You have to create the world (which you seem to know from the above), create a body, create collision data for the body (by either using a built-in shape like a box or by parsing the mesh and using it's vertices), assign the collision data to the body, set up some basic things of the body (mass, etc.), set up the body's callbacks (force and torque, transfomation, etc.), and actually write those callbacks.

The gravity thing in specific does not exist in Newton, what you do with the gravity is apply it as a force yourself in the force and torque callback.

I could write a whole tutorial, but I don't have the time for it so... Look at THIS example (great job sio2, btw!): http://sio2.g0dsoft.com/modules/wmpdownloads/ (look for "Irrlicht 3D Engine / Newton Physics Demo")

I believe the source was included, and that's pretty much the best example I've seen. Check out how it does things and then start doing things on your own.

You'll find http://irrlicht.sourceforge.net/phpBB2/ ... hp?t=14720 useful for using a mesh as collision data.
Delee
Posts: 18
Joined: Sat Apr 14, 2007 8:36 am

Post by Delee »

My thanks, I will have a look!

After much trial and error, I managed to get an object mesh to be rotated by Newton, but essentialy, that didn't help me very much. I still have no idea how to get it to interact with the rest of the environment.
agi_shi
Posts: 122
Joined: Mon Feb 26, 2007 12:46 am

Post by agi_shi »

Delee wrote:My thanks, I will have a look!

After much trial and error, I managed to get an object mesh to be rotated by Newton, but essentialy, that didn't help me very much. I still have no idea how to get it to interact with the rest of the environment.
Just look at the example and it'll all just come into you... Well, it did for me :)
Delee
Posts: 18
Joined: Sat Apr 14, 2007 8:36 am

Post by Delee »

agi_shi wrote:
Delee wrote:My thanks, I will have a look!

After much trial and error, I managed to get an object mesh to be rotated by Newton, but essentialy, that didn't help me very much. I still have no idea how to get it to interact with the rest of the environment.
Just look at the example and it'll all just come into you... Well, it did for me :)
My thanks for your help! I learnt more from that one example than I did from staring at all the other tutorials and examples. :)
bcronje
Posts: 10
Joined: Thu Mar 29, 2007 9:10 pm

Post by bcronje »

Another great example that includes balls, hinges, slider joints and ragdolls see "Modified version of Mercior's Tutorial for the Irrlicht Engine" on http://www.newtondynamics.com/downloads.html
Post Reply