Comments (6)
@rickomax the is a bit overly complicated I think..
Below is my implementation and I'm able to get correct results with Ortho matrix as input.
template <class T>
bool Project(T objx, T objy, T objz, const mathfu::Matrix<T, 4> projMatrix, const mathfu::Matrix<T, 4> modelMatrix, int* view, T* winx, T* winy, T* winz)
{
mathfu::Vector<T, 4> in = projMatrix * modelMatrix* mathfu::Vector<T, 4>(objx, objy, objz, static_cast<T>(1));
*winx = view[0] + (static_cast<T>(1) + in.x) * view[1] / static_cast<T>(2);
*winy = view[2] + (static_cast<T>(1) + in.y) * view[3] / static_cast<T>(2);
*winz = (in.z + static_cast<T>(1)) / static_cast<T>(2);
return true;
}
int main(int argc, char** argv) {
::testing::InitGoogleTest(&argc, argv);
float winX,winY, winZ;
int view[] = {0,800,0,600};
Project(100.0f, 110.0f, 0.0f, mathfu::Matrix<float, 4, 4>::Ortho(0,800,0,600,-1,1), mathfu::Matrix<float, 4>::Identity(), view, &winX, &winY, &winZ);
printf("%f %f %f\n", winX, winY, winZ);
return 0;
}
@stewartmiles do you feel this is something we should include in mathfu? If it is, I can send a PR to add this in.
from mathfu.
@billhsu you wrote the UnProjectHelper, what do you think?
from mathfu.
I've tried to implement the "gluProject" source using MathFu matrices, but something is wrong, all the resulting points using a "mathfu::mat4::Ortho" matrix as "projMatrix" parameter are getting perspective-projected when calculated with my function:
https://pastebin.com/GRdBGm4E
Maybe the projection code is not suitable for MathFu, or I'm not creating the "ortho" matrix with right parameters.
from mathfu.
Thank you @billhsu and @stewartmiles !
I just discovered that I could not divide the input product by the z value, as this was causing the value to be "perspective divided".
Anyway, your function is well-written and I will use it.
In my opinion, would be awesome to have this function in Mathfu.
from mathfu.
We already have helper functions to create projection matrices (e.g. Perspective()
). So a projection function should simply be a question of multiplying with such a matrix, followed with perspective divide.
from mathfu.
@rickomax sounds like a fair addition to the library fits within it's goals AFAIK. @gwvo / @aardappel thoughts?
I agree with @billhsu and @aardappel that the implementation could be simplified, wanna give it a shot and send a pull request?
from mathfu.
Related Issues (20)
- Matrix vector product question.
- SIMD detection doesn't work on MSVC x64 targets HOT 5
- Google_Mathfu failed with warning C4305 when build with MSVC HOT 3
- Expose GetColumn in Matrix
- Remove "vectorial" lib external dependency? HOT 2
- Support for double vectors/matrices (with SIMD)?
- matrix_4x4_simd.h is not included by default HOT 2
- Quaternions are 32 bytes due to alignment constraints instead of 16 bytes
- Api description in GLSL Mappings for typedef Matrix< float, 4, 4 > HOT 1
- CMAKE_SOURCE_DIR vs. CMAKE_CURRENT_SOURCE_DIR usage in studio 3.4 timeframe
- Google_MathFu failed to build due to error C1083 with MSVC on windows HOT 1
- Google_Mathfu failed with warning C4100 when build with MSVC
- When SIMD build disabled, Vector<T, Dims> miss some fundamental methods HOT 1
- Perspective projection matrix (what device coordinates is it mapping to?)
- Is this page wrong? I think there should be no parentheses. HOT 2
- method HadamardProduct of Matrix can not compile
- Bug on Quaternion::LookAt()
- Compile flag Not Updated HOT 1
- When building Google_MathFu emits warning C2220 on MSVC
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 mathfu.