Author Topic: cloning an extended Object3D  (Read 2073 times)

Offline fireside

  • double
  • *****
  • Posts: 605
    • View Profile
cloning an extended Object3D
« on: December 19, 2010, 12:05:51 am »
Maybe this is obvious, but I'm not much of a programmer.  How do I clone an extended Object3D class?  The clone() function returns an Object3D.
click here->Fireside 7 Games<-

Offline paulscode

  • double
  • *****
  • Posts: 863
    • View Profile
    • PaulsCode.Com
Re: cloning an extended Object3D
« Reply #1 on: December 19, 2010, 12:56:32 am »
I'm pretty sure this would have to be done by overriding the clone() method and do everything the current clone() method does plus inheriting any additional properties that you've added to your extended class.  I personally prefer to wrap Object3D in my new classes rather than extending it (makes things like this easier to do without having the jPCT sourcecode to reference).

Offline fireside

  • double
  • *****
  • Posts: 605
    • View Profile
Re: cloning an extended Object3D
« Reply #2 on: December 19, 2010, 05:41:14 am »
What kind of hit would I take if I make new instances for moving characters?
edit: I guess I'll just put about 20 in a scene and see how it works.  If not, I'll try to figure out a wrapper.  The problem is I extended everything from an actor class, so there are two extensions above Object3D.
BTW, if anyone can post a brief summary on how they clone characters with animations in a class and still get access from the world, I'd appreciate it.
« Last Edit: December 19, 2010, 07:03:13 pm by fireside »
click here->Fireside 7 Games<-

Offline paulscode

  • double
  • *****
  • Posts: 863
    • View Profile
    • PaulsCode.Com
Re: cloning an extended Object3D
« Reply #3 on: December 19, 2010, 08:17:45 pm »
I haven't personally done any cloning with animations yet, so I'll leave that question to someone else who has.  For the basic Object3D wrapped into a class, I use a simple infrastructure like this:

Code: [Select]
public class SuperObject3D
{
    private Object3D basicObject3D = null;
    // Other variables, properties, etc ..

    public SuperObject3D( Object3D obj /*args for other properties*/ )
    {
        basicObject3D = obj;
        // Set other variables, properties, etc ...
    }

    public SuperObject3D cloneObject()
    {
        return ( new SuperObject3D( basicObject3D.cloneObject() /*other args*/ ) );
    }
}

And then I extend that for various subcategories of objects.  I would think that you could use the same infrastructure for animations -- doesn't cloneObject() also clone the Object3D's animations as well?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11775
    • View Profile
    • http://www.jpct.net
Re: cloning an extended Object3D
« Reply #4 on: December 19, 2010, 08:40:01 pm »
You can simply use the Object3D(<Object3D>)-constructors for this. I'm doing this the Robombs sources, so you can have a look there if you want to.

Offline fireside

  • double
  • *****
  • Posts: 605
    • View Profile
Re: cloning an extended Object3D
« Reply #5 on: December 19, 2010, 11:54:28 pm »
I'm currently using the Object3D(Object3D) for my extended class constructors, but I don't understand how to clone my extended class, since Object3d.cloneObject() returns an Object3D, so if I do an extendedClass ec = extendedClassInstance.cloneObect(), I get imcompatible types because it returns an Object3D.
I looked at robombs source but it's over my head.
Would I send the cloned Object3D back into the constructor of my extended class, but then it seems it would no longer need the animations added which come after the constructor?
« Last Edit: December 20, 2010, 12:04:44 am by fireside »
click here->Fireside 7 Games<-

Offline fireside

  • double
  • *****
  • Posts: 605
    • View Profile
Re: cloning an extended Object3D
« Reply #6 on: December 20, 2010, 05:04:07 am »
It works to send a cloned object in the constructor as long as I clear translation for some reason.  I only load the animation on the first instance and all of them are animating.  If I don't clear translation first I get odd behavior on the first move.
« Last Edit: December 20, 2010, 05:07:15 am by fireside »
click here->Fireside 7 Games<-

Offline raft

  • quad
  • ******
  • Posts: 1971
    • View Profile
    • http://www.aptalkarga.com
Re: cloning an extended Object3D
« Reply #7 on: December 20, 2010, 07:34:08 pm »
..but I don't understand how to clone my extended class, since Object3d.cloneObject() returns an Object3D, so if I do an extendedClass ec = extendedClassInstance.cloneObect(), I get imcompatible types because it returns an Object3D.
not true. since java 5, java supports covariant return types. that means when you override a method, your return type can be a sub type of original return type.

hence below is perfectly legal:
Code: [Select]
public class Extended extends Object3D {
  public Extended clone() {
     //..
  }
}

but dont go too fancy about coveriant return types. indeed i had a bug report about this

Offline fireside

  • double
  • *****
  • Posts: 605
    • View Profile
Re: cloning an extended Object3D
« Reply #8 on: December 20, 2010, 10:11:48 pm »
Thanks, I'll do more studying on that.  I hadn't heard of it. 
click here->Fireside 7 Games<-