Normand Briere
2019-12-25 3d30e720e6f012f2d9996b136154dd551844998a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
 
/**
 *
 * @author nbriere
 */
public class BillboardNode extends Composite implements java.io.Serializable
{
    static final long serialVersionUID = 0;
    
    BillboardNode()
    {
        super("Billboard");
        
        toParent = LA.newMatrix();
        fromParent = LA.newMatrix();
    }
    
    cVector pos = new cVector();
        
    void draw(iCameraPane display, Object3D /*Composite*/ root, boolean selected, boolean blocked)
    {
        cVector eye = display.EyeCamera().location;
        
        GlobalTransformInv();
 
        pos.x = parent.globalTransform[3][0];
        pos.y = parent.globalTransform[3][1];
        pos.z = parent.globalTransform[3][2];
        
        pos.x -= eye.x;
        pos.y -= eye.y;
        pos.z -= eye.z;
        
        double angle = Math.atan2(pos.x, pos.z);
        
        LA.matIdentity(toParent);
        LA.matIdentity(fromParent);
        LA.matYRotate(toParent, angle);
        LA.matYRotate(fromParent, -angle);
        
        super.draw(display, root, selected, blocked);
    }
    
    Object3D deepCopy()
    {
            Composite comp = new BillboardNode();
            deepCopySelf(comp);
            return comp;
    }
}