* This method should be typically called from render in all derived classes.
* This one just modifies the current ModelView matrix by this node's offset, rotation and scale.
* @param g GLAutoDrawable
*/
public void render( GLAutoDrawable g )
{
GL gl = g.getGL();
gl.glTranslated( translation.getX(), translation.getY(), translation.getZ() ); // modify current model view matrix with this translation.
gl.glScaled( scale.getX( ), scale.getY( ), scale.getZ( ) ); // scale relative to the parent.
gl.glRotated( rotation_angle, rotation.getX(), rotation.getY(), rotation.getZ() ); // rotate around rotation by rotation_angle
if( display_list != no_disp_list && show ) gl.glCallList( display_list ); // if needed, call display list.
}
public static void hideTree( ANode root )
{
if( root == null ) return;
root.show = false;
for( Object kid : root.children )
{
hideTree( (ANode)kid );
}
}
public static void showTree( ANode root )
{
if( root == null ) return;
root.show = true;
for( Object kid : root.children )
{
showTree( (ANode)kid );
}
}
/**
* This static function renders the tree with root as the root.
* @param contex GLAutoDrawable
* @param root ANode
*/
static public void renderTree( GLAutoDrawable contex, ANode root )
{
GL gl = contex.getGL();
if( root.pushPop( ) ) gl.glPushMatrix(); // push current model view matrix on the stack, if pushPop is true
root.render( contex ); // render current node. This will potentialy affect modelview matrix.
for( Object child : root.children ){ renderTree( contex, ((ANode)child) );} // render the children. Notice that modelview matrix affecting these children is modified by previous call to root.render()
if( root.pushPop( ) ) gl.glPopMatrix(); // // pop current model view matrix from the stack, if pushPop is true
}
/**
* counts the number of nodes in the tree with root as root.
* @param root ANode - root to the tree to count nodes of.
* @return int - number of nodes in root.
*/
static public int countNodes( ANode root )
{
return countNodes( root, 0 );
}
/**
* counts the number of nodes in the tree with root as root.
* @param root ANode - root to the tree to count nodes of.
* @param count int - current count.
* @return int - number of nodes in root.
*/
static private int countNodes( ANode root, int count )
{
int c = count + 1;
if( root.children.size() == 0 ) { return c; }
for( Object n : root.children )
{
c += countNodes( (ANode)n, count);
}
return c;
}
public boolean pushPop( ){ return ppop; }
public void setPushPop( boolean a ){ ppop = a; }
/**
* computes a normal between (a-c)x(b-c)
* @param a Coordinate
* @param b Coordinate
* @param c Coordinate
* @return Coordinate
*/
public static Coordinate getNormal( Coordinate a, Coordinate b, Coordinate c )
{
Coordinate tmp = new Coordinate( -c.getX(), -c.getY(), -c.getZ() );