cloning an extended Object3D

Started by fireside, December 19, 2010, 12:05:51 AM

Previous topic - Next topic

fireside

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<-

paulscode

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).

fireside

#2
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.
click here->Fireside 7 Games<-

paulscode

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:

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?

EgonOlsen

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.

fireside

#5
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?
click here->Fireside 7 Games<-

fireside

#6
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.
click here->Fireside 7 Games<-

raft

Quote from: fireside on December 19, 2010, 11:54:28 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:
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

fireside

Thanks, I'll do more studying on that.  I hadn't heard of it. 
click here->Fireside 7 Games<-