Commits

filipkunc committed e0b8e6d

addVertex

Comments (0)

Files changed (5)

Classes/MyDocument.cpp

     return NO;
 }
 
+- (BOOL)addVertexEnabled
+{
+    // TODO: add tool window
+    return YES;
+}
+
+- (void)addVertex:(Vector3D)position
+{
+    Mesh2 *mesh = [self currentMesh];
+    mesh->addVertex(position);
+}
+
 - (NSString *)windowNibName
 {
     // Override returning the nib file name of the document

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) { [_sceneView.delegate addVertex:position]; }
     virtual void makeCurrentContext() { [[_sceneView openGLContext] makeCurrentContext]; }
 };
 

Classes/OpenGLSceneView.h

 @property (readonly) NSColor *brushColor;
 @property (readonly) float brushSize;
 @property (readonly) BOOL texturePaintEnabled;
+@property (readonly) BOOL addVertexEnabled;
+
+- (void)addVertex:(Vector3D)position;
 
 @end
 

Classes/OpenGLSceneViewCore.cpp

 	glEnd();
 	
 	glPopMatrix();
+    
+//    glPushMatrix();
+//    glMultMatrixf(_camera->GetRotationQuaternion().Conjugate().ToMatrix());
+//    
+//    int index = (int)PlaneAxis::Z - (int)PlaneAxis::X;
+//    
+//    drawSelectionPlane(index);
+//    
+//    glPopMatrix();
 }
 
 NSRect OpenGLSceneViewCore::orthoManipulatorRect()
 	return result;
 }
 
+Vector3D OpenGLSceneViewCore::addVertexPositionFromPoint(NSPoint point)
+{
+    _delegate->makeCurrentContext();
+    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+    glLoadMatrixf(_camera->GetViewMatrix());
+    
+    Vector3D position = _manipulated->selectionCenter();
+	
+	glPushMatrix();
+	glTranslatef(position.x, position.y, position.z);
+    glMultMatrixf(_camera->GetRotationQuaternion().Conjugate().ToMatrix());
+	DrawSelectionPlane(PlaneAxis::Z);
+	glPopMatrix();
+    
+    position = positionInSpaceByPoint(point);
+    
+    return position;
+}
+
 Vector3D OpenGLSceneViewCore::translationFromPoint(NSPoint point)
 {
 	_delegate->makeCurrentContext();
         //[self paintOnTextureWithFirstPoint:lastPoint secondPoint:lastPoint];
         return;
     }
+    else if (_delegate->addVertexEnabled())
+    {
+        Vector3D position = addVertexPositionFromPoint(point);
+        _delegate->addVertex(position);
+    }
 	else if (_manipulated != NULL && _manipulated->selectedCount() > 0 && _currentManipulator->selectedIndex < UINT_MAX)
 	{
 		if (_currentManipulator == _translationManipulator)

Classes/OpenGLSceneViewCore.h

     virtual void manipulationEnded() = 0;
     virtual void selectionChanged() = 0;
     virtual bool texturePaintEnabled() = 0;
+    virtual bool addVertexEnabled() = 0;
+    virtual void addVertex(Vector3D position) = 0;
     virtual void makeCurrentContext() = 0;
 };
 
     Vector3D positionFromAxisPoint(Axis axis, NSPoint point);
     Vector3D positionFromRotatedAxisPoint(Axis axis, NSPoint point, Quaternion rotation);
     Vector3D positionFromPlaneAxis(PlaneAxis plane, NSPoint point);
+    Vector3D addVertexPositionFromPoint(NSPoint point);
     Vector3D translationFromPoint(NSPoint point);
     Vector3D scaleFromPoint(NSPoint point, Vector3D &lastPosition);
     Quaternion rotationFromPoint(NSPoint point, Vector3D &lastPosition);