当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript vec3.create方法代码示例

本文整理汇总了TypeScript中gl-matrix.vec3.create方法的典型用法代码示例。如果您正苦于以下问题:TypeScript vec3.create方法的具体用法?TypeScript vec3.create怎么用?TypeScript vec3.create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在gl-matrix.vec3的用法示例。


在下文中一共展示了vec3.create方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: moveAlong

    moveAlong(elapsedTime: number, speed: number): Vec3 {
        // If there is no further waypoint, we've arrived at the end and we
        // always return the current position.
        if (this.done) {
            return vec3.clone(this.currentPosition);
        }

        // The vector from the current position to the next waypoint.
        var vector        = vec3.subtract(vec3.create(), this.waypoints[0], this.currentPosition)
          , vectorLength  = vec3.length(vector)
          , distanceMoved = speed * elapsedTime;

        if (vectorLength < distanceMoved) {
            // The remaining distance in the current segment is less than what
            // we moved, jump to the next waypoint and move along the next path
            // segment from there.

            vec3.copy(this.currentPosition, this.waypoints.shift());
            this.currentHeading = normalizeHeading(Math.atan2(vector[1], vector[0]));

            return this.moveAlong(elapsedTime - vectorLength / speed, speed);
        }

        // We have not yet reached the next waypoint. Move along the vector
        // towards it and update the heading.
        vec3.add(this.currentPosition, this.currentPosition, vec3.scale(vec3.create(), vec3.normalize(vec3.create(), vector), distanceMoved));
        this.currentHeading = normalizeHeading(Math.atan2(vector[1], vector[0]));

        return vec3.clone(this.currentPosition);
    }
开发者ID:rmx,项目名称:encounter,代码行数:30,代码来源:MovePath.ts

示例2: lookAt

export function lookAt(eye: vec3, target: vec3, up: vec3) {
  const quatOut = quat.create();
  const x = vec3.create();
  const y = vec3.create();
  const z = vec3.create();

  vec3.sub(z, eye, target);

  if (vec3.squaredLength(z) === 0) {
    // eye and target are in the same position
    z[2] = 1;
  }

  vec3.normalize(z, z);
  vec3.cross(x, up, z);

  if (vec3.squaredLength(x) === 0) {
    // eye and target are in the same vertical
    z[2] += 0.0001;
    vec3.cross(x, up, z);
  }

  vec3.normalize(x, x);
  vec3.cross(y, z, x);

  quat.setAxes(quatOut, z, x, y);
  quat.invert(quatOut, quatOut);

  return quatOut;
}
开发者ID:davidpaulrosser,项目名称:leonardo,代码行数:30,代码来源:Utils.ts

示例3: barycoordFromPoint

export function barycoordFromPoint(point: vec3, a: vec3, b: vec3, c: vec3) {
  const v0 = vec3.create();
  const v1 = vec3.create();
  const v2 = vec3.create();

  vec3.sub(v0, c, a);
  vec3.sub(v1, b, a);
  vec3.sub(v2, point, a);

  const dot00 = vec3.dot(v0, v0);
  const dot01 = vec3.dot(v0, v1);
  const dot02 = vec3.dot(v0, v2);
  const dot11 = vec3.dot(v1, v1);
  const dot12 = vec3.dot(v1, v2);

  const denom = dot00 * dot11 - dot01 * dot01;

  const result = new Vector3();

  // collinear or singular triangle
  if (denom === 0) {
    // arbitrary location outside of triangle?
    // not sure if this is the best idea, maybe should be returning undefined
    return result.set(-2, -1, -1);
  }

  const invDenom = 1 / denom;
  const u = (dot11 * dot02 - dot01 * dot12) * invDenom;
  const v = (dot00 * dot12 - dot01 * dot02) * invDenom;

  // barycentric coordinates must always sum to 1
  return result.set(1 - u - v, v, u);
}
开发者ID:davidpaulrosser,项目名称:leonardo,代码行数:33,代码来源:Utils.ts

示例4: angleAxis

 /**
 * Calculate the rotation quaternion represented as pair of angle and axis.
 */
 public static angleAxis(angle: number, axis: Vector3): Quaternion {
   const axisVec = vec3.create();
   axisVec[0] = axis.X;
   axisVec[1] = axis.Y;
   axisVec[2] = axis.Z;
   const newQuat = quat.create();
   return new Quaternion(quat.setAxisAngle(newQuat, axisVec, +angle));
 }
开发者ID:kyasbal-1994,项目名称:jThree,代码行数:11,代码来源:Quaternion.ts

示例5: constructor

 constructor(
   readonly type: BoneType,
   readonly basis: Triple<vec3>,
   readonly prevJoint: vec3,
   readonly nextJoint: vec3,
   readonly width: number
 ) {
   const difference = vec3.subtract(vec3.create(), this.nextJoint, this.prevJoint);
   this.length = vec3.length(difference);
   this.basisMatrix = mat3.fromValues(
     this.basis[0][0], this.basis[0][1], this.basis[0][2],
     this.basis[1][0], this.basis[1][1], this.basis[1][2],
     this.basis[2][0], this.basis[2][1], this.basis[2][2]
   );
   this.left = mat3.determinant(this.basisMatrix) < 0;
   this.center = vec3.lerp(vec3.create(), this.prevJoint, this.nextJoint, 0.5);
   this.direction = Bone.createBoneDirection(this.basisMatrix);
   this.matrix = Bone.createBoneMatrix(this.basisMatrix, this.center, this.left);
 }
开发者ID:alexeden,项目名称:dotstar-node,代码行数:19,代码来源:bone.ts

示例6: constructor

 constructor() {
   this.children = [];
   this.localMatrix = mat4.create();
   this.modelMatrix = mat4.create();
   this.modelViewMatrix = mat4.create();
   this.matrixAutoUpdate = true;
   this.position = new Vector3();
   this.rotation = new Vector3();
   this.scale = new Vector3(1, 1, 1);
   this.isObject3D = true;
   this.quaternion = quat.create();
   this.quaternionLookAt = quat.create();
   this.lookAtUp = vec3.create(); // needs to be [0, 0, 0] although it should be [0, 1, 0]
 }
开发者ID:davidpaulrosser,项目名称:leonardo,代码行数:14,代码来源:Object3D.ts

示例7: needRecomputeMovePath

    private needRecomputeMovePath(): boolean {
        var terrain  = lookupEntity<Terrain>(this.state, this.target.terrainId)
          , tpos     = getWorldCoordinates(terrain, this.target.terrainPosition)
          , fpos     = finalPosition(this.owner)
          , distance = Math.abs(vec3.length(vec3.subtract(vec3.create(), tpos, fpos)))
          , diff     = distance - (this.distance + this.target.boundingRadius);

        return 0.1 < diff;

        function finalPosition(entity: WorldObject): Vec3 {
            if (entity.movePath) {
                return entity.movePath.finalPosition;
            } else {
                return getWorldCoordinates(terrain, entity.terrainPosition);
            }
        }
    }
开发者ID:rmx,项目名称:encounter,代码行数:17,代码来源:follow.ts

示例8:

let vec3B = vec3.fromValues(3, 4, 5);
let vec4A = vec4.fromValues(1, 2, 3, 4);
let vec4B = vec4.fromValues(3, 4, 5, 6);
let mat2A = mat2.fromValues(1, 2, 3, 4);
let mat2B = mat2.fromValues(1, 2, 3, 4);
let mat2dA = mat2d.fromValues(1, 2, 3, 4, 5, 6);
let mat2dB = mat2d.fromValues(1, 2, 3, 4, 5, 6);
let mat3A = mat3.fromValues(1, 2, 3, 4, 5, 6, 7, 8, 9);
let mat3B = mat3.fromValues(1, 2, 3, 4, 5, 6, 7, 8, 9);
let mat4A = mat4.fromValues(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16);
let mat4B = mat4.fromValues(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16);
let quatA = quat.fromValues(1, 2, 3, 4);
let quatB = quat.fromValues(5, 6, 7, 8);

let outVec2 = vec2.create();
let outVec3 = vec3.create();
let outVec4 = vec4.create();
let outMat2 = mat2.create();
let outMat2d = mat2d.create();
let outMat3 = mat3.create();
let outMat4 = mat4.create();
let outQuat = quat.create();

let outMat2Null: mat2 | null;
let outMat2dNull: mat2d | null;
let outMat3Null: mat3 | null;
let outMat4Null: mat4 | null;

// vec2
outVec2 = vec2.create();
outVec2 = vec2.clone(vec2A);
开发者ID:DenisCarriere,项目名称:DefinitelyTyped,代码行数:31,代码来源:gl-matrix-tests.ts

示例9: diagonal

 diagonal(): Vec3 {
     return vec3.subtract(vec3.create(), this.max, this.min);
 }
开发者ID:rmx,项目名称:encounter,代码行数:3,代码来源:BoundingBox.ts

示例10: updateFaceNormal

import { vec3 } from 'gl-matrix';
import Vector3 from '../math/Vector3';
const cb = vec3.create();
const ab = vec3.create();

export default class Face {
  public indices: number[];
  public vertices: Vector3[];
  public uvs: number[];
  public normal: Vector3;

  constructor(
    indiceA: number,
    indiceB: number,
    indiceC: number,
    vertexA: Vector3,
    vertexB: Vector3,
    vertexC: Vector3
  ) {
    this.indices = [indiceA, indiceB, indiceC];
    this.vertices = [vertexA, vertexB, vertexC];
    this.uvs = [indiceA, indiceB, indiceC];
    this.normal = new Vector3();
    this.updateFaceNormal();
  }

  public updateFaceNormal() {
    // from threejs
    vec3.set(cb, 0, 0, 0);
    vec3.set(ab, 0, 0, 0);
    vec3.subtract(cb, this.vertices[2].v, this.vertices[1].v);
开发者ID:davidpaulrosser,项目名称:leonardo,代码行数:31,代码来源:Face.ts


注:本文中的gl-matrix.vec3.create方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。