Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

11991 Posts in 1587 Topics- by 3509 Members - Latest Member: lioneltenel

26. May 2012, 10:23:03 pm
Xith3D CommunityGeneral CategorySupport (Moderator: Marvin Fröhlich)Getting Behaviors to work
Pages: [1]
Print
Author Topic: Getting Behaviors to work  (Read 1143 times)
rbivens
Just dropped in

Offline Offline

Posts: 11


View Profile Email
« on: 21. December 2006, 04:54:51 pm »

How do I set up a Behavior? My code looks like this:

   // camera behavior
   cameraBehavior = new EarthCameraBehavior(this.env.getView());
   cameraBehavior.setEnable(true);
   cameraBehavior.setSchedulingBounds(new BoundingSphere(new Vector3f(), Float.MAX_VALUE));
   this.addMouseEventListener(cameraBehavior);

and later in the code I add it to the scene:

bg.addChild(this.cameraBehavior);

It seems that the initialize() and processStimulus() events are never called. I've set up the appropriate WakeupCriterion in my Behavior class.

Are Behaviors the preferred way to manipulate scene graph objects in Xith, or is there a better way?

Thanks,

rbivens
Logged
Marvin Fröhlich
Xith Lord
Administrator
Guru
*****
Offline Offline

Posts: 4381


May the 4th, be with you...


View Profile
« Reply #1 on: 21. December 2006, 05:36:01 pm »

How do I set up a Behavior? My code looks like this:

   // camera behavior
   cameraBehavior = new EarthCameraBehavior(this.env.getView());
   cameraBehavior.setEnable(true);
   cameraBehavior.setSchedulingBounds(new BoundingSphere(new Vector3f(), Float.MAX_VALUE));
   this.addMouseEventListener(cameraBehavior);

and later in the code I add it to the scene:

bg.addChild(this.cameraBehavior);

It seems that the initialize() and processStimulus() events are never called. I've set up the appropriate WakeupCriterion in my Behavior class.

Are Behaviors the preferred way to manipulate scene graph objects in Xith, or is there a better way?

I've never used Behaviors. So I cannot tell you, if or how they work (nor if they are the best way to go). But I can tell you, there's a very convenient and definitely working way using ScheduledOperation or Animatable interfaces (or implementation Atapters).

Please have a look at org.xith3d.test.animation.BulletTest or org.xith3d.test.animation.RotatableGroup or the Model Loader Tests (they use a test class called RotatableModel).

You seem to try to get a player movement by mouse to work, aren't you? I wrote a class called org.xith3d.utility.input.EgoInputAdapter. It is specially for first person shooter like mouse and keyboard input abstraction. But it should be quite simple to port it to a third person perspective or what ever... Have a look at it's usage in org.xith3d.test.benchmark.Q3FlightBenchmark or org.xith3d.test.loaders.BSPLoaderTest.

ScheduledOperation basically works like this:
Code:
ScheduledOperation schedOp = new MyOwnScheduledOperationClass();

OperationScheduler opScheder = this; // where 'this' is your ExtRenderLoop (can be used without OperationScheduler, too. But I wanted to point it out ;).
opScheder.scheduleOperation( schedOp );

And Animatable basically works like this:
Code:
Animatable anim = new MyAnimatedThing();

Animator animator = this; // where 'this' is your ExtRenderLoop (can be used without Animator, too. But I wanted to point it out ;).
animator.addAnimatableObject( anim );

Please watch the Type Hierarchy of ScheduledOperation and Animatable (F4 in Eclipse) to see the numerous classes making use of them.

Marvin
Logged
rbivens
Just dropped in

Offline Offline

Posts: 11


View Profile Email
« Reply #2 on: 21. December 2006, 06:01:04 pm »

Marvin-

Thanks for the quick reply!

I actually like ScheduledOperation better than Behaviors. They look cleaner and easier to use.

Thanks again,

rbivens
Logged
Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic