Extending Camera Class

Started by bionicoz, April 18, 2011, 04:51:41 PM

Previous topic - Next topic

bionicoz

I need some method to smooth move my camera to a point in my world. I thought that the right way to do this was extending Camera class.
I did the nearly same thing with the 3DObject class. I added some methods and some fields. And everything works.
But when i do this:

myCamera cam = (myCamera)world.getCamera();

I get a Cast Error. I'm not a guru with Java, but I cannot understand why with 3DObject class is working and with Camera is not.
Any suggestion? Maybe a better way to add this functionality to my cam?
ty all.





EgonOlsen

You can't anything to a type that isn't of that type. Create an instance of your extended camera yourself and set it to the world via setCameraTo(...);

Kaiidyn

try to put the jpct camera in the constructor of myCamera



private cam = null;

public myCamera(camera cam){
    this.cam = cam;
}


now you can use this.cam in your class..
and call it by using
MyCamera myCamera = new myCamera(world.getCamera());

something like that.
Clean code is simple and direct. Clean code reads like well-written prose. Clean code never obscures the designer's intent but rather is full of crisp abstractions and straightforward lines of control. - Grady Booch

bionicoz

I got it working using Egon solution, but just for simplicity. Kaiidyn's one is working too.
Thanks for the great support you all offer in this forum.