Hi,
I am new in jME (java Monkey Engine). I am doing my master project about a smart home simulator. I decided to do this project with jME.
Right now, I have a 3D model into my simulator, the next step I want to do It’s control the main door of my virtual house, so, I followed this tutorial and I could implement exactly I wanted.
I tried opening and closing the door, and I got. But the problem is the physics, when the door is opening you can see how the door is opening, but when I try to cross the door I can’t , I know I can do a physics layer into the object but when I try to do this the control disapear.
I have a class which control my main door but the problem is that I can’t update the physics.
This is the control code:
[java]
package control;
import com.jme3.bullet.collision.shapes.CollisionShape;
import com.jme3.bullet.collision.shapes.CompoundCollisionShape;
import com.jme3.bullet.control.RigidBodyControl;
import com.jme3.bullet.util.CollisionShapeFactory;
import com.jme3.math.FastMath;
import com.jme3.math.Matrix3f;
import com.jme3.math.Quaternion;
import com.jme3.math.Vector3f;
import com.jme3.renderer.RenderManager;
import com.jme3.renderer.ViewPort;
import com.jme3.scene.Geometry;
import com.jme3.scene.Node;
import com.jme3.scene.Spatial;
import com.jme3.scene.control.AbstractControl;
import com.jme3.scene.control.Control;
import mygame.Main;
public class OpenDoor extends RigidBodyControl{
static final float PI = 3.14159265359f;
private float speed = 5;
private float inipos = 0f;
private boolean action = false; //true=opening, false=closing
RigidBodyControl myRigidBody;
public OpenDoor() {
}
public OpenDoor(CollisionShape sceneDoor, int i) {
super(sceneDoor,i);
}
@Override
public void update(float tpf) {
Quaternion q = new Quaternion();
q.fromAngles(0, -90, 0);
spatial.setLocalRotation(q);
super.update(tpf);
/*float angle;
float angleRads;
angle = speed;
angleRads = (angle * PI)/180;
if(action==true){
//counter = counter + angleRads;
if(Math.abs(spatial.getLocalRotation().getY()*2.2-inipos)<PI/2){
spatial.rotate(0, -angleRads,0);
}
}else{
if(spatial.getLocalRotation().getY()*2.2-inipos<0){
spatial.rotate(0, angleRads,0);
}
}
*/
}
public Control cloneForSpatial(Spatial spatial){
//save initial position
inipos = (float) (spatial.getLocalRotation().getY()*2.2);
OpenDoor control = new OpenDoor();
control.setSpeed(speed);
control.setSpatial(spatial);
return control;
}
/**
* @return the speed
*/
public float getSpeed() {
return speed;
}
/**
* @param speed the speed to set
*/
public void setSpeed(float speed) {
this.speed = speed;
}
/**
* @return the action
*/
public boolean isAction() {
return action;
}
/**
* @param action the action to set
*/
public void setAction(boolean action) {
this.action = action;
}
public void actionDoor(){
setAction(!action);
}
public Object getRigidDoor() {
return myRigidBody;
}
}[/java]