修改拾取点的实现. 支持正交 极轴捕捉

pull/7/head
ChenX 7 years ago
parent 2499ed05e2
commit 5c69b64461

@ -7,5 +7,16 @@
], ],
// //
"tsimporter.filesToExclude": [], "tsimporter.filesToExclude": [],
"typescript.tsdk": "node_modules\\typescript\\lib" "typescript.tsdk": "node_modules\\typescript\\lib",
//
"editor.tabSize": 4,
"editor.formatOnPaste": true,
"editor.formatOnSave": true,
"editor.minimap.enabled": true,
//
"typescript.format.placeOpenBraceOnNewLineForFunctions": true,
"typescript.format.placeOpenBraceOnNewLineForControlBlocks": true,
"typescript.referencesCodeLens.enabled": true,
"javascript.format.placeOpenBraceOnNewLineForFunctions": true,
"javascript.format.enable": true
} }

@ -0,0 +1,18 @@
import { GeUtils } from "../../src/Geometry/GeUtils";
test("GeUtils.angle", () =>
{
let pi2 = Math.PI * 0.5;
let pi4 = pi2 * 0.5;
console.log(GeUtils.fixAngle(0.05, pi2, 0.1)/*?*/ == 0);
console.log(GeUtils.fixAngle(0.08, pi2, 0.1)/*?*/ == 0);
console.log(GeUtils.fixAngle(0.09, pi2, 0.1)/*?*/ == 0);
console.log(GeUtils.fixAngle(-0.05, pi2, 0.1)/*?*/ == Math.PI * 2);
console.log(GeUtils.fixAngle(Math.PI / 2 + 0.01, pi2, 0.1)/*?*/ == Math.PI / 2);
console.log(GeUtils.fixAngle(0.3, pi2));
})

@ -1,67 +0,0 @@
import * as THREE from 'three';
import { GeUtils } from "../src/Geometry/GeUtils"
let v = new THREE.Vector3(1, 0, 0);
let v2 = new THREE.Vector3(1, 0.1, 0)
let an = v.angleTo(v2);
console.log('an: ', an);
console.log(an);
console.log(v.angleTo(v2));
console.log(Math.PI * 0.25);
console.log(v);
console.log(v2);
console.log(v.dot(v2));
function fixAngle(an)
{
let pi4 = Math.PI * 0.5;
let rem = an % pi4;
if (rem < 0.1)
{
an -= rem;
}
else
{
an += 0.2;
rem = an % pi4;
if (rem < 0.1)
{
an -= rem;
}
else
{
an -= 0.2
}
}
return an;
}
an = fixAngle(an);
console.log(an);
GeUtils.angle(v, an, 1);
console.log(v);
console.log(fixAngle(Math.PI / 2 + 0.0));
console.log(fixAngle(Math.PI / 2 + 0.05));
console.log(Math.PI % Math.PI);
console.log(fixAngle(Math.PI / 2 + 0.05) % Math.PI / 2);

@ -61,12 +61,8 @@ export class Editor
} }
removeDrag = xaop.end(this.m_MouseCtrl, this.m_MouseCtrl.onMouseMove, () => removeDrag = xaop.end(this.m_MouseCtrl, this.m_MouseCtrl.onMouseMove, () =>
{ {
let p = this.m_MouseCtrl.m_CurMousePointWCS.clone(); let p = app.m_CursorViewer.ptWcs;
if (app.m_CursorViewer.m_LastSnapPoint && app.m_CursorViewer.m_LastSnapPoint.distanceToSquared(this.m_MouseCtrl.m_CurMousePointVCS) < 100) app.m_Viewer.ScreenToWorld(p);
{
p.copy(app.m_CursorViewer.m_LastSnapPoint);
app.m_Viewer.ScreenToWorld(p);
}
if (prompt.BasePoint) if (prompt.BasePoint)
{ {
@ -110,12 +106,9 @@ export class Editor
retValue.Status = PromptStatus.OK; retValue.Status = PromptStatus.OK;
retValue.Value = this.m_MouseCtrl.m_CurMousePointWCS; retValue.Value = this.m_MouseCtrl.m_CurMousePointWCS;
if (app.m_CursorViewer.m_LastSnapPoint && app.m_CursorViewer.m_LastSnapPoint.distanceToSquared(this.m_MouseCtrl.m_CurMousePointVCS) < 100) let p = app.m_CursorViewer.ptWcs;
{ app.m_Viewer.ScreenToWorld(p);
let p = app.m_CursorViewer.m_LastSnapPoint.clone(); retValue.Value = p;
app.m_Viewer.ScreenToWorld(p);
retValue.Value = p;
}
dispose(); dispose();
} }
}); });
@ -144,52 +137,6 @@ export class Editor
{ {
let testSnap = () => let testSnap = () =>
{ {
if (basePoint)
{
function fixAngle(an)
{
let pi2 = Math.PI * 0.5;
let rem = an % pi2;
if (rem < 0.1)
{
an -= rem;
}
else
{
an += 0.2;
rem = an % pi2;
if (rem < 0.1)
{
an -= rem;
}
else
{
an -= 0.2
}
}
return an;
}
let p = this.m_MouseCtrl.m_CurMousePointWCS.clone().sub(basePoint);
let an = Math.atan2(p.y, p.x);
if (an < 0) an += Math.PI * 2;
an = fixAngle(an);
console.log('an: ', an);
if (an % (Math.PI * 0.5) < 0.01)
{
let ptC = basePoint.clone();
GeUtils.angle(ptC, an, basePoint.dot(this.m_MouseCtrl.m_CurMousePointWCS));
app.m_Viewer.WorldToScreen(ptC);
app.m_CursorViewer.SerCursorPostion(ptC);
app.m_CursorViewer.render();
return;
}
}
for (let obj of app.m_Viewer.m_Scene.children) for (let obj of app.m_Viewer.m_Scene.children)
{ {
@ -232,6 +179,36 @@ export class Editor
} }
} }
} }
if (basePoint)
{
let p = this.m_MouseCtrl.m_CurMousePointWCS.clone();
let anV = p.clone().sub(basePoint);
let an = Math.atan2(anV.y, anV.x);
if (an < 0) an += Math.PI * 2;
let newan = GeUtils.fixAngle(an, Math.PI * 0.25);
if (!GeUtils.equaln(newan, an, 0.001))
{
//dis.
let v0 = new THREE.Vector3(0, 0, 0);
GeUtils.angle(v0, newan, 1);
let dis = v0.dot(p.sub(basePoint));
console.log(dis);
let newP = basePoint.clone();
GeUtils.angle(newP, newan, dis);
app.m_Viewer.WorldToScreen(newP);
app.m_CursorViewer.SerCursorPostion(newP);
app.m_CursorViewer.render();
return;
}
}
} }
testSnap(); testSnap();
return xaop.end(this.m_MouseCtrl, this.m_MouseCtrl.onMouseMove, testSnap); return xaop.end(this.m_MouseCtrl, this.m_MouseCtrl.onMouseMove, testSnap);

@ -17,6 +17,22 @@ export namespace GeUtils
return v1.manhattanDistanceTo(v2) < 1e-8; return v1.manhattanDistanceTo(v2) < 1e-8;
} }
export function fixAngle(an: number, fixAngle: number, fuzz: number = 0.1)
{
if (an < 0)
an += Math.PI * 2;
an += fuzz;
let rem = an % fixAngle;
if (rem < fuzz * 2)
{
an -= rem;
}
else
{
an -= fuzz;
}
return an;
}
export function angle(v: THREE.Vector3, an: number, dis: number) export function angle(v: THREE.Vector3, an: number, dis: number)
{ {
v.x += Math.cos(an) * dis; v.x += Math.cos(an) * dis;

@ -45,6 +45,13 @@ export class CursorViewer
get Scene() { return this.m_Scene; } get Scene() { return this.m_Scene; }
get Camera() { return this.m_Camera.Camera; } get Camera() { return this.m_Camera.Camera; }
get ptWcs(): THREE.Vector3
{
let v = this.m_CursorObject.position.clone();
this.ViewerPointToScreenPoint(v);
return v;
}
render() render()
{ {
@ -183,6 +190,11 @@ export class CursorViewer
p.x = p.x - this.m_Width * 0.5; p.x = p.x - this.m_Width * 0.5;
p.y = this.m_Height * 0.5 - p.y; p.y = this.m_Height * 0.5 - p.y;
} }
ViewerPointToScreenPoint(p: THREE.Vector3)
{
p.x = p.x + this.m_Width * 0.5;
p.y = this.m_Height * 0.5 - p.y;
}
onSize() onSize()
{ {

Loading…
Cancel
Save