Git Product home page Git Product logo

Comments (6)

billhsu avatar billhsu commented on July 28, 2024 1

@rickomax the implementation 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.

stewartmiles avatar stewartmiles commented on July 28, 2024

@billhsu you wrote the UnProjectHelper, what do you think?

from mathfu.

rickomax avatar rickomax commented on July 28, 2024

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.

rickomax avatar rickomax commented on July 28, 2024

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.

aardappel avatar aardappel commented on July 28, 2024

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.

stewartmiles avatar stewartmiles commented on July 28, 2024

@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)

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.