Author Topic: Extending Camera Class  (Read 1424 times)

Offline bionicoz

  • byte
  • *
  • Posts: 10
    • View Profile
Extending Camera Class
« 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.





Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11747
    • View Profile
    • http://www.jpct.net
Re: Extending Camera Class
« Reply #1 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(...);

Offline Kaiidyn

  • long
  • ***
  • Posts: 103
    • View Profile
Re: Extending Camera Class
« Reply #2 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.
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

Offline bionicoz

  • byte
  • *
  • Posts: 10
    • View Profile
Re: Extending Camera Class
« Reply #3 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.