commit | 8e505ae596d0ab8ed2967c59857967a317f9fc1b | [log] [tgz] |
---|---|---|
author | John McCutchan <john@johnmccutchan.com> | Tue Feb 19 08:01:23 2013 -0800 |
committer | John McCutchan <john@johnmccutchan.com> | Tue Feb 19 08:01:23 2013 -0800 |
tree | ccde9e46d17c43d6bfc68281fd8b502ac00d7c00 | |
parent | a217879a1556103c5fff049599b43997c7194a2f [diff] | |
parent | 3866bd0ec75dc706c3a4b248798e44d30f984776 [diff] |
Merge pull request #46 from fkleon/dynamic_constructors Vec3+4 constructors fail on vector/scalar combinations
==============
A Vector math library for 2D and 3D applications.
position.xwz = color.grb;
.new vec3(new vec2(x,y), z);
.1. Add the following to your project's pubspec.yaml and run pub install
.
dependencies: vector_math: git: https://github.com/johnmccutchan/DartVectorMath.git
2. Add the correct import for your project.
import 'package:vector_math/vector_math.dart';
1. Using the GLSL getter and setter syntax.
void main() { vec3 x = new vec3(); // Zero vector vec4 y = new vec4(4.0); // Vector with 4.0 in all lanes x.zyx = y.xzz; // Sets z,y,x the values in x,z,z }
2. Transforming a vector.
void main() { // Rotation of pi/2 degrees around the Y axis followed by a // translation of (5.0, 2.0, 3.0). mat4 T = new mat4.rotationY(pi*0.5).translate(5.0, 2.0, 3.0); // A point. vec3 position = new vec3.raw(1.0, 1.0, 1.0); // Transform position by T. T.transform3(position); }
3. Invert a matrix
void main() { // Rotation of 90 degrees around the Y axis followed by a // translation of (5.0, 2.0, 3.0). mat4 T = new mat4.rotationY(pi*0.5).translate(5.0, 2.0, 3.0); // Invert T. T.invert(); // Invert just the rotation in T. T.invertRotation(); }
4. Rotate a vector using a quaternion
void main() { // The X axis. vec3 axis = new vec3.raw(1.0, 0.0, 0.0); // 90 degrees. double angle = pi/2.0; // Quaternion encoding a 90 degree rotation along the X axis. quat q = new quat.axisAngle(axis, angle); // A point. vec3 point = new vec3.raw(1.0, 1.0, 1.0); // Rotate point by q. q.rotate(point); }