public virtual bool UpdateDraw_Ray_MultiClick(Frame3f frameW) { bool first = (preview.VertexCount == 0); Vector3f vPos = Scene.ToSceneP(frameW.Origin); // the last vertex is the one we are repositioning in UpdateDrawPreview. So, on // click we actaully want to freeze that vertex to this position and then add a new // temporary one. Except for the first vertex. if (first) { preview.AppendVertex(vPos); preview.AppendVertex(vPos); OnAddedClickPoint(vPos, true); } else { // close curve if we are within close threshold //if ( preview.VertexCount > 2 && vPos.Distance((Vector3f)preview[0]) < CloseThresholdScene ) // return false; //preview[preview.VertexCount - 1] = vPos; preview.AppendVertex(vPos); OnAddedClickPoint(vPos, false); } return(true); }
public virtual bool UpdateDraw_Ray_MultiClick(Ray3f ray) { bool first = (preview.VertexCount == 0); SORayHit hit; bool bHit = target.FindRayIntersection(ray, out hit); if (bHit) { float offset = Scene.ToWorldDimension(SurfaceOffsetScene); Vector3f vHit = hit.hitPos + offset * hit.hitNormal; Vector3f vPos = Scene.ToSceneP(vHit); // the last vertex is the one we are repositioning in UpdateDrawPreview. So, on // click we actaully want to freeze that vertex to this position and then add a new // temporary one. Except for the first vertex. if (first) { preview.AppendVertex(vPos); preview.AppendVertex(vPos); OnAddedClickPoint(vPos, true); } else { // close curve if we are within close threshold if (preview.VertexCount > 2 && vPos.Distance((Vector3f)preview[0]) < CloseThresholdScene) { return(false); } //preview[preview.VertexCount - 1] = vPos; preview.AppendVertex(vPos); OnAddedClickPoint(vPos, false); } } return(true); }
public void smooth_append(CurvePreview preview, Vector3f newPos, float fDistThresh) { // empty curve, always append if (preview.VertexCount == 0) { preview.AppendVertex(newPos); last_append_idx = preview.VertexCount - 1; appended_last_update = true; have_temp_append = false; return; } double d = (newPos - preview[last_append_idx]).Length; if (d < fDistThresh) { // have not gone far enough for a real new vertex! Vector3f usePos = new Vector3f(newPos); bool bValid = false; // do we have enough vertices to do a good job? if (preview.VertexCount > 3) { int nLast = (have_temp_append) ? preview.VertexCount - 2 : preview.VertexCount - 1; Vector3d tan = preview.Tangent(nLast); double fDot = tan.Dot((usePos - preview[nLast]).Normalized); if (fDot > 0.9f) // cos(25) ~= 0.9f // new vtx is aligned with tangent of last "real" vertex { bValid = true; } else { // not aligned, try projection onto tangent Line3d l = new Line3d(preview[nLast], tan); double t = l.Project(newPos); if (t > 0) { // projection of new vtx is 'ahead' so we can use it usePos = (Vector3f)l.PointAt(t); bValid = true; } } } if (bValid) { if (appended_last_update) { preview.AppendVertex(usePos); have_temp_append = true; } else if (have_temp_append) { preview[preview.VertexCount - 1] = usePos; } } appended_last_update = false; } else { // ok we drew far enough, add this position if (have_temp_append) { // re-use temp vertex preview[preview.VertexCount - 1] = newPos; have_temp_append = false; } else { preview.AppendVertex(newPos); } last_append_idx = preview.VertexCount - 1; appended_last_update = true; // do smoothing pass // [TODO] cannot do this until we can reproject onto surface!! //smoother.End = curve.VertexCount - 1; //smoother.Start = MathUtil.Clamp(smoother.End - 5, 0, smoother.End); //smoother.UpdateDeformation(2); } }