Collision Problems

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
Tyn
Posts: 932
Joined: Thu Nov 20, 2003 7:53 pm
Location: England
Contact:

Collision Problems

Post by Tyn »

Here's my collision to get a ray to use for collision from 2D coordiantes ( the mouse position ). For some reason this chunk of code is crashing the program back to desktop, has someone else had the same thing ( and found a solution ) ?

Code: Select all

void createNodePicker()
{
irr::scene::ISceneCollisionManager* sceneCollision;
irr::scene::ISceneNode* selectedSceneNode;
irr::scene::ISceneNode* lastSelectedSceneNode;
irr::core::position2d<int> cursorPos;
irr::core::line3d<float> line;

	cursorPos = cursor->getPosition();
	
	
	line = sceneCollision->getRayFromScreenCoordinates(cursorPos, camera);

	selectedSceneNode = sceneCollision->getSceneNodeFromRayBB(line);

	if (lastSelectedSceneNode)
	{
		// Set tile to unselected state
	}
	if(selectedSceneNode)
	{
		// Set tile to selected state
	}

}
thesmileman
Posts: 360
Joined: Tue Feb 10, 2004 2:20 am
Location: Lubbock, TX

Post by thesmileman »

Ummmmmm, you are using several pointers with out creating objects for them to point to.

For example you define a pointer to a ISceneCollisionManager; But never create a collision manager for it to point to This is not a problem until you try to access the colllision manager it points to, however it doesn't point to anything(Well some random space in memory but nothing useful). This is cause a crash probibly because of an illegal memory usage. Also you do the same thing with several other objects. The only ones you have done right is cursorPos and selectedSceneNode;

Maybe look over the tech demo it covers ray casting I think for the rockets that are fired.
Tyn
Posts: 932
Joined: Thu Nov 20, 2003 7:53 pm
Location: England
Contact:

Post by Tyn »

I implemented the collision manager, but the problem is the ray that is being created from scene coords, I can't see anything wrong with it. cursorPos is implemented in this funtion and camera is a global variable that is implemented in main() before this funtion is called.

Code: Select all

	irr::core::position2d<int> cursorPos;
	irr::scene::ISceneCollisionManager* colmgr;

	cursorPos = cursor->getPosition();
	colmgr = smgr->getSceneCollisionManager();
	
	irr::core::line3d<f32> line = colmgr->getRayFromScreenCoordinates(cursorPos, camera);
Post Reply