Jump to content

  • Log In with Google      Sign In   
  • Create Account

Ogre3d Engine, First Person Collision Detection


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
6 replies to this topic

#1 hybridhaylee   Members   -  Reputation: 132

Like
0Likes
Like

Posted 29 December 2013 - 03:35 PM

Hey there!
 
I am currently working on a jumping puzzle game concept based on a first person view. Being new at this, its been a steep learning curve but am getting there in very small strides.
 
I am having a few problems, I was hoping you would help me. Orge forum isn't really active enough and am getting no responses.
 
So here it goes.
 
I have a scenenode which has a camera and sphere attached to it, I was going to use the sphere around the camera to flag any collisions with objects within the game. I couldn't figure out how to put collision detection on the camera itself so i thought this would be simpler. 
 
Below is how i create and attach my nodes.
	tdynamicnode = this->_obj_mgr_scene->getRootSceneNode()->createChildSceneNode("DynamicNode");
	tdynamicnode->attachObject(_obj_camera_one);
	
	Entity* tempdynentity = nullptr;
	tempdynentity = this->_obj_mgr_scene->createEntity("Sphere",tspheremesh);
	tdynamicnode->attachObject(tempdynentity);
Originally I had controls controlling the camera (using the mouse for rotation and WASD for X,Z ) but now since I have the both the sphere and the camera, I transfered the controls to move the scenenode so the camera and the sphere woudl move together. 
 
Below is the code for moving the scenenode.
if (tnotexiting) 
	{
		this->_obj_mgr_camera_one->frameRenderingQueued(pframe_event);	

		this->_node_player_disp = Vector3::ZERO;
		if(this->_actn_move_fwd)
		{
			this->_node_player_disp += Vector3::NEGATIVE_UNIT_Z * 100 * pframe_event.timeSinceLastFrame;
		}
		if(this->_actn_move_bkwrd)
		{
			this->_node_player_disp += Vector3::UNIT_Z * 100 * pframe_event.timeSinceLastFrame;
		}
		if(this->_actn_strafe_left)
		{
			this->_node_player_disp += Vector3::NEGATIVE_UNIT_X * 100 * pframe_event.timeSinceLastFrame;
		}
		if(this->_actn_strafe_right)
		{
			this->_node_player_disp += Vector3::UNIT_X * 100 * pframe_event.timeSinceLastFrame;
		}
		this->tdynamicnode->translate(this->_node_player_disp);
	}
	
bool tresult = true;

	if(pkeyevt.key == OIS::KC_W)
	{
		this->_actn_move_fwd = true;
	}
	else if(pkeyevt.key == OIS::KC_S)
	{
		this->_actn_move_bkwrd = true;
	}
	else if(pkeyevt.key == OIS::KC_A)
	{
		this->_actn_strafe_left = true;
	}
	else if(pkeyevt.key == OIS::KC_D)
	{
		this->_actn_strafe_right = true;
	}
 
My next problem is I dont know how to change the rotation of the scenenode when moving the camera rotation. Ideally i would like to rotate the X and Z axis on yaw rotation. Essentially I would like it behaviouring simpler to minecraft.
 
But this can be fixed another time, I need collision detection working before i can fix fiddly bits.
 
Now for the collision detection. I need the sphere big enough to encase camera (its currently in front of the camera), then am guessing I use something similar to this to detect collision.
Node::ChildNodeIterator itr = this->_node_obstacles->getChildIterator();


 bool tcollide = false;
 while (itr.hasMoreElements())
 {
  SceneNode* n = (Ogre::SceneNode *)itr.getNext();


  if(n->_getWorldAABB().intersects(_node_player->_getWorldAABB()))
  {
   tcollide = true;
  }
 }


 if(tcollide)
 {
   this->_node_player->translate(-5 * this->_node_player_disp);
 }

I need help with getting the collision to work properly. its so frustrating when its almost there but you cant figure out what it is. Ogre's website doesn't have much.

 



Sponsor:

#2 pptech   Members   -  Reputation: 107

Like
0Likes
Like

Posted 29 December 2013 - 04:56 PM

I would start by not using the scene node bounding box method you are currently using. This method is not meant to be used externally hence the underscore at the start of its name. I have read somewhere not all scene managers maintain it so don't rely on it. I think you need to iterate over the attached objects on each scene node and get their bounding boxes to test your collision against.

As for adding pitch/roll/yaw to your camera try having a hierarchy of three scene nodes one for rotating in each direction.

Hope this helps...good luck!

#3 hybridhaylee   Members   -  Reputation: 132

Like
0Likes
Like

Posted 29 December 2013 - 05:17 PM

I am guessing you are talking about the _getWorldAABB() method?

I think there is a getBoundingBox() method would i be using that to intersect?

 

Thanks for the reply!



#4 AgentC   Members   -  Reputation: 1419

Like
1Likes
Like

Posted 29 December 2013 - 05:28 PM

The Ogre AABB's necessarily don't have anything to do with the object's actual dimensions, it's just what's stored in the mesh file. For example animated meshes often have their AABB's expanded to account for all possible poses they can be in, preventing unwanted culling. Furthermore, AABB is exactly that, axis-aligned bounding box; in games objects are usually not just axis aligned. In general Ogre implements intersection tests only for the purposes of rendering (to see what's visible and what should be culled), not for game collision detection.

 

I would recommend integrating a physics engine such as Bullet instead, to handle both collision detection and character & object movement. Then you can author collisions for objects separate from rendering, based on what fits best for each case (box, sphere, capsule, convex hull etc.)

 

Have no doubt though, using a physics engine will have a steep learning curve as well. But you can eg. take a look at OgreBullet http://www.ogre3d.org/tikiwiki/OgreBullet which is a wrapper library that does the integration for you.

 


Every time you add a boolean member variable, God kills a kitten. Every time you create a Manager class, God kills a kitten. Every time you create a Singleton...

Urho3D (engine)  Hessian (C64 game project)


#5 hybridhaylee   Members   -  Reputation: 132

Like
0Likes
Like

Posted 29 December 2013 - 05:49 PM

Thanks great help!

 

I was actually considering using the bullet engine, I have a whiz through some of the documents and they weren't very clear on how to implement it. Is there a step by step guide on how to get set up, the stuff i have read on it says something about Cmake i think.. I have no idea what that is



#6 pptech   Members   -  Reputation: 107

Like
0Likes
Like

Posted 30 December 2013 - 03:40 AM

If you are happy using a library to do collision detection then there is MOC - Minimal Ogre Collision.

http://www.ogre3d.org/tikiwiki/tiki-index.php?page=Minimal+Ogre+Collision

This might be enough for your needs.

#7 hybridhaylee   Members   -  Reputation: 132

Like
0Likes
Like

Posted 02 January 2014 - 09:51 AM

If you are happy using a library to do collision detection then there is MOC - Minimal Ogre Collision.

http://www.ogre3d.org/tikiwiki/tiki-index.php?page=Minimal+Ogre+Collision

This might be enough for your needs.

 

This could be what i need but... I need the character to have the ability to jump too.. I dont know if i need Bullet for that or if I can simulate it with Ogre.

 

Thanks for your reply.






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS