Commits

filipkunc  committed 8af994d

Vertex Tool Hints.

  • Participants
  • Parent commits 6c31512

Comments (0)

Files changed (5)

File Classes/MyDocument.cpp

     [vertexWindowController showWindow:nil];
 }
 
-- (BOOL)addVertexEnabled
+- (BOOL)vertexToolEnabled
 {
     if (vertexWindowController.isWindowLoaded)
     {
     return NO;
 }
 
-- (void)addVertex:(Vector3D)position fromCamera:(Camera *)camera
+- (void)vertexAddOrConnect:(Vector3D)position fromCamera:(Camera *)camera
 {
     if (vertexWindowController.isWindowLoaded && vertexWindowController.window.isVisible)
     {
     }
 }
 
+- (void)vertexAddOrConnectHint:(Vector3D)position fromCamera:(Camera *)camera vertices:(vector<Vector3D> *)vertices
+{
+    if (vertexWindowController.isWindowLoaded && vertexWindowController.window.isVisible)
+    {
+        Mesh2 *mesh = [self currentMesh];
+        switch (vertexWindowController.vertexMode)
+        {
+            case VertexWindowMode::Add:
+                vertices->push_back(position);
+                break;
+            case VertexWindowMode::Connect:
+            {
+                vector<VertexNode *> vertexNodes;
+                for (uint i = 0; i < 4; i++)
+                {
+                    VertexNode *nearestVertex = mesh->findNearestVertex(position, vertexNodes);
+                    vertexNodes.push_back(nearestVertex);
+                    vertices->push_back(nearestVertex->data().position);
+                }
+            }
+                break;
+            default:
+                break;
+        }
+    }
+}
+
 - (NSString *)windowNibName
 {
     // Override returning the nib file name of the document

File Classes/OpenGLSceneView.cpp

     virtual void manipulationEnded() { [_sceneView.delegate manipulationEndedInView:_sceneView]; }
     virtual void selectionChanged() { [_sceneView.delegate selectionChangedInView:_sceneView]; }
     virtual bool texturePaintEnabled() { return [_sceneView.delegate texturePaintEnabled]; }
-    virtual bool addVertexEnabled() { return [_sceneView.delegate addVertexEnabled]; }
-    virtual void addVertex(Vector3D position, Camera *camera) { [_sceneView.delegate addVertex:position fromCamera:camera]; }
+    virtual bool vertexToolEnabled() { return [_sceneView.delegate vertexToolEnabled]; }
+    virtual void vertexAddOrConnect(Vector3D position, Camera *camera) { [_sceneView.delegate vertexAddOrConnect:position fromCamera:camera]; }
+    virtual void vertexAddOrConnectHint(Vector3D position, Camera *camera, vector<Vector3D> &vertices) { [_sceneView.delegate vertexAddOrConnectHint:position fromCamera:camera vertices:&vertices]; }
     virtual void makeCurrentContext() { [[_sceneView openGLContext] makeCurrentContext]; }
 };
 

File Classes/OpenGLSceneView.h

 @property (readonly) NSColor *brushColor;
 @property (readonly) float brushSize;
 @property (readonly) BOOL texturePaintEnabled;
-@property (readonly) BOOL addVertexEnabled;
+@property (readonly) BOOL vertexToolEnabled;
 
-- (void)addVertex:(Vector3D)position fromCamera:(Camera *)camera;
+- (void)vertexAddOrConnect:(Vector3D)position fromCamera:(Camera *)camera;
+- (void)vertexAddOrConnectHint:(Vector3D)position fromCamera:(Camera *)camera vertices:(vector<Vector3D> *)vertices;
 
 @end
 

File Classes/OpenGLSceneViewCore.cpp

 	glDisable(GL_DEPTH_TEST);
 	glEnable(GL_BLEND);
     
+    glColor3f(1.0f, 0.0f, 0.0f);
+    glBegin(GL_POINTS);
+    for (uint i = 0; i < _vertexHints.size(); i++)
+    {
+        glVertex3f(_vertexHints[i].x, _vertexHints[i].y, _vertexHints[i].z);
+    }
+    glEnd();
+    
     drawCurrentManipulator();
     
     drawOrthoDefaultManipulator();
         //[self paintOnTextureWithFirstPoint:lastPoint secondPoint:lastPoint];
         return;
     }
-    else if (_delegate->addVertexEnabled())
+    else if (_delegate->vertexToolEnabled())
     {
         Vector3D position = addVertexPositionFromPoint(point);
-        _delegate->addVertex(position, _camera);
+        _delegate->vertexAddOrConnect(position, _camera);
     }
 	else if (_manipulated != NULL && _manipulated->selectedCount() > 0 && _currentManipulator->selectedIndex < UINT_MAX)
 	{
 
 void OpenGLSceneViewCore::mouseMoved(NSPoint point)
 {
+    _vertexHints.clear();
     _highlightCameraMode = false;
 	_currentPoint = point;
 	if (_manipulated != NULL && _manipulated->selectedCount() > 0)
 			_highlightCameraMode = true;
         _delegate->setNeedsDisplay();
 	}
+    
+    if (_delegate->vertexToolEnabled())
+    {
+        Vector3D position = addVertexPositionFromPoint(point);
+        _delegate->vertexAddOrConnectHint(position, _camera, _vertexHints);
+        _delegate->setNeedsDisplay();
+    }
 }
 
 void OpenGLSceneViewCore::mouseExited()

File Classes/OpenGLSceneViewCore.h

     virtual void manipulationEnded() = 0;
     virtual void selectionChanged() = 0;
     virtual bool texturePaintEnabled() = 0;
-    virtual bool addVertexEnabled() = 0;
-    virtual void addVertex(Vector3D position, Camera *camera) = 0;
+    virtual bool vertexToolEnabled() = 0;
+    virtual void vertexAddOrConnect(Vector3D position, Camera *camera) = 0;
+    virtual void vertexAddOrConnectHint(Vector3D position, Camera *camera, vector<Vector3D> &vertices) = 0;
     virtual void makeCurrentContext() = 0;
 };
 
 	Manipulator *_scaleManipulator;
 	Manipulator *_currentManipulator;
 	CameraMode _cameraMode;
+    vector<Vector3D> _vertexHints;
     
     static bool _alwaysSelectThrough;    
 public: