Comments (4)
Why should one try to extend the vector classes? I would try to avoid that.
from vector_math.dart.
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.
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.
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)
- Overflowed issue HOT 1
- Decomposing a Matrix4 does not result in the same scale as its composition. HOT 1
- Need help HOT 1
- Does Flutter expose SkMatrix::setPolyToPoly like Android does?
- Does Flutter expose SkMatrix::setPolyToPoly like Android does? HOT 1
- Reflections implemented incorrectly HOT 1
- The form of rotation animation has changed HOT 1
- Matrix4.leftMultiply HOT 1
- Polygon HOT 4
- setPerspectiveMatrix seems to be missing near term numerators HOT 1
- Aab3 intersects with plane fails HOT 1
- Matrix3.rotationY provides incorrect matrix HOT 2
- Remove bundled dependencies HOT 10
- Deprecate and remove the `SimplexNoise` classes HOT 8
- Quaternion unary - takes the conjugate instead of memberwise negation HOT 2
- Impossible to implement/extend Vector2 HOT 13
- Does Vector2 perform SIMD instructions on computation? HOT 2
- Consider sealing vector_math classes HOT 1
- Why do frustum normals point outside? HOT 1
- Extension Types HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from vector_math.dart.