Comments (15)
No, that is not a mistake. The goal is to compute a change of coordinates where the center becomes origin and the eye lies on the z-axis. So we subtract center and not eye.
from tinyrenderer.
@ssloy , Can you explain why other implementations subtract eye instead center? Is it because you have only 1 object on scene?
from tinyrenderer.
@wavvs, can you give me a link to another implementation so I could check it?
from tinyrenderer.
@ssloy, https://github.com/g-truc/glm/blob/aa38362b2c80d099a5e3b1645f7d9b2decf5e4bd/glm/gtc/matrix_transform.inl#L754
https://www.khronos.org/registry/OpenGL-Refpages/gl2.1/xhtml/gluLookAt.xml
https://www.scratchapixel.com/lessons/mathematics-physics-for-computer-graphics/lookat-function
from tinyrenderer.
@wavvs, thank you. There is no mistake. The difference is I suppose that the object is centered at the origin and the camera is placed at the z-axis facing origin.
The links you gave me suppose the opposite:
Remember that the camera in its default position is assumed to be centred at the origin and aligned along the negative z-axis.
Check the very beginning of their code:
vec<3, T, Q> const f(normalize(center - eye));
Where I do
Vec3f z = (eye-center).normalize();
So at the end it boils down to the same thing.
from tinyrenderer.
They do vec<3, T, Q> const f(normalize(center - eye));
, but take negative forward vector Result[0][2] =-f.x;
, and you take eye - center
and take positive forward vector in right-handed system, so yes, it's the same.
So you place object at the origin of camera space coordinates, not camera itself. Do I understand right?
from tinyrenderer.
Yes, that's right.
from tinyrenderer.
@ssloy, thank you!
from tinyrenderer.
I am also seeing some unexpected camera behavior -- for example, moving the eye further away from center does not zoom the scene out.
from tinyrenderer.
I am also seeing some unexpected camera behavior -- for example, moving the eye further away from center does not zoom the scene out.
It is not a bug, it is a feature. The job of the lookat function is to place the camera at the Oz axis, nothing more (e.g. for a parallel projection).
The actual distance between the origin and the camera is set in the perspective matrix.
from tinyrenderer.
Fair enough, but would you agree that this makes your lookAt different from what is the "usual convention"?
By no means am I trying to say that it is wrong, let alone that you should change anything, I just disagree with your summary that So at the end it boils down to the same thing, which I find quite misleading :-)
In any case, thank you for your great work!
from tinyrenderer.
I am not sure what you mean when you say "the usual convention". If I am not mistaken, the standard gluLookAt() function does not set the perspective projection, you need to call gluPerspective() for that. I emulate exactly this behaviour.
However, yes, indeed, it would make sense to set the object-to-camera distance directly from lookat(), since we have this information. But it is a non-standard behaviour as far as I know :(
from tinyrenderer.
The usual convention (LookAt in GLU & glm) includes translating the scene away from the camera by length(eye - center)
.
gluPerspective
does not even have the camera distance as an argument; disregarding the clipping that we don't care about here, the only input is FOV which would be fixed most of the time. How could the camera position be taken into consideration in gluPerspective?
from tinyrenderer.
Check the code from the guys who define what OpenGL is:
https://www.khronos.org/opengl/wiki/GluLookAt_code, esp the line:
NormalizeVector(forward);
gluPerspective()
does not have the camera distance as the argument, however it does have the field of view argument that is equivalent to the distance.
from tinyrenderer.
My bad, it is not length(eye - center)
that matters, only eye (e.g. every vertex is pushed away from the camera proportionally to its distance from the eye plane).
I was still not able to figure out how to convert from a conventional (eye, center, FOV°) tuple to (eye', center', factor) that would achieve the same result in Tinyrenderer, but I was able to work around by just including glm and using its implementation of the matrix calculations :-)
from tinyrenderer.
Related Issues (20)
- Incompatible with modern C++? HOT 3
- Lighting code in lesson 2 is not working properly
- Drawing triangle compilation error HOT 2
- Why does the rendered line break when it is vertical —— lesson 1 HOT 2
- Question about transformation of normal vectors in Lesson5 HOT 2
- My picture is brighter
- Where is the function of face() HOT 1
- Typo in Lesson 5
- 我渲染得到的结果是这样的,有人能告诉我这是哪里出现问题了吗 HOT 3
- Question about zbuffer HOT 2
- How to do the shadow mapping after perspective deformations? HOT 1
- Confused about design of the articles HOT 1
- In lesson2,something wrong in function `barycentric` when i run task in Vscode and i fix it. HOT 2
- The compilation error of lambda expressions in lesson 2 HOT 1
- Holes in fill a triangle using coordinates of pixel left bottom corner HOT 1
- About the function of face() HOT 1
- LLVM linker error HOT 6
- Why not use the more universal Bresenham?
- equations for lesson two are invisible due to githubs default dark theme HOT 1
- slower result when using omp HOT 7
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 tinyrenderer.