Skip to main content

Adding collision to cameraNode

18 replies [Last post]
aliatis
Offline
Joined: 2009-09-24

Hi, guys.

I need to add collision system to cameraNode. I have tried to do it via JMony but I think better way is mtgame.

Any ideas?.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
kaplanj
Offline
Joined: 2004-07-13

What are you using for collision geometry (in this case the collisionGraph variable)? It looks like the collision geometry needs to be positioned properly in world coordinates to do the collision check, so you may need to transform the geometry like in AvatarController.

In fact, the code mentioned above in AvatarController is the only place I know where we use collision detection. You may need to start with a simpler case and expand from there.

aliatis
Offline
Joined: 2009-09-24

I'm going to try it. Thanks, Kaplanj.

kaplanj
Offline
Joined: 2004-07-13

I don't think it's enough to just add the collision component. This will let you detect collisions, but you still need to write some code to react to those collisions. For example, the avatars collision is controlled in the IMI code, at line 292 here:

https://avatars.dev.java.net/source/browse/avatars/trunk/src/imi/charact...

This performs a collision check (using the collision component) each time the avatar moves. If collision response is enabled and there is a collision, the avatar is reverted back to its previous position.

Once you have the collision component added to the camera, you will need to add a similar collision check to your CameraProcessor to decide whether or not to move the camera.

jagwire
Offline
Joined: 2008-06-21

Off topic but,

Is there a way to hook into the collision system to create a listener outside of the avatar code to listen for collisions?

jW

aliatis
Offline
Joined: 2009-09-24

I think that is possible. You can add a CollisionListener to avatar. The only questios is if you can get avatar to add your custom CollisionListener

aliatis
Offline
Joined: 2009-09-24

I use a thirdPersonCameraProcessor.

I'm going to turn off collision along this morning. I'll advice you with news.

aliatis
Offline
Joined: 2009-09-24

That doesn't work. CameraNode not response to collision:

CollisionInfo collisionInfo = colisionControllerCamara.getCollisionSystem().findAllCollisions(collisionGraph, true);

This object, collisionInfo, has a method size(). It's value is zero.

I'm sure I'm doing something wrong.

Message was edited by: aliatis

bernard_horan
Offline
Joined: 2007-06-04

Hi

I'm still confused about what you're trying to achieve. You want to stop the avatar's camera from colliding into solid objects? What would happen if your avatar kept moving and the camera stopped?

regards

Bernard

aliatis
Offline
Joined: 2009-09-24

Yes, it is. I want to stop camera when collides with solid object, thiws is my first problem: camera never collide, always pass through solid objects. The second cuestion don't worry me, for now.

jagwire
Offline
Joined: 2008-06-21

aliatis,

If you download the mtgame project from mtgame.dev.java.net you'll find many examples involving CollisionComponents and dynamics. This is on my radar as of late too, so don't be shy asking questions...

jW

EDIT: Here's the code I commonly use to add collision to a node. It's important to to know that the Entity passed to this method should be an empty entity and it get's attached to the parent entity (in this case the cameraNode's entity) after this method is called. The last parameter can be used as a switch to turn on/off collision. Hope this helps...

[code]
public void makeEntityCollidable(Entity e, Node n, boolean collidable) {
JMECollisionSystem collisionSystem = (JMECollisionSystem)ClientContextJME.getWorldManager().getCollisionManager().loadCollisionSystem(JMECollisionSystem.class);

CollisionComponent cc = collisionSystem.createCollisionComponent(n);
cc.setCollidable(collidable);
e.addComponent(CollisionComponent.class, cc);
}

[/code]

null

aliatis
Offline
Joined: 2009-09-24

Many thanks for reply.

I have tested this code in following enviroment:

I have a CameraNode, cameraNode.

I have created an entity, Entity entity=new Entity();

And I set collidable to true.

This is the piece of code:

Entity entity = new Entity();
makeEntityCollidable(entity, cameraNode, true);

When I execute wonderland, cameraNode pass through the walls, is not collidable.

What's wrong?.

jagwire
Offline
Joined: 2008-06-21

aliatis,

Um... is cameraNode just an arbitrary CameraNode class or is the instance that wonderland is using to control the camera?

jW

aliatis
Offline
Joined: 2009-09-24

cameraNode is the object from this class:

**
* A very simplistic third person camera model
*
* @author paulby
*/
public class ThirdPersonCameraProcessor implements CameraController {

private boolean commitRequired = false;
private Quaternion viewRot = new Quaternion();
private Vector3f viewTranslation = new Vector3f();

protected Vector3f cameraLook = new Vector3f(0,0,1);
private Vector3f yUp = new Vector3f(0,1,0);

private Vector3f tmp=new Vector3f();

private WorldManager wm;

[b] private CameraNode cameraNode;[/b]
.........
.........
}

I think it's a instance that wonderland is using to control the camera. What's wrong with that?.

thanks for reply. :D

jagwire
Offline
Joined: 2008-06-21

aliatis,
Hmm... are you attaching the entity you pass to that method to the entity that already encompasses the cameraNode?

jW

aliatis
Offline
Joined: 2009-09-24

When you say "attaching the entity", you mean entity from this line of code of my last post?. :::> Entity entity=new Entity();

The answer is not. cameraNode hasn't entity, isn't it?.

I think I'm doing something wrong: my camera always pass through walls.

bernard_horan
Offline
Joined: 2007-06-04

I'm not clear what you're trying to do here. Add a collision component to _some_ instance of CameraNode, or to the _particular_ instance of CameraNode that you identify above?

B

aliatis
Offline
Joined: 2009-09-24

CameraNode that I identify above.

I only need that camera can't pass trough walls. When I rotate the avatar, camera pass trough all objects and I lost avatar.

bernard_horan
Offline
Joined: 2007-06-04

ah, I think I understand.

Which 'view' are you using when this happens?

As far as I know the position of the avatar camera (and its collision with other objects) is overridden by the position of the avatar. Have you turned off collision on the menu? Is your avatar no longer colliding with objects?

regards

Bernard