#!/usr/bin/env python
# -*- coding: iso-8859-1 -*-
"""DOCS HERE.
"""

# Copyright (C) 2010
# $Id: scene_element_line_segment.py 1916 2006-11-21 17:21:05Z  $
__version__ = "$Revision: 1 $"[11:-2]

# NUMPY lib
import numpy as np

# FrustumTracer CORE Classes
from scene_element import *

# --------------------------------------------------------------------------------------------------

class SceneElementLineSegment( SceneElement ):
    element_type = "SceneElementLineSegment"

    def __init__( self, element_name, vertex_0, vertex_1 ):
        SceneElement.__init__(self, element_name)

        # a SceneElementSegment is a collection of two vertexes
        self.addVertex(vertex_0)
        self.addVertex(vertex_1)

    def calculateNormal(self):
        self.normal = self.normalizeNumpyArray(self.vertex_list[1] - self.vertex_list[0])

    def calculateCenter(self):
        self.center = ( self.vertex_list[0] + self.vertex_list[1] ) / 2.0

    def renderToNodePath(self):
        # Step 0: check if the element is visible
        if not self.element_is_renderizable: return None

        # Step 1: create line
        line_segment = LineSegs()
        line_segment.moveTo( self.vertex_list[0][0], self.vertex_list[0][1], self.vertex_list[0][2] )
        line_segment.drawTo( self.vertex_list[1][0], self.vertex_list[1][1], self.vertex_list[1][2] )

        # Step 2: create Node and NodePath
        self.node_path = NodePath( line_segment.create() )

        # Step 3: set Rendering Properties
        self.node_path.setColor(self.element_color_rgba)
        self.node_path.setCollideMask(self.element_collide_mask)

        return self.node_path

# --------------------------------------------------------------------------------------------------
