three#Vector2 TypeScript Examples
The following examples show how to use
three#Vector2.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DisplayObject.ts From FairyGUI-threejs with MIT License | 6 votes |
public globalToLocal(x: number, y: number, result?: Vector2): Vector2 {
if (!Stage.disableMatrixValidation)
this.validateMatrix();
screenToWorld(this._getRenderCamera(), x, y, s_v3, s_dir);
this.worldToLocal(s_v3, s_dir);
if (!result)
result = new Vector2();
result.set(s_v3.x, s_v3.y);
return result;
}
Example #2
Source File: UnitsUtils.ts From geo-three with MIT License | 6 votes |
/**
* Converts given lat/lon in WGS84 Datum to XY in Spherical Mercator EPSG:900913.
*
* @param latitude - Latitude value in degrees.
* @param longitude - Longitude value in degrees.
*/
public static datumsToSpherical(latitude: number, longitude: number): Vector2
{
const x = longitude * UnitsUtils.EARTH_ORIGIN / 180.0;
let y = Math.log(Math.tan((90 + latitude) * Math.PI / 360.0)) / (Math.PI / 180.0);
y = y * UnitsUtils.EARTH_ORIGIN / 180.0;
return new Vector2(x, y);
}
Example #3
Source File: useRaycaster.ts From trois with MIT License | 6 votes |
export default function useRaycaster(options: RaycasterConfigInterface): RaycasterInterface {
const {
camera,
resetPosition = new Vector3(0, 0, 0),
} = options
const raycaster = new Raycaster()
const position = resetPosition.clone()
const plane = new Plane(new Vector3(0, 0, 1), 0)
const updatePosition = (coords: Vector2) => {
raycaster.setFromCamera(coords, camera)
camera.getWorldDirection(plane.normal)
raycaster.ray.intersectPlane(plane, position)
}
const intersect = (coords: Vector2, objects: Object3D[], recursive = false) => {
raycaster.setFromCamera(coords, camera)
return raycaster.intersectObjects(objects, recursive)
}
return {
position,
updatePosition,
intersect,
}
}
Example #4
Source File: DOMParticles.tsx From react-ecs with MIT License | 5 votes |
location?= new Vector2(0, 0)
Example #5
Source File: DisplayObject.ts From FairyGUI-threejs with MIT License | 5 votes |
protected hitTest(context: HitTestContext): DisplayObject {
if (this._obj3D.scale.x == 0 || this._obj3D.scale.y == 0)
return null;
let backupRay: any;
if (this.camera) {
backupRay = context.ray;
context.camera = this.camera;
}
let target: DisplayObject;
let pt: Vector2 = context.getLocal(this);
let lx: number = pt.x;
let ly: number = pt.y;
if (this.hitArea) {
if (!this.hitArea.hitTest(this._contentRect, lx, ly))
return null;
}
else {
if (this._clipRect && !this._clipRect.contains(lx, ly))
return null;
}
if (this.mask) {
let tmp: DisplayObject = this.mask.visible ? this.mask.hitTest(context) : null;
if (!this.reversedMask && !tmp || this.reversedMask && tmp)
return null;
}
target = traverseHitTest(this._obj3D, context, this.mask);
if (!target && this.opaque && (this.hitArea || this._contentRect.contains(lx, ly)))
target = this;
if (backupRay)
context.ray = backupRay;
return target;
}