The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

import-bot (20211) [Avatar] Offline
#1
[Originally posted by goranth]

Hello, thankyou for your answer. The first 3 clues did not help and the last
one to 'establish the axis of rotation' I'm not sure how to code.

But to be a little more clear this is the most important code changes to your
code:
Node aPlan = ModelLoader.loadModelFromName("plane.wrl");
AffineGroup aPlane = new AffineGroup(aPlan);
flyView.addNode(aPlane);
............

flyCameraRoll = flyCamera.getRollActuator().getPlugin();
flyCameraRoll.initActuation(new Vector4d(0, 0, 0, 0));
submoEventSource flyCameraRoller = new submoEventSource(submo, 2,
flyCameraRoll);
flyCameraRoller.setEnable(true);
flyCameraRoller.setNoOfTimeouts(1000);
flyCameraRoller.addsubmoEventListener(this);
.................
public class submoEventSource implements Runnable, ActuationTarget,
EnableTarget {
public class Positions extends Tuple4d {
// create SubmoBehavior
Positions(){
}
}
public class Rotations extends Tuple4d {
// create SubmoBehavior
Rotations(){
}
}
protected RpcSimnon submo;
protected Positions pos;
protected Rotations rot;
protected int rotation = 0;
................
public submoEventSource(RpcSimnon submo, int rotation, ActuatorPlugin
plugin){
this.submo = submo;
// set the sample time to 1 sec
setTimeOut(1000);
if(plugin==null) throw new
IllegalArgumentException("'plugin' is null.");
_plugin = plugin;
this.rotation = rotation;
pos = new Positions();
rot = new Rotations();
rot.set(setRotation(Math.PI, -Math.PI, Math.PI/2));
}
public Quat4f setRotation(double p0, double p1, double p2){
Matrix3d rotations = new Matrix3d();
rotations.rotX(p0);
rotations.rotY(p1);
rotations.rotZ(p2);
Quat4f quat = new Quat4f();
return quat;
}
........
public void startsubmoEventSource(){
if(t == null){
t = new Thread(this);
t.start();
}
}
..............
public void run(){
if(t != null){
for(; actualNumber != 0; actualNumber--){
try{
t.sleep(timeOut);
}catch(Exception e){
System.out.println(e);
}
fireOff();
}
}

t = null;
}
..............
protected void fireOff(){
// get the current plane positions and atitude angles
double[] states = submo.GetSubmoStates();
double x, y, z;
te.setCount(actualNumber);
Vector listeners = (Vector) this.listeners.clone();
for(int i = 0; i < listeners.size(); i++){
((submoEventListener) listeners.elementAt(i)).timedOut(te);
if (rotation == 0) {
pos.x = states[1]; pos.y = states[0]; pos.z = states[2];
pos.w = 0.0;
updateActuation(pos);
}
else if (rotation == 1) {
x = Math.toRadians( Math.IEEEremainder(-states[6], 360.0
));//rot.
y = Math.toRadians( Math.IEEEremainder(-states[7], 360.0
));
z = Math.toRadians( Math.IEEEremainder(states[8], 360.0
));
rot.set(setRotation(x, y, z));
updateActuation(rot);//update
}
// Rolling
else if (rotation == 2) {
x = 0.0;
y = 0.0;
z = Math.toRadians( Math.IEEEremainder(states[8], 360.0
));
rot.set(setRotation(x, y, z));
updateActuation(rot);
}
// Yawing
else if (rotation == 3) {
x = 0.0;
y = Math.toRadians( Math.IEEEremainder(-states[7], 360.0
));
z = 0.0;
rot.set(setRotation(x, y, z));
updateActuation(rot);
}
// pitching
else if (rotation == 4) {
x = Math.toRadians( Math.IEEEremainder(-states[6], 360.0
));
y = 0.0;
z = 0.0;
rot.set(setRotation(x, y, z));
updateActuation(rot);
}
}
}
............
// ActuationTarget implementation
public void initActuation(Tuple4d value) {
if(!_enable) return;
_plugin.initActuation(value);
if(_actuationSplitter != null)
_actuationSplitter.initActuation(value);
ChangeSensor.processAllChanges(getTargetNode());
}
public void updateActuation(Tuple4d value) {
if(!_enable) return;
_plugin.updateActuation(value);
if(_actuationSplitter != null) {
_actuationSplitter.updateActuation(value);
}
ChangeSensor.processAllChanges(getTargetNode());
}
..............
}


Best regards Goran
import-bot (20211) [Avatar] Offline
#2
Re: CameraNavigating:
[Originally posted by author]

I posted a response but it was apparently lost. Oh well...

The problem is probably because you are not setting the axis of rotation. I
see in your code...

flyCameraRoll.initActuation(new Vector4d(0, 0, 0, 0));

For axis angle rotation actuators the state specification is similar to an
AxisAngle4d, with the first three components specifying the axis of rotation.
If it is (0 , 0,0), you will not see any rotation because there is no axis.
In a sperical actuator, as the j3dui javadoc states, although the actuators
are labeled X, Y, Z, these are just arbitrary designations. You still have to
specify the rotation axis for each of the actuators.

Take a look at the FlyCameraController class, as well as earlier examples that
use the spherical actuator. You'll see that they set the axis, typically by
establishing a constant offset in the actuator plugin.

BTW: Although it is hard to tell from your code whether you are extending or
modifying the FlyCamera class, might I suggest that you take an approach
similar to that done in FlyCameraController, or just extend it. That way the
integrity of the fly camera remains intact and all you do is modify how you
control it in the controller, which is what I believe you are trying to do.

In any case, good luck

--jon