private void LateUpdate() { if (!clickVisualFeedTarget || (!_targetDirty && !_mouseDown)) { return; } if ((Time.time - _mouseDownTime) > maxHoldForClick || ((Input.mousePosition.ToVector2() - _mouseDownPosition).magnitude > maxMousePositionPixOffsetForClick)) { _mouseDown = false; } if (transition == ClickableElementTransition.Fade) { var a = clickVisualFeedTarget.color.a; var target = _mouseDown ? 0.75f : 1; a = QcMath.LerpBySpeed(a, target, 5); clickVisualFeedTarget.TrySetAlpha(a); _targetDirty = (Math.Abs(a - 1) > float.Epsilon); } }
public Vector3 GetSharpNormal() { sharpNormal = QcMath.GetNormalOfTheTriangle( vertexes[0].LocalPos, vertexes[1].LocalPos, vertexes[2].LocalPos); return(sharpNormal); }
public void UpdateSpeed(ref float speed) { if (speed < startSpeed) { QcMath.IsLerpingBySpeed(ref speed, startSpeed, startSpeed * 0.3f); } else { speed += accelerationPerSecond * Time.deltaTime; } }
public Vector3 GetNormalByArea(float accuracyFix = 1) { var p0 = vertexes[0].LocalPos * accuracyFix; var p1 = vertexes[1].LocalPos * accuracyFix; var p2 = vertexes[2].LocalPos * accuracyFix; sharpNormal = QcMath.GetNormalOfTheTriangle( p0, p1, p2); return(sharpNormal * Vector3.Cross(p0 - p1, p0 - p2).magnitude); }
public static void SHADER_POSITION_AND_PREVIEW_UPDATE(StrokeVector st, bool hidePreview, float size) { PainterDataAndConfig.BRUSH_POINTED_UV.GlobalValue = st.uvTo.ToVector4(0, _previewAlpha); if (hidePreview && Math.Abs(_previewAlpha) < float.Epsilon) { return; } QcMath.IsLerpingBySpeed(ref _previewAlpha, hidePreview ? 0 : 1, 4f); PainterDataAndConfig.BRUSH_WORLD_POS_FROM.GlobalValue = _prevPosPreview.ToVector4(size); PainterDataAndConfig.BRUSH_WORLD_POS_TO.GlobalValue = st.posTo.ToVector4((st.posTo - _prevPosPreview).magnitude); //new Vector4(st.posTo.x, st.posTo.y, st.posTo.z, (st.posTo - prevPosPreview).magnitude)); _prevPosPreview = st.posTo; }
private bool ProcessLinesOnTriangle(PainterMesh.Triangle t) { t.wasProcessed = true; const float precision = 0.05f; var acc = (targetTransform.InverseTransformPoint(CurrentViewTransform().position) - collisionPosLocal).magnitude; acc *= precision; var v0 = t.vertexes[0]; var v1 = t.vertexes[1]; var v2 = t.vertexes[2]; var v0p = v0.meshPoint.distanceToPointed; var v1p = v1.meshPoint.distanceToPointed; var v2p = v2.meshPoint.distanceToPointed; if (QcMath.IsPointOnLine(v0p, v1p, Vector3.Distance(v0.LocalPos, v1.LocalPos), acc)) { ProcessPointOnALine(v0, v1, t); return(true); } if (QcMath.IsPointOnLine(v1p, v2p, Vector3.Distance(v1.LocalPos, v2.LocalPos), acc)) { ProcessPointOnALine(v1, v2, t); return(true); } if (QcMath.IsPointOnLine(v2p, v0p, Vector3.Distance(v2.LocalPos, v0.LocalPos), acc)) { ProcessPointOnALine(v2, v0, t); return(true); } return(false); }
public void UpdatePositions() { var m = MeshMGMT; var cfg = TexMgmtData; if (!cfg) { return; } var showGrid = MeshEditorManager.target.NeedsGrid() || TexMGMT.FocusedPainter.NeedsGrid(); SetEnabled(showGrid, cfg.snapToGrid && showGrid); if (!showGrid) { return; } if (cfg.gridSize <= 0) { cfg.gridSize = 1; } switch (gSide) { case Gridside.xy: rendy.transform.rotation = ZGrid; break; case Gridside.xz: rendy.transform.rotation = YGrid; break; case Gridside.zy: rendy.transform.rotation = XGrid; break; } _xzPlane.distance = -onGridPos.y; _xyPlane.distance = -onGridPos.z; _zyPlane.distance = -onGridPos.x; var hit = Vector3.zero; switch (gSide) { case Gridside.xy: hit = MouseToPlane(_xyPlane); break; case Gridside.xz: hit = MouseToPlane(_xzPlane); break; case Gridside.zy: hit = MouseToPlane(_zyPlane); break; } if (cfg.snapToGrid) { hit = QcMath.RoundDiv(hit, cfg.gridSize); } if (hit != Vector3.zero) { switch (gSide) { case Gridside.xy: onGridPos.x = hit.x; onGridPos.y = hit.y; break; case Gridside.xz: onGridPos.x = hit.x; onGridPos.z = hit.z; break; case Gridside.zy: onGridPos.z = hit.z; onGridPos.y = hit.y; break; } } var tf = transform; var dotTf = dot.transform; var rndTf = rendy.transform; tf.position = onGridPos + Vector3.one * 0.01f; var position = tf.position; _dotPositionProperty.GlobalValue = new Vector4(onGridPos.x, onGridPos.y, onGridPos.z); dotTf.rotation = CurrentViewTransform().rotation; var cam = CurrentViewTransform(); var dist = Mathf.Max(0.1f, (cam.position - position).magnitude * 2); dotTf.localScale = Vector3.one * (dist / 64f); rndTf.localScale = new Vector3(dist, dist, dist); float scale = !cfg.snapToGrid ? Mathf.Max(1, Mathf.ClosestPowerOfTwo((int)(dist / 8))) : cfg.gridSize; var dx = gSide != Gridside.zy ? position.x : -position.z; var dy = gSide != Gridside.xz ? position.y : position.z; dx -= Mathf.Round(dx / scale) * scale; dy -= Mathf.Round(dy / scale) * scale; var mat = rendy.sharedMaterial; mat.Set(_dxProp, dx / dist) .Set(_dyProp, dy / dist) .Set(_sizeProp, dist / scale); if (MeshEditorManager.target) { MeshMGMT.UpdateLocalSpaceMousePosition(); } }
public bool LerpBySpeed(float targetValue, float speed) => QcMath.IsLerpingBySpeed(ref colorAlpha, targetValue, speed);