Git Product home page Git Product logo

Comments (4)

Fox32 avatar Fox32 commented on May 2, 2024

Why should one try to extend the vector classes? I would try to avoid that.

from vector_math.dart.

brason avatar brason commented on May 2, 2024

Well, again I'm thinking with three.dart in mind. Wouldn't something like this work?

library custom_vector;

import 'package:vector_math:vector_math.dart' as vm;

class Vector3 extends vm.Vector3 {
  Vector3 project(Camera camera) {
    var matrixWorldInverse = new Matrix4.identity()..copyInverse(camera.matrixWorld);
    applyProjection(camera.projectionMatrix * matrixWorldInverse);
    return this;
  }

  Vector3 unproject(Camera camera) {
    var projectionMatrixInverse = new Matrix4.identity()..copyInverse(camera.projectionMatrix);
    applyProjection(camera.matrixWorld * projectionMatrixInverse);
    return this;
  }
}

or

library custom_quaternion;

import 'package:vector_math:vector_math.dart' as vm;

class Quaternion extends vm.Quaternion {
  Euler _euler;

  void _updateEuler() {
    if (_euler != null) {
      _euler.setFromQuaternion(this, update: false);
    }
  }

  Quaternion setFromEuler(Euler euler, {bool update: true}) {
    final c1 = Math.cos(euler._x / 2);
    final c2 = Math.cos(euler._y / 2);
    final c3 = Math.cos(euler._z / 2);
    final s1 = Math.sin(euler._x / 2);
    final s2 = Math.sin(euler._y / 2);
    final s3 = Math.sin(euler._z / 2);

    if (euler.order == 'XYZ') {
      storage[0] = s1 * c2 * c3 + c1 * s2 * s3;
      storage[1] = c1 * s2 * c3 - s1 * c2 * s3;
      storage[2] = c1 * c2 * s3 + s1 * s2 * c3;
      storage[3] = c1 * c2 * c3 - s1 * s2 * s3;
    } else if (euler.order == 'YXZ') {
      storage[0] = s1 * c2 * c3 + c1 * s2 * s3;
      storage[1] = c1 * s2 * c3 - s1 * c2 * s3;
      storage[2] = c1 * c2 * s3 - s1 * s2 * c3;
      storage[3] = c1 * c2 * c3 + s1 * s2 * s3;
    } else if (euler.order == 'ZXY') {
      storage[0] = s1 * c2 * c3 - c1 * s2 * s3;
      storage[1] = c1 * s2 * c3 + s1 * c2 * s3;
      storage[2] = c1 * c2 * s3 + s1 * s2 * c3;
      storage[3] = c1 * c2 * c3 - s1 * s2 * s3;
    } else if (euler.order == 'ZYX') {
      storage[0] = s1 * c2 * c3 - c1 * s2 * s3;
      storage[1] = c1 * s2 * c3 + s1 * c2 * s3;
      storage[2] = c1 * c2 * s3 - s1 * s2 * c3;
      storage[3] = c1 * c2 * c3 + s1 * s2 * s3;
    } else if (euler.order == 'YZX') {
      storage[0] = s1 * c2 * c3 + c1 * s2 * s3;
      storage[1] = c1 * s2 * c3 + s1 * c2 * s3;
      storage[2] = c1 * c2 * s3 - s1 * s2 * c3;
      storage[3] = c1 * c2 * c3 - s1 * s2 * s3;
    } else if (euler.order == 'XZY') {
      storage[0] = s1 * c2 * c3 - c1 * s2 * s3;
      storage[1] = c1 * s2 * c3 - s1 * c2 * s3;
      storage[2] = c1 * c2 * s3 + s1 * s2 * c3;
      storage[3] = c1 * c2 * c3 + s1 * s2 * s3;
    }

    if (update) _updateEuler();


    return this;
  }
}

from vector_math.dart.

Fox32 avatar Fox32 commented on May 2, 2024

Methods like project can also be top level methods. Instead of using inheritance one can also use composition. Would changing the default constructor to a non factory be sufficient?

from vector_math.dart.

brason avatar brason commented on May 2, 2024

Hm, actually you don't need to change a thing. The only class that I can't extend is Quaternion, but that class isn't too big so I can implement it and use delegation instead. Sorry for bothering you :)

from vector_math.dart.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.