Hello
In my little game-project i use a Behavior where the view (let's say, inside
the cockpit of a spaceship) gets transformed (pitch, roll, yaw, translate)
according to the keyboard-input.
Now there are also stars around my ship (points distributed randomly on a
imaginary sphere), placed under a TransformGroup.
To make the stars moving togehther with my ship (view) i grab the
translational part of my newly calculated view-transform and set the transform
in my StarsTransformGroup to this translation.
The StarsTransformGroup is NOT a child of my ViewTransformGroup, because i
dont want to rotate it together with my view (spaceship).
I only want to translate the stars to the view.
So in short i do the following in my Behavior
(1) transform view (my spaceship ;)
(2) translate stars under the StarsTransformGroup accordingly.
(all INSIDE the processStimulus method)
The problem now arises is that the two transforms seem not to be in sync in
the rendering:
some frames reflect only transform (1), some show transform (2) and some do
reflect both transforms.
The strange thing about this is that this problem only shows up, when the
translational part of the transforms becomes larger.
(I already checked that precision of double is'nt the source of the problem
and also the order of (1) and (2) plays no role.)
The result is a "jumping" starfield (looks awfully choppy) while i move the
view.
Anybody had a similar problem already?
here is some technical info about the things i use:
- java 1.3.1_03-b03
- java 3D beta 1.3 (DirectX)
- windoze xp pro
- amd athlon 1200C
- geforce2
I add some (in my opinion) relevant code snippets :
(i replaced the stars with a TransformGroup with a ColorCube)
(code is not optimal, i know, but thats only for testing ;)
====snipp===================================
.
.
.
Canvas3D canvas3d;
Transform3D viewTransform;
TransformGroup viewTransformGroup;
Transform3D StarsTransform;
TransformGroup StarsTransformGroup;
View myView;
.
.
.
public void initUniverse()
{
canvas3d = new Canvas3D(null); // null = i was lazy ;)
VirtualUniverse myUniverse = new VirtualUniverse();
Locale myLocale = new Locale(myUniverse);
myLocale.addBranchGraph(buildViewBranch(canvas3d));
}
.
.
.
public BranchGroup buildViewBranch(Canvas3D c)
{
BranchGroup viewBranch = new BranchGroup();
viewTransform = new Transform3D();
viewTransformGroup = new TransformGroup(viewTransform);
ViewPlatform myViewPlatform = new ViewPlatform();
StarsTransform = new Transform3D();
StarsTransformGroup = new TransformGroup(StarsTransform);
StarsTransformGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
StarsTransformGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
Transform3D sunTransform = new Transform3D();
sunTransform.set(new Vector3d(0.0, 0.0, -10.0));
TransformGroup SunTG = new TransformGroup(sunTransform);
SunTG.addChild(new ColorCube());
StarsTransformGroup.addChild(SunTG);
viewTransformGroup.addChild(myViewPlatform);
timedBehavior behav = new timedBehavior();
behav.setSchedulingBounds(new BoundingSphere(new Point3d(0.0, 0.0, 0.0),
1000.0));
viewTransformGroup.addChild(behav);
viewTransformGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
viewTransformGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
viewBranch.addChild(viewTransformGroup);
viewBranch.addChild(StarsTransformGroup);
myView = new View();
PhysicalBody myBody = new PhysicalBody();
PhysicalEnvironment myEnvironment = new PhysicalEnvironment();
myView.setPhysicalBody(myBody);
myView.setPhysicalEnvironment(myEnvironment);
myView.addCanvas3D(c);
myView.attachViewPlatform(myViewPlatform);
return(viewBranch);
}
.
.
.
public class timedBehavior extends Behavior
{
public boolean running = false;
WakeupCriterion[] wakeConditions;
WakeupOr oredConditions;
AWTEvent ae[];
Transform3D moveTrans;
Vector3d viewTranslation;
public void initialize()
{
moveTrans = new Transform3D();
moveTrans.set(new Vector3d(0.0, 0.0, 100000.0)); //we are moving
really fast ;=) so we se the jumpung stars as soon as possible :(
viewTranslation = new Vector3d();
wakeConditions = new WakeupCriterion[3];
wakeConditions[0] = new WakeupOnAWTEvent(KeyEvent.KEY_PRESSED);
wakeConditions[1] = new WakeupOnAWTEvent(KeyEvent.KEY_RELEASED);
wakeConditions[2] = new WakeupOnElapsedTime(10);
oredConditions = new WakeupOr(wakeConditions);
wakeupOn(oredConditions);
}
// things are really straightforward for this testcase: only a
translation (if any key pressed), no rotations at all
public void processStimulus(Enumeration criteria)
{
WakeupCriterion theCriteria;
if(criteria.hasMoreElements())theCriteria =
(WakeupCriterion)criteria.nextElement();
else
{
wakeupOn(oredConditions);
return;
}
if(theCriteria instanceof WakeupOnAWTEvent)
{
ae = ((WakeupOnAWTEvent)theCriteria).getAWTEvent();
if(ae[0].getID()==KeyEvent.KEY_PRESSED) running = true;
else if(ae[0].getID()==KeyEvent.KEY_RELEASED) running = false;
}
else
{
if(running&&(theCriteria instanceof WakeupOnElapsedTime))
{
viewTransform.mul(moveTrans);
viewTransform.get(viewTranslation);
StarsTransform.setTranslation(viewTranslation);
StarsTransformGroup.setTransform(StarsTransform);
viewTransformGroup.setTransform(viewTransform);
}
}
wakeupOn(oredConditions);
}
}
.
.
.
====snipp===================================
PS: english is not my natural language, so plz not laugh ;)
--
+++ GMX - Mail, Messaging & more http://www.gmx.net +++
NEU: Mit GMX ins Internet. Rund um die Uhr f�r 1 ct/ Min. surfen!
===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA3D-INTEREST". For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".