]> de.git.xonotic.org Git - xonotic/netradiant.git/blobdiff - contrib/bobtoolz/DTrainDrawer.cpp
Prevent implicit Widget construction
[xonotic/netradiant.git] / contrib / bobtoolz / DTrainDrawer.cpp
index 83ddc3eca3505c0745e859d1a69bba6e4be90b65..da7edcc1bd0ee568892cf4f4dc74653d87108027 100644 (file)
-/*\r
-BobToolz plugin for GtkRadiant\r
-Copyright (C) 2001 Gordon Biggans\r
-\r
-This library is free software; you can redistribute it and/or\r
-modify it under the terms of the GNU Lesser General Public\r
-License as published by the Free Software Foundation; either\r
-version 2.1 of the License, or (at your option) any later version.\r
-\r
-This library is distributed in the hope that it will be useful,\r
-but WITHOUT ANY WARRANTY; without even the implied warranty of\r
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\r
-Lesser General Public License for more details.\r
-\r
-You should have received a copy of the GNU Lesser General Public\r
-License along with this library; if not, write to the Free Software\r
-Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA\r
-*/\r
-\r
-#include "StdAfx.h"\r
-#include "DPoint.h"\r
-\r
-#include "DTrainDrawer.h"\r
-#include "DEPair.h"\r
-\r
-#include "misc.h"\r
-#include "funchandlers.h"\r
-\r
-#include "dialogs/dialogs-gtk.h"\r
-\r
-DTrainDrawer::DTrainDrawer() {\r
-       refCount = 1;\r
-       m_bHooked = FALSE;\r
-       m_bDisplay = FALSE;\r
-\r
-       BuildPaths();\r
-}\r
-\r
-DTrainDrawer::~DTrainDrawer(void) {\r
-       if(m_bHooked)\r
-               UnRegister();\r
-\r
-       ClearPoints();\r
-       ClearSplines();\r
-}\r
-\r
-void DTrainDrawer::ClearSplines() {\r
-       for(list<splinePoint_t *>::const_iterator deadSpline = m_splineList.begin(); deadSpline != m_splineList.end(); deadSpline++) {\r
-               (*deadSpline)->m_pointList.clear();\r
-               (*deadSpline)->m_vertexList.clear();\r
-               delete (*deadSpline);\r
-       }\r
-\r
-       m_splineList.clear();\r
-}\r
-\r
-void DTrainDrawer::ClearPoints() {\r
-       for(list<controlPoint_t *>::const_iterator deadPoint = m_pointList.begin(); deadPoint != m_pointList.end(); deadPoint++) {\r
-               delete *deadPoint;\r
-       }\r
-\r
-       m_pointList.clear();\r
-}\r
-\r
-void DTrainDrawer::Register() {\r
-       g_QglTable.m_pfnHookGL2DWindow( this );\r
-       g_QglTable.m_pfnHookGL3DWindow( this );\r
-       m_bHooked = TRUE;\r
-}\r
-\r
-void DTrainDrawer::UnRegister() {\r
-       g_QglTable.m_pfnUnHookGL2DWindow( this );\r
-       g_QglTable.m_pfnUnHookGL3DWindow( this );\r
-       m_bHooked = FALSE;\r
-}\r
-\r
-void CalculateSpline_r(vec3_t* v, int count, vec3_t out, float tension) {\r
-       vec3_t dist;\r
-\r
-       if(count < 2) {\r
-               return;\r
-       }\r
-\r
-       if(count == 2) {\r
-               VectorSubtract( v[1], v[0], dist );\r
-               VectorMA(v[0], tension, dist, out);\r
-               return;\r
-       }\r
-\r
-       vec3_t* v2 = new vec3_t[count-1];\r
-\r
-       for( int i = 0; i < count-1; i++ ) {\r
-               VectorSubtract( v[i+1], v[i], dist );\r
-               VectorMA(v[i], tension, dist, v2[i]);\r
-       }\r
-\r
-       CalculateSpline_r( v2, count-1, out, tension);\r
-\r
-       delete[] v2;\r
-}\r
-\r
-void DTrainDrawer::Draw3D() {\r
-\r
-       if(!m_bDisplay) {\r
-               return;\r
-       }\r
-\r
-       g_QglTable.m_pfn_qglPushAttrib(GL_ALL_ATTRIB_BITS);\r
-\r
-       g_QglTable.m_pfn_qglDisable(GL_BLEND);\r
-       g_QglTable.m_pfn_qglDisable(GL_LINE_SMOOTH);\r
-\r
-       g_QglTable.m_pfn_qglPushMatrix();\r
-       \r
-       g_QglTable.m_pfn_qglLineWidth(2.0f);\r
-       g_QglTable.m_pfn_qglColor4f(1.0f, 1.0f, 1.0f, 1.0f);\r
-\r
-       g_QglTable.m_pfn_qglEnable(GL_BLEND);\r
-       g_QglTable.m_pfn_qglBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);\r
-       g_QglTable.m_pfn_qglDisable(GL_POLYGON_SMOOTH);\r
-\r
-       g_QglTable.m_pfn_qglDepthFunc(GL_ALWAYS);\r
-\r
-       for(list<splinePoint_t* >::const_iterator sp = m_splineList.begin(); sp != m_splineList.end(); sp++) {\r
-               splinePoint_t* pSP = (*sp);\r
-\r
-               g_QglTable.m_pfn_qglBegin(GL_LINE_STRIP);\r
-                       for(list<DPoint >::const_iterator v = pSP->m_vertexList.begin(); v != pSP->m_vertexList.end(); v++) {\r
-                               g_QglTable.m_pfn_qglVertex3fv((*v)._pnt);\r
-                       }\r
-               g_QglTable.m_pfn_qglEnd();\r
-\r
-       }\r
-\r
-       g_QglTable.m_pfn_qglPopMatrix();\r
-       g_QglTable.m_pfn_qglPopAttrib();\r
-}\r
-\r
-void DTrainDrawer::Draw2D(VIEWTYPE vt) {\r
-\r
-       if(!m_bDisplay) {\r
-               return;\r
-       }\r
-\r
-       g_QglTable.m_pfn_qglPushAttrib(GL_ALL_ATTRIB_BITS);\r
-\r
-       g_QglTable.m_pfn_qglDisable(GL_BLEND);\r
-       g_QglTable.m_pfn_qglDisable(GL_LINE_SMOOTH);\r
-\r
-       g_QglTable.m_pfn_qglPushMatrix();\r
-       \r
-       switch(vt)\r
-       {\r
-       case XY:\r
-               break;\r
-       case XZ:\r
-               g_QglTable.m_pfn_qglRotatef(270.0f, 1.0f, 0.0f, 0.0f);\r
-               break;\r
-       case YZ:\r
-               g_QglTable.m_pfn_qglRotatef(270.0f, 1.0f, 0.0f, 0.0f);\r
-               g_QglTable.m_pfn_qglRotatef(270.0f, 0.0f, 0.0f, 1.0f);\r
-               break;\r
-       }\r
-\r
-       g_QglTable.m_pfn_qglLineWidth(1.0f);\r
-       g_QglTable.m_pfn_qglColor4f(1.0f, 0.0f, 0.0f, 0.5f);\r
-\r
-       g_QglTable.m_pfn_qglEnable(GL_BLEND);\r
-       g_QglTable.m_pfn_qglBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);\r
-       g_QglTable.m_pfn_qglDisable(GL_POLYGON_SMOOTH);\r
-\r
-       g_QglTable.m_pfn_qglDepthFunc(GL_ALWAYS);\r
-\r
-       g_QglTable.m_pfn_qglColor4f(1.f, 0.f, 0.f, 1.f);\r
-\r
-       for(list<splinePoint_t* >::const_iterator sp = m_splineList.begin(); sp != m_splineList.end(); sp++) {\r
-               splinePoint_t* pSP = (*sp);\r
-\r
-               g_QglTable.m_pfn_qglBegin(GL_LINE_STRIP);\r
-                       for(list<DPoint >::const_iterator v = pSP->m_vertexList.begin(); v != pSP->m_vertexList.end(); v++) {\r
-                               g_QglTable.m_pfn_qglVertex3fv((*v)._pnt);\r
-                       }\r
-               g_QglTable.m_pfn_qglEnd();\r
-\r
-       }\r
-\r
-       g_QglTable.m_pfn_qglPopMatrix();\r
-       g_QglTable.m_pfn_qglPopAttrib();\r
-}\r
-\r
-void AddSplineControl(const char* control, splinePoint_t* pSP) {\r
-       controlPoint_t cp;\r
-       strncpy(cp.strName,     control, 64);\r
-\r
-       pSP->m_pointList.push_front(cp);\r
-}\r
-\r
-void DTrainDrawer::BuildPaths() {\r
-       int count = g_FuncTable.m_pfnGetEntityCount();\r
-\r
-       DEntity e;\r
-\r
-       for(int i = 0; i < count; i++) {\r
-               entity_s* ent = (entity_s*)g_FuncTable.m_pfnGetEntityHandle(i);\r
-               e.ClearEPairs();\r
-               e.LoadEPairList(*g_EntityTable.m_pfnGetEntityKeyValList(ent));\r
-\r
-               const char* classname = e.m_Classname.GetBuffer();\r
-               const char* target;\r
-               const char* control;\r
-               const char* targetname;\r
-               vec3_t          vOrigin;\r
-\r
-               e.SpawnString("targetname", NULL, &targetname);\r
-               e.SpawnVector("origin", "0 0 0", vOrigin);\r
-\r
-               if(!strcmp(classname, "info_train_spline_main")) {\r
-                       if(!targetname) {\r
-                               Sys_Printf( "info_train_spline_main with no targetname" );\r
-                               return;\r
-                       }\r
-\r
-                       e.SpawnString("target", NULL, &target);\r
-\r
-                       if(!target) {\r
-                               AddControlPoint( targetname, vOrigin );\r
-                       } else {\r
-                               splinePoint_t* pSP = AddSplinePoint( targetname, target, vOrigin );\r
-\r
-                               e.SpawnString("control", NULL, &control);\r
-\r
-                               if(control) {\r
-                                       AddSplineControl( control, pSP );\r
-\r
-                                       for(int j = 2;; j++) {\r
-                                               char buffer[16];\r
-                                               sprintf(buffer, "control%i", j);\r
-\r
-                                               e.SpawnString(buffer, NULL, &control);\r
-                                               if(!control) {\r
-                                                       break;\r
-                                               }\r
-                                       \r
-                                               AddSplineControl( control, pSP );\r
-                                       }\r
-                               }\r
-                       }\r
-               } else if(!strcmp(classname, "info_train_spline_control")) {\r
-                       if(!targetname) {\r
-                               Sys_Printf( "info_train_spline_control with no targetname" );\r
-                               return;\r
-                       }\r
-\r
-                       AddControlPoint( targetname, vOrigin );\r
-               }\r
-       }\r
-\r
-  list<splinePoint_t* >::const_iterator sp;\r
-       for(sp = m_splineList.begin(); sp != m_splineList.end(); sp++) {\r
-               splinePoint_t* pSP = (*sp);\r
-\r
-               controlPoint_t* pTarget = FindControlPoint( pSP->strTarget );\r
-\r
-               if(!pTarget) {\r
-                       Sys_Printf( "couldn't find target %s", pSP->strTarget );\r
-                       return;\r
-//                     continue;\r
-               }\r
-\r
-               pSP->pTarget = pTarget;\r
-\r
-\r
-               for(list<controlPoint_t >::iterator cp = pSP->m_pointList.begin(); cp != pSP->m_pointList.end(); cp++) {                        \r
-                       controlPoint_t* pControl = FindControlPoint( (*cp).strName );\r
-                       if(!pControl) {\r
-                               Sys_Printf( "couldn't find control %s", (*cp).strName );\r
-                               return;\r
-                       }\r
-\r
-                       VectorCopy(pControl->vOrigin, (*cp).vOrigin);\r
-               }\r
-       }\r
-\r
-       m_bDisplay = TRUE;\r
-       Register();\r
-\r
-       for(sp = m_splineList.begin(); sp != m_splineList.end(); sp++) {\r
-               splinePoint_t* pSP = (*sp);\r
-               DPoint out;\r
-\r
-               if(!pSP->pTarget) {\r
-                       continue;\r
-               }\r
-\r
-               int count = pSP->m_pointList.size() + 2;\r
-               vec3_t* v = new vec3_t[count];\r
-\r
-               VectorCopy(pSP->point.vOrigin, v[0]);\r
-\r
-               int i = 1;\r
-               for(list<controlPoint_t>::reverse_iterator cp = pSP->m_pointList.rbegin(); cp != pSP->m_pointList.rend(); cp++) {\r
-                       VectorCopy((*cp).vOrigin, v[i]);\r
-                       i++;\r
-               }\r
-               VectorCopy(pSP->pTarget->vOrigin, v[i]);\r
-\r
-               for (float tension = 0.0f; tension <= 1.f; tension += 0.01f) {\r
-                       CalculateSpline_r(v, count, out._pnt, tension);\r
-                       pSP->m_vertexList.push_front(out);\r
-               }\r
-\r
-               delete[] v;\r
-\r
-               VectorCopy(pSP->pTarget->vOrigin, out._pnt);\r
-               pSP->m_vertexList.push_front(out);\r
-       }\r
-\r
-\r
-}\r
-\r
-void DTrainDrawer::AddControlPoint(const char* name, vec_t* origin)\r
-{\r
-       controlPoint_t* pCP = new controlPoint_t;\r
-\r
-       strncpy(pCP->strName, name, 64);\r
-       VectorCopy( origin, pCP->vOrigin );\r
-\r
-       m_pointList.push_back( pCP );\r
-}\r
-\r
-splinePoint_t* DTrainDrawer::AddSplinePoint(const char* name, const char* target, vec_t* origin)\r
-{\r
-       splinePoint_t* pSP = new splinePoint_t;\r
-\r
-       strncpy(pSP->point.strName, name,               64);\r
-       strncpy(pSP->strTarget,         target,         64);\r
-       VectorCopy( origin, pSP->point.vOrigin );\r
-       m_splineList.push_back( pSP );\r
-\r
-       return pSP;\r
-}\r
-\r
-controlPoint_t* DTrainDrawer::FindControlPoint(const char* name)\r
-{\r
-       for(list<controlPoint_t*>::const_iterator cp = m_pointList.begin(); cp != m_pointList.end(); cp++) {\r
-               if(!strcmp(name, (*cp)->strName)) {\r
-                       return (*cp);\r
-               }\r
-       }\r
-\r
-       for(list<splinePoint_t*>::const_iterator sp = m_splineList.begin(); sp != m_splineList.end(); sp++) {\r
-               if(!strcmp(name, (*sp)->point.strName)) {\r
-                       return &((*sp)->point);\r
-               }\r
-       }\r
-\r
-       return NULL;\r
-}\r
+/*
+   BobToolz plugin for GtkRadiant
+   Copyright (C) 2001 Gordon Biggans
+
+   This library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   This library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with this library; if not, write to the Free Software
+   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+#include "DTrainDrawer.h"
+
+#include <list>
+#include "str.h"
+
+#include "DPoint.h"
+#include "DPlane.h"
+#include "DBrush.h"
+#include "DEPair.h"
+#include "DPatch.h"
+#include "DEntity.h"
+
+#include "misc.h"
+#include "funchandlers.h"
+
+#include "iglrender.h"
+#include "ientity.h"
+#include "math/matrix.h"
+
+#include "dialogs/dialogs-gtk.h"
+
+DTrainDrawer::DTrainDrawer() {
+       m_bDisplay = false;
+
+       BuildPaths();
+       constructShaders();
+       GlobalShaderCache().attachRenderable( *this );
+}
+
+DTrainDrawer::~DTrainDrawer( void ) {
+       GlobalShaderCache().detachRenderable( *this );
+       destroyShaders();
+
+       ClearPoints();
+       ClearSplines();
+}
+
+void DTrainDrawer::ClearSplines() {
+       for ( std::list<splinePoint_t *>::const_iterator deadSpline = m_splineList.begin(); deadSpline != m_splineList.end(); deadSpline++ ) {
+               ( *deadSpline )->m_pointList.clear();
+               ( *deadSpline )->m_vertexList.clear();
+               delete ( *deadSpline );
+       }
+
+       m_splineList.clear();
+}
+
+void DTrainDrawer::ClearPoints() {
+       for ( std::list<controlPoint_t *>::const_iterator deadPoint = m_pointList.begin(); deadPoint != m_pointList.end(); deadPoint++ ) {
+               delete *deadPoint;
+       }
+
+       m_pointList.clear();
+}
+
+void CalculateSpline_r( vec3_t* v, int count, vec3_t out, float tension ) {
+       vec3_t dist;
+
+       if ( count < 2 ) {
+               return;
+       }
+
+       if ( count == 2 ) {
+               VectorSubtract( v[1], v[0], dist );
+               VectorMA( v[0], tension, dist, out );
+               return;
+       }
+
+       vec3_t* v2 = new vec3_t[count - 1];
+
+       for ( int i = 0; i < count - 1; i++ ) {
+               VectorSubtract( v[i + 1], v[i], dist );
+               VectorMA( v[i], tension, dist, v2[i] );
+       }
+
+       CalculateSpline_r( v2, count - 1, out, tension );
+
+       delete[] v2;
+}
+
+void DTrainDrawer::render( RenderStateFlags state ) const {
+       for ( std::list<splinePoint_t* >::const_iterator sp = m_splineList.begin(); sp != m_splineList.end(); sp++ ) {
+               splinePoint_t* pSP = ( *sp );
+
+               glBegin( GL_LINE_STRIP );
+               for ( std::list<DPoint >::const_iterator v = pSP->m_vertexList.begin(); v != pSP->m_vertexList.end(); v++ ) {
+                       glVertex3fv( ( *v )._pnt );
+               }
+               glEnd();
+
+       }
+}
+
+const char* DTrainDrawer_state_wireframe = "$bobtoolz/traindrawer/wireframe";
+const char* DTrainDrawer_state_solid = "$bobtoolz/traindrawer/solid";
+
+void DTrainDrawer::constructShaders(){
+       OpenGLState state;
+       GlobalOpenGLStateLibrary().getDefaultState( state );
+       state.m_state = RENDER_COLOURWRITE | RENDER_DEPTHWRITE | RENDER_BLEND;
+       state.m_sort = OpenGLState::eSortOverlayFirst;
+       state.m_linewidth = 1;
+       state.m_colour[0] = 1;
+       state.m_colour[1] = 0;
+       state.m_colour[2] = 0;
+       state.m_colour[3] = 1;
+       state.m_linewidth = 1;
+       GlobalOpenGLStateLibrary().insert( DTrainDrawer_state_wireframe, state );
+
+       state.m_colour[0] = 1;
+       state.m_colour[1] = 1;
+       state.m_colour[2] = 1;
+       state.m_colour[3] = 1;
+       state.m_linewidth = 2;
+       GlobalOpenGLStateLibrary().insert( DTrainDrawer_state_solid, state );
+
+       m_shader_wireframe = GlobalShaderCache().capture( DTrainDrawer_state_wireframe );
+       m_shader_solid = GlobalShaderCache().capture( DTrainDrawer_state_solid );
+}
+
+void DTrainDrawer::destroyShaders(){
+       GlobalOpenGLStateLibrary().erase( DTrainDrawer_state_wireframe );
+       GlobalOpenGLStateLibrary().erase( DTrainDrawer_state_solid );
+       GlobalShaderCache().release( DTrainDrawer_state_wireframe );
+       GlobalShaderCache().release( DTrainDrawer_state_solid );
+}
+
+
+void DTrainDrawer::renderSolid( Renderer& renderer, const VolumeTest& volume ) const {
+       if ( !m_bDisplay ) {
+               return;
+       }
+
+       renderer.SetState( m_shader_wireframe, Renderer::eWireframeOnly );
+       renderer.SetState( m_shader_solid, Renderer::eFullMaterials );
+       renderer.addRenderable( *this, g_matrix4_identity );
+}
+void DTrainDrawer::renderWireframe( Renderer& renderer, const VolumeTest& volume ) const {
+       renderSolid( renderer, volume );
+}
+
+void AddSplineControl( const char* control, splinePoint_t* pSP ) {
+       controlPoint_t cp;
+       strncpy( cp.strName, control, 64 );
+
+       pSP->m_pointList.push_front( cp );
+}
+
+class EntityBuildPaths
+{
+mutable DEntity e;
+DTrainDrawer& drawer;
+public:
+EntityBuildPaths( DTrainDrawer& drawer ) : drawer( drawer ){
+}
+void operator()( scene::Instance& instance ) const {
+       e.ClearEPairs();
+       e.LoadEPairList( Node_getEntity( instance.path().top() ) );
+
+       const char* classname = e.m_Classname.GetBuffer();
+       const char* target;
+       const char* control;
+       const char* targetname;
+       vec3_t vOrigin;
+
+       e.SpawnString( "targetname", NULL, &targetname );
+       e.SpawnVector( "origin", "0 0 0", vOrigin );
+
+       if ( !strcmp( classname, "info_train_spline_main" ) ) {
+               if ( !targetname ) {
+                       globalOutputStream() << "info_train_spline_main with no targetname";
+                       return;
+               }
+
+               e.SpawnString( "target", NULL, &target );
+
+               if ( !target ) {
+                       drawer.AddControlPoint( targetname, vOrigin );
+               }
+               else {
+                       splinePoint_t* pSP = drawer.AddSplinePoint( targetname, target, vOrigin );
+
+                       e.SpawnString( "control", NULL, &control );
+
+                       if ( control ) {
+                               AddSplineControl( control, pSP );
+
+                               for ( int j = 2;; j++ ) {
+                                       char buffer[16];
+                                       sprintf( buffer, "control%i", j );
+
+                                       e.SpawnString( buffer, NULL, &control );
+                                       if ( !control ) {
+                                               break;
+                                       }
+
+                                       AddSplineControl( control, pSP );
+                               }
+                       }
+               }
+       }
+       else if ( !strcmp( classname, "info_train_spline_control" ) ) {
+               if ( !targetname ) {
+                       globalOutputStream() << "info_train_spline_control with no targetname";
+                       return;
+               }
+
+               drawer.AddControlPoint( targetname, vOrigin );
+       }
+}
+};
+
+void DTrainDrawer::BuildPaths() {
+       Scene_forEachEntity( EntityBuildPaths( *this ) );
+
+       std::list<splinePoint_t* >::const_iterator sp;
+       for ( sp = m_splineList.begin(); sp != m_splineList.end(); sp++ ) {
+               splinePoint_t* pSP = ( *sp );
+
+               controlPoint_t* pTarget = FindControlPoint( pSP->strTarget );
+
+               if ( !pTarget ) {
+                       globalOutputStream() << "couldn't find target " << pSP->strTarget;
+                       return;
+//                     continue;
+               }
+
+               pSP->pTarget = pTarget;
+
+
+               for ( std::list<controlPoint_t >::iterator cp = pSP->m_pointList.begin(); cp != pSP->m_pointList.end(); cp++ ) {
+                       controlPoint_t* pControl = FindControlPoint( ( *cp ).strName );
+                       if ( !pControl ) {
+                               globalOutputStream() << "couldn't find control " << ( *cp ).strName;
+                               return;
+                       }
+
+                       VectorCopy( pControl->vOrigin, ( *cp ).vOrigin );
+               }
+       }
+
+       m_bDisplay = true;
+
+       for ( sp = m_splineList.begin(); sp != m_splineList.end(); sp++ ) {
+               splinePoint_t* pSP = ( *sp );
+               DPoint out;
+
+               if ( !pSP->pTarget ) {
+                       continue;
+               }
+
+               std::size_t count = pSP->m_pointList.size() + 2;
+               vec3_t* v = new vec3_t[count];
+
+               VectorCopy( pSP->point.vOrigin, v[0] );
+
+               int i = 1;
+               for ( std::list<controlPoint_t>::reverse_iterator cp = pSP->m_pointList.rbegin(); cp != pSP->m_pointList.rend(); cp++ ) {
+                       VectorCopy( ( *cp ).vOrigin, v[i] );
+                       i++;
+               }
+               VectorCopy( pSP->pTarget->vOrigin, v[i] );
+
+               for ( float tension = 0.0f; tension <= 1.f; tension += 0.01f ) {
+                       CalculateSpline_r( v, static_cast<int>( count ), out._pnt, tension );
+                       pSP->m_vertexList.push_front( out );
+               }
+
+               delete[] v;
+
+               VectorCopy( pSP->pTarget->vOrigin, out._pnt );
+               pSP->m_vertexList.push_front( out );
+       }
+
+       SceneChangeNotify();
+}
+
+void DTrainDrawer::AddControlPoint( const char* name, vec_t* origin ){
+       controlPoint_t* pCP = new controlPoint_t;
+
+       strncpy( pCP->strName, name, 64 );
+       VectorCopy( origin, pCP->vOrigin );
+
+       m_pointList.push_back( pCP );
+}
+
+splinePoint_t* DTrainDrawer::AddSplinePoint( const char* name, const char* target, vec_t* origin ){
+       splinePoint_t* pSP = new splinePoint_t;
+
+       strncpy( pSP->point.strName, name,       64 );
+       strncpy( pSP->strTarget,     target,     64 );
+       VectorCopy( origin, pSP->point.vOrigin );
+       m_splineList.push_back( pSP );
+
+       return pSP;
+}
+
+controlPoint_t* DTrainDrawer::FindControlPoint( const char* name ){
+       for ( std::list<controlPoint_t*>::const_iterator cp = m_pointList.begin(); cp != m_pointList.end(); cp++ ) {
+               if ( !strcmp( name, ( *cp )->strName ) ) {
+                       return ( *cp );
+               }
+       }
+
+       for ( std::list<splinePoint_t*>::const_iterator sp = m_splineList.begin(); sp != m_splineList.end(); sp++ ) {
+               if ( !strcmp( name, ( *sp )->point.strName ) ) {
+                       return &( ( *sp )->point );
+               }
+       }
+
+       return NULL;
+}