0

I am implementing a project like Notch's "breaking the tower", in Java. I have it mostly written, but I'm having difficulty with z-order.

When the objects "rotate" around the center they still draw on top of each other badly. For example a tree in the background might draw on top of a tree "in front" of it.

can anyone suggest an algorithm that would help me solve the problem? ...or maybe help explain the full concept of z-ordering or even possibly give another solution.

thanks

4

1 に答える 1

0

あなたがしたいことは、z座標で配列を作成し、配列をソートしてから、オブジェクトをその場所に変換することに戻ると思います。例えば:

TransformGroup translate(Node node,Vector3f vector){

    Transform3D transform3D = new Transform3D();
    transform3D.setTranslation(vector);
    TransformGroup transformGroup = new TransformGroup();
    transformGroup.setTransform(transform3D);
    transformGroup.addChild(node);
    return transformGroup;
}    
for(int i=0;vec[i];i++)
 translate(Your_Object,new Vector3f(x,y,vec[i]);
//do this while you still have elements in your vector. 
//you may want to set a value, let's say 2500 that  indicates that you ran out of objects
//in that case, you will have for(int i=0;vec[i]!=2500;i++)

したがって、このように、オブジェクトを積み重ねるのではなく、オブジェクトを別のオブジェクトの前に配置する必要があります。

お役に立てば幸いです、マイク

于 2012-10-31T15:43:00.993 に答える