SegmentConnectionHandle.cpp

Go to the documentation of this file.
00001 
00005 /* Copyright © 2009, 2010 James Legg.
00006     This program is free software: you can redistribute it and/or modify
00007     it under the terms of the GNU General Public License as published by
00008     the Free Software Foundation, either version 3 of the License, or
00009     (at your option) any later version.
00010 */
00011 
00012 #include "SegmentConnectionHandle.h"
00013 
00014 #include <GL/gl.h>
00015 
00016 #include "../document/InsertEdgeDelta.h"
00017 
00018 #include "../Track.h"
00019 
00020 
00021 namespace Track
00022 {
00023 
00024 namespace EditAssist
00025 {
00026 
00027 SegmentConnectionHandle::SegmentConnectionHandle(const Track & track, std::size_t vertex_name, std::size_t connection_index, const SegmentConnection * segment_connection)
00028     :   track(track)
00029     ,   vertex_name(vertex_name)
00030     ,   connection_index(connection_index)
00031     ,   segment_connection(segment_connection)
00032 {
00033     DEBUG_MESSAGE("Created " << this);
00034 }
00035 
00036 SegmentConnectionHandle::~SegmentConnectionHandle()
00037 {
00038     DEBUG_MESSAGE("Destroyed " << this);
00039 }
00040 
00041 void SegmentConnectionHandle::draw() const
00042 {
00043     glColor3ub(255, 0, 255);
00044     glBegin(GL_POINTS);
00045         glVertex3f(position.x(), position.y(), position.z());
00046     glEnd();
00047 }
00048 
00049 void SegmentConnectionHandle::snap(btVector3 & new_position, btVector3 normal) const
00050 {
00052     const SegmentConnectionHandle * other = track.get_path().get_nearest_segment_connection_handle(new_position, normal);
00053     if (other)
00054     {
00055         new_position = other->position;
00056     }
00057 }
00058 
00059 boost::shared_ptr<Document::DocumentDelta> SegmentConnectionHandle::make_delta(btVector3 new_position) const
00060 {
00061     const Path & path = track.get_path();
00062     const SegmentConnectionHandle * other = path.get_nearest_segment_connection_handle(new_position);
00063     if (other && other != this)
00064     {
00065         btScalar gradient_strength = position.distance(other->position) / 2.5;
00066         const Theme & theme = track.get_theme();
00067         PathEdge edge(theme);
00068         edge.segment_index = theme.get_default_segment_index();
00069         edge.segment = &(theme.get_segment(edge.segment_index));
00070         edge.start.segment_connection_index = connection_index;
00071         edge.start.gradient_strength = gradient_strength;
00072         edge.finish.segment_connection_index = other->connection_index;
00073         edge.finish.gradient_strength = gradient_strength;
00074         edge.render_mode = path.editor ? DrawableMesh::RM_WIREFRAME : DrawableMesh::RM_SOLID;
00075         DEBUG_MESSAGE(this << " is about to update its new edge connecting v" << vertex_name << ".c" << connection_index << " to v" << other->vertex_name << ".c" << other->connection_index << ".");
00076         edge.update(vertex_name, other->vertex_name, &(path));
00077         return boost::shared_ptr<Document::DocumentDelta>(new Document::InsertEdgeDelta(edge));
00078     }
00079     // no valid connection to make. Return null pointer.
00080     return boost::shared_ptr<Document::DocumentDelta>();
00081 }
00082 
00083 } // namespace EditAssist
00084 
00085 } // namespace Track

Get Racer at SourceForge.net. Fast, secure and Free Open Source software downloads

Generated at Mon Sep 6 00:41:11 2010 by Doxygen version 1.4.7 for Racer version svn335.