Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Camera and matrix transforms don't seem to mix intuitively #26

Open
dhiahassen opened this issue Oct 12, 2016 · 4 comments · May be fixed by #206
Open

Camera and matrix transforms don't seem to mix intuitively #26

dhiahassen opened this issue Oct 12, 2016 · 4 comments · May be fixed by #206

Comments

@dhiahassen
Copy link

dhiahassen commented Oct 12, 2016

i want to get the current projection matrix and store it to a variable so that later i can reuse it ,
i can try this :

float * matrix;
GPU_PushMatrix();
matrix = GPU_GetProjection();
...
//here i want to set the projection matrix to "matrix"

how to do that ?
i mean i looking for an equivalent to "glLoadMatrixf(matrix);"

@grimfang4
Copy link
Owner

GPU_GetProjection() returns a pointer to the current projection matrix. If SDL_gpu changes that matrix, it'll affect your pointer. If you really want to store the matrix for later, copy it into your own 16-element float array. GPU_MatrixCopy() will help. To restore it, you can copy it back onto the result of GPU_GetProjection(). GPU_MatrixCopy() is a more generic equivalent to glLoadMatrix(). You might also look at GPU_LoadIdentity() and GPU_MultMatrix().

Most of the time, however, you are temporarily changing the matrix and want to reset it back to how it was before. It might be cleaner and clearer if you use GPU_PushMatrix() to store the matrix, then GPU_PopMatrix() to restore it. It works very similarly to glPushMatrix() and glPopMatrix().

@dhiahassen
Copy link
Author

thanks , im asking because i have a problem mixing sdl_gpu camera with GPU_Translate() ill tell you in short what it is :
I am using sdl_gpu camera to navigate on the level's world and follow an object , but when i try to apply rotation on the camera , it appears that the rotaion center is not the screen's center point as expected but it is the top left cornner of the screen , one possible solution is to rotate first then translate ( as i did in allegro 5 ) , but that is impossible with sdl_gpu , because it handles the camera control at once using GPU_SetCamera() and it does it in it's one only own way .
i left the camera methods and i thought that i can use SDL_Translate() , it is working as expected with some exceptions :

  • when rotating : the shapes are scaled because the screen ratio is not 1:1
  • and something you peobably didn't know about , or didn't think of , the Blit functions are not responding to the translation as the shapes does .
    now i think i should leave the camera rotation thing all together
    , and make my game without cool effects :/ or i thing i should use shaders for the rotation , or do you thing i can fix this whole problem with sdl gpu itself ?

@grimfang4
Copy link
Owner

This sounds like something that needs to be fixed, but I don't have the time right now to dig into it. If you do look into it further, you can send a pull request or a patch and I'll take it in.

@dhiahassen
Copy link
Author

dhiahassen commented Oct 18, 2016

i think i will make some changes on sdl gpu for the engine im working on , ill back to this later when i need a camera rotation , whenever i add something or fix something ill let you know , im sure that after few months ill have to back to work on the engine's guts and basics but for the moment i don't have to loose time i prefer to move on , don't close this

@grimfang4 grimfang4 changed the title how to store and restore the current projection matrix ? Camera and matrix transforms don't seem to mix intuitively Jul 22, 2017
@albertvaka albertvaka linked a pull request Oct 4, 2020 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants