www.jpct.net

General => Feedback => Topic started by: AGP on August 16, 2006, 10:27:33 pm

Title: Suggestions for Next Release
Post by: AGP on August 16, 2006, 10:27:33 pm
Apart from better lighting controls (already promised in the docs), how about a Camera.follow(Object3D)? Could either start its own thread, or take the Object3D's current position plus the camera's delta from it once. That would be cool.
Title: Suggestions for Next Release
Post by: EgonOlsen on August 16, 2006, 11:28:26 pm
The improved light source handling is already done and will be part of the next release. It'll leave the current implementation untouched but adds a little helper class to the util-package that wraps each light into an object. Handling is much better with this IMHO.
About the camera stuff...i'm not really sure if i fully understand what to want this method to do!?
Title: Suggestions for Next Release
Post by: AGP on August 17, 2006, 01:45:08 am
Just that: follow an object. Like the camera follows the X-Wing in the Rogue Squadron series, or like you would want a camera following a character who is walking around an environment (over the shoulder) for an RPG. Example of the camera following the x-wing:

(http://66.160.166.159/RogueExample.jpg)
Title: Suggestions for Next Release
Post by: AGP on August 17, 2006, 08:47:51 pm
Egon, Can I take your lack of response to indicate that you aprove of my camera suggestion?
Title: Suggestions for Next Release
Post by: EgonOlsen on August 17, 2006, 09:03:57 pm
No, you can indicate that as my lack of time due to the fact that i have to install my new Core2 Duo machine... :wink:
Anyway, i don't think that such a method belongs into the engine. It depends too much on the game's/application's needs IMHO. The car example already contains an example on how to do something like this and so do the Paradroidz sources. I don't think there is a generic solution to this that fits everyones needs.
Title: Suggestions for Next Release
Post by: AGP on August 17, 2006, 11:13:21 pm
Yes, but a lot of the things you put in an engine don't fit everyone's needs. This would be very cool because camera-handling is always a pain-in-the-ass.

Anyway, I was thinking about it and you would need two methods. A Camera.set(Object3D) indicating that the camera's position relative to the object has been set, and the aforementioned Camera.follow(Object3D). Pretty please?
Title: Suggestions for Next Release
Post by: EgonOlsen on August 17, 2006, 11:38:15 pm
Some stuff may not fit everyones needs, but if it does...it does. That's not the case with camera stuff IMO. Take Camera.follow(Object3D) as an example: What should that method do? move the camera behind the object? In which distance? With which viewing angle? How should it react to acceleration? How to deceleration? How to rotations? Should it just "stick" onto the object or have a "flow"? Should it collide with obstacles or not? What should be done, if it does?
A method that handles all this has to have a lot of configuration variables...i don't think, that it's worth it. However, i'll think about some camera related stuff for the util-package to decouple it from the engine's core.
Title: Suggestions for Next Release
Post by: AGP on August 17, 2006, 11:44:49 pm
I just answered all your questions: you would set the distance and angle, then call Camera.set(Object3D). From then on, you would call Camera.follow(Object3D) which would adjust its position relative to the object as if it were being pulled by a stick.
Title: Suggestions for Next Release
Post by: EgonOlsen on August 17, 2006, 11:56:16 pm
That's simple:

Code: [Select]
   
SimpleVector center=object.getTransformedCenter();
SimpleVector camPos=new SimpleVector(center);
SimpleVector zOffset=object.getZAxis();
SimpleVector yOffset=object.getYAxis();
zOffset.scalarMul(-100f);
yOffset.scalarMul(60f);
camPos.add(zOffset);
camPos.add(yOffset);
camera.setPosition(camPos);
camera.lookAt(center);


That should work. But as you can see, it doesn't take collisions into account (for example) and it can't do that in a generic way. But a lot of people will need that, so i still think you're better off with your own, tailored method. But i'll add some stuff like this into util. I'm just not sure that it'll make it into the next release.
Title: Suggestions for Next Release
Post by: AGP on August 18, 2006, 12:07:48 am
That's neither set() nor follow(). Follow has to consider the camera's previous settings (as determined by set()).

They would be two cool methods to have but if you won't include them I'll be happy to get their respective codes from you. :-)

Seriously I'll be grateful for any help.
Title: Suggestions for Next Release
Post by: EgonOlsen on August 18, 2006, 12:16:04 am
Quote from: "AGP"
That's neither set() nor follow(). Follow has to consider the camera's previous settings (as determined by set()).
No, it's both. The position is determined by the -100 (in z-direction) and the 60 (in y-direction). The lookAt makes you look at the objects center (or whatever point you put in there). Call this every frame and it should do what you want. If it doesn't, then i'm still not getting what you want.
Title: Suggestions for Next Release
Post by: AGP on August 18, 2006, 12:18:04 am
Just so you don't think I'm a moron, I believe my problem comes from adjusting the camera before building all the objects. Building the objects just seems like the last thing to do when initializing. I still think that the set() and follow() methods are useful, but I understand your position.
Title: Suggestions for Next Release
Post by: EgonOlsen on August 18, 2006, 12:53:35 am
Maybe this will help. It doesn't work with angles directly, because that will cause a lot more math to be involved. The set()-method needs a camera position and an initial lookAt position in world space (if you want to work with angles, derive the lookAt from the position and the angles). Then call follow() each frame. It may do, what you want.

Code: [Select]
import com.threed.jpct.*;

public class Follower {
   
   private SimpleVector initial=null;
   private SimpleVector angles=null;
   private SimpleVector offsets=null;
   private SimpleVector lookAt=null;
   private boolean firstRun=true;
   
   public Follower() {
      initial=new SimpleVector();
   }
   
   public void set(SimpleVector start, SimpleVector lookAt) {
      initial=start;
      this.angles=angles;
      this.lookAt=lookAt;
   }
   
   public void follow(Object3D obj, Camera cam) {
      if (firstRun) {
         SimpleVector c=obj.getTransformedCenter();
         offsets=initial.calcSub(c);
         lookAt=lookAt.calcSub(c);
         firstRun=false;
      }
     
      SimpleVector center=obj.getTransformedCenter();
      SimpleVector camPos=new SimpleVector(center);
      SimpleVector zOffset=obj.getZAxis();
      SimpleVector yOffset=obj.getYAxis();
      SimpleVector xOffset=obj.getXAxis();
      zOffset.scalarMul(offsets.z);
      yOffset.scalarMul(offsets.y);
      xOffset.scalarMul(offsets.x);
     
      SimpleVector zlookOffset=obj.getZAxis();
      SimpleVector ylookOffset=obj.getYAxis();
      SimpleVector xlookOffset=obj.getXAxis();

      SimpleVector look=new SimpleVector(center);
      zlookOffset.scalarMul(lookAt.z);
      ylookOffset.scalarMul(lookAt.y);
      xlookOffset.scalarMul(lookAt.x);
      look.add(zlookOffset);
      look.add(xlookOffset);
      look.add(ylookOffset);
     
      camPos.add(zOffset);
      camPos.add(yOffset);
      camPos.add(xOffset);
      cam.setPosition(camPos);
      cam.lookAt(look);
   }
}
Title: Suggestions for Next Release
Post by: AGP on August 18, 2006, 05:03:45 am
Thanks a lot. I'm about to try it out.

But how about a public Camera Object3D.lookThrough()? That way you could set an invisible object as your camera. That's probably insanely easy to do, and you could just addChild(cameraObject) to another object. You have to admit that is very useful. How about it?
Title: Suggestions for Next Release
Post by: EgonOlsen on August 18, 2006, 07:58:12 pm
Code: [Select]

camera.setBack(obj.getWorldTransformation().invert3x3());
camera.setPosition(obj.getTransformedCenter());
 :?:
Title: Suggestions for Next Release
Post by: AGP on August 19, 2006, 08:51:45 pm
I don't understand one part of that first line. For starters, what's the invert for? It works exactly the same without it. And all I seem to get renderered is the bottom of my model. If I move the camera object over the model to try to get its top, even when I rotate the camera object 180 degrees, I don't get anything.
Title: Suggestions for Next Release
Post by: AGP on August 20, 2006, 09:39:11 am
A quick update so you what I'm talking about: I can rotate the object, the object's pivot, and even mirror the object but I can't get the camera to face anywhere but up with your code.

What I've done instead is basically just set the camera to the invisible object's position and rotate it separately, but it would really help a lot if I could set a plane as the position of the camera and the camera face towards the plane's normals. I don't mean to ask too much and appreciate your time but if this is possible it would be very of you to show me.
Title: Suggestions for Next Release
Post by: AGP on August 20, 2006, 09:53:58 am
Also a final suggestion: Object3D.addChild(Camera). Now that is cool.
Title: Suggestions for Next Release
Post by: EgonOlsen on August 20, 2006, 11:05:22 am
The code works for me. It has to be called every single frame of course. Take the car example that comes with jPCT and put this

Code: [Select]
camera.setBack(car.getWorldTransformation().invert3x3());
camera.setPosition(car.getTransformedCenter());


at the very end of the moveCamera()-method and you'll see what it's supposed to do. If you are calling it every frame and it still doesn't work, please provide me with a test case that demonstrates the problem, so i see what's wrong.

About the addChild(<Camera>)...no, that wouldn't be cool, because it makes the camera part of the scene graph, which it shouldn't be by design. If you want that, do it yourself. The code above should do it. If it doesn't, well...then please provide me with the mentioned test case, so i can check this out.
Title: Suggestions for Next Release
Post by: AGP on August 23, 2006, 12:48:15 am
Test case sent. Please prove me wrong because the code really doesn't seem to work. Thanks in advance.
Title: Suggestions for Next Release
Post by: AGP on August 23, 2006, 09:15:02 pm
Did you see it yet, Egon? Any suggestion?
Title: Suggestions for Next Release
Post by: Melssj5 on August 23, 2006, 10:37:44 pm
Hi, I just have downloaded your code and barely checked it, I never have done something like a follower. And I have been bussy, but as now I am bored on my job lets see.

I could see you are calling to follow on each iteration

just set the cam position and after that move it the 600 units, I dont know why do you the 2 last lines of code.

I may check it on my house today.

So, which behaviour do you got?
Title: Suggestions for Next Release
Post by: AGP on August 23, 2006, 11:15:33 pm
Sorry about the confusion: what I sent you was just a quick-and-dirty little program in which the x-Wing doesn't even turn around. But you have to imagine the camera following the x-Wing turning constantly on screen.
Title: Suggestions for Next Release
Post by: Melssj5 on August 24, 2006, 06:19:05 pm
Egon wont be here until 28th, in fact he disconnected just a few seconds before you sent the mail. bad luck I guess, but I suggest this.

do this on any iteration:

camera.setPosition (xWing.getTranslation ());

camera.moveCamera(Camera.CAMERA_MOVEOUT, 600);

camera.lookAt (xWing);


and  thats all, it should work. I cant test it bt is an idea. I couldnt check your code on my house . Hope this help.
Title: Suggestions for Next Release
Post by: AGP on August 24, 2006, 07:41:27 pm
Try it out. If it worked I would have done it. Trust me, following is complicated. But I appreciate the suggestion.