Comments (3)
Thanks for your continuing bug reports and improvments! I will look into this as soon as possible, but on the first glance, this looks solid.
from gl3n.
I still don't have much, time, I checked if it compiles and just put it in. Thanks for the code, if it doesn't work, please reopen it.
from gl3n.
I can't seem to reopen the issue, I hope it's alright that I just post a comment.
The posted function seems to have problems as well, I'm so sorry for inconveniencing you with more broken code :(
I've been working with the following:
/// Creates a quaternion from a 3x3 matrix.
/// Params:
/// matrix = 3x3 matrix (rotation)
/// Returns: A quaternion representing the rotation (3x3 matrix)
static Quaternion from_matrix(Matrix!(qt, 3, 3) matrix) {
Quaternion ret;
auto mat = matrix.matrix;
qt trace = mat[0][0] + mat[1][1] + mat[2][2];
if(trace > 0) {
qt s = 0.5 / sqrt(trace + 1.0f);
ret.w = to!qt(0.25 / s);
ret.x = to!qt((mat[2][1] - mat[1][2]) * s);
ret.y = to!qt((mat[0][2] - mat[2][0]) * s);
ret.z = to!qt((mat[1][0] - mat[0][1]) * s);
} else if((mat[0][0] > mat[1][1]) && (mat[0][0] > mat[2][2])) {
qt s = 2.0 * sqrt(1.0 + mat[0][0] - mat[1][1] - mat[2][2]);
ret.w = to!qt((mat[2][1] - mat[1][2]) / s);
ret.x = to!qt(0.25f * s);
ret.y = to!qt((mat[0][1] + mat[1][0]) / s);
ret.z = to!qt((mat[0][2] + mat[2][0]) / s);
} else if(mat[1][1] > mat[2][2]) {
qt s = 2.0 * sqrt(1 + mat[1][1] - mat[0][0] - mat[2][2]);
ret.w = to!qt((mat[0][2] - mat[2][0]) / s);
ret.x = to!qt((mat[0][1] + mat[1][0]) / s);
ret.y = to!qt(0.25f * s);
ret.z = to!qt((mat[1][2] + mat[2][1]) / s);
} else {
qt s = 2.0 * sqrt(1 + mat[2][2] - mat[0][0] - mat[1][1]);
ret.w = to!qt((mat[1][0] - mat[0][1]) / s);
ret.x = to!qt((mat[0][2] + mat[2][0]) / s);
ret.y = to!qt((mat[1][2] + mat[2][1]) / s);
ret.z = to!qt(0.25f * s);
}
return ret;
}
without any trouble for a while now.
I'm fairly certain that it works since the output of loads of tests have magnitude 1.
Reference:
http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToQuaternion/index.htm
from gl3n.
Related Issues (20)
- travis does not run unittests HOT 1
- Broke in dmd 2.068.0 HOT 5
- column major layout for matrices ? HOT 1
- Transposed matrixes not supported on every system HOT 2
- TypeTuple not found HOT 1
- 'TypeTuple' not found and other stuff HOT 1
- Matrix decomposition HOT 1
- Compiling example code HOT 3
- core.simd and gl3n HOT 14
- Project Status HOT 2
- AABBT!int doesn't work HOT 1
- No documentation on Matrix.perspective HOT 1
- Matrix Translate resulting in different values from glm HOT 2
- Vector can not be used as AA-key
- Casting between Vector's with different types but the same length does not work HOT 3
- N-dimension AABB HOT 1
- When vecN is used with tuples, 'dub test' fails.
- Deprecation warnings HOT 1
- [proposal] adding a member function to_axisAngle() in struct Quat HOT 1
- Quaternion inverse is not the same as conjugate
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 gl3n.