www.jpct.net

jPCT-AE - a 3d engine for Android => Support => Topic started by: bionicoz on April 18, 2011, 04:51:41 pm

Title: Extending Camera Class
Post by: bionicoz on April 18, 2011, 04:51:41 pm
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:
Code: [Select]
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.




Title: Re: Extending Camera Class
Post by: EgonOlsen on April 18, 2011, 09:12:48 pm
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(...);
Title: Re: Extending Camera Class
Post by: Kaiidyn on April 18, 2011, 09:35:38 pm
try to put the jpct camera in the constructor of myCamera

Code: [Select]

private cam = null;

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

now you can use this.cam in your class..
and call it by using
Code: [Select]
MyCamera myCamera = new myCamera(world.getCamera());
something like that.
Title: Re: Extending Camera Class
Post by: bionicoz on April 19, 2011, 09:52:02 am
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.