[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

I have never been able to find an explanation of transformation

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 10
Thread images: 2

File: Capture.png (8KB, 599x217px) Image search: [Google]
Capture.png
8KB, 599x217px
I have never been able to find an explanation of transformation matrices in 3D graphics that doesn't use specialised libraries and doesn't use coding practices of questionable efficiency.

So I tried making my own, but it makes no sense, yet it almost works.
Anyone on /g/ thinks it's redeemable?

Every frame:
>create camera matrix, starting with a translation matrix
>multiply by z rotation matrix, then x, then y
>translate by (0, 0, -1) (so that when the camera rotates, it doesn't rotate around a point in front of the camera)
>multiply by projection matrix, which is as shown

Every frame, per object:
>create object matrix, starting with a scale matrix
>multiply by x rotation matrix, then y, then z
>multiply by translation matrix
>multiply with camera matrix to get the transformation matrix

In vertex shader:
>create vec4 "position" by multiplying the transformation matrix with the vertex position (since it's a vec3, 1.0 is tacked on the end)
>define gl_Position in either of the following ways
>gl_Position = vec4(position.xy/position.w, position.z, 1.0) (causes layering issues and vertices behave weirdly as they go offscreen)
>gl_Position = position (cutoffs are no longer the near and far defined by the camera)
>>
Have you tried, oh I don't know, read the text?
>>
>>58849134
what de fuck
>>
Matrix operations really just can be implemented by individual elements one at a time.

mat4& mat4::operator*=(mat4 r) {
vec4 res[4];
vec4 rhs[4] = {r.a, r.b, r.c, r.d};
vec4 lhsRows[4] = {
vec4(a.x, b.x, c.x, d.x),
vec4(a.y, b.y, c.y, d.y),
vec4(a.z, b.z, c.z, d.z),
vec4(a.w, b.w, c.w, d.w)
};

for (int i=0; i<4; i++) {
res[i].x = vdot(lhsRows[0], rhs[i]);
res[i].y = vdot(lhsRows[1], rhs[i]);
res[i].z = vdot(lhsRows[2], rhs[i]);
res[i].w = vdot(lhsRows[3], rhs[i]);
}

a=res[0];
b=res[1];
c=res[2];
d=res[3];

return *this;
}
>>
>>58849120
It'll make more sense if you learn linear algebra.
>>
>>58849120

> so you want to MAKE GAYMES, the thread

first of all you should just use a library to handle matrices and vectors. It's such a common thing that it isn't worth making your own. I suggest GLM.

Most CPUs have built in instructions to help with operations on matrices. It's called SIMD. You are probably losing that advantage by not using a library.

So I would just rework your project to work with GLM. This will make it a lot more easy to manage mentally but you aren't really copping out by just using someone elses library
>>
>>58850975
this
>>
>>58849120
You're doing it wrong. You need a world-view-projection matrix passed to the shader as uniform. Then you multiply the vertices by the matrix in the vertex shader, gpu does this a million times faster. You just need to keep the matrices with your objects, but don't multiply them manually.
>>
shorter variable names does not mean faster code
give your variables proper names and use camelCase
>>
>>58849120

I honestly don't remember specifics but I've been there and figured it out.

pic related

>create vec4 "position" by multiplying the transformation matrix with the vertex position (since it's a vec3, 1.0 is tacked on the end)

lets just start from the basics:

gl_Position = proj * view * model * vec4(position, 1.0);


is all you need in the vertex shader. IIRC a transformation matrix is an object's specific translation, rotation and scale all combined into one thing. I think that's just another word for model matrix (as I use in this code). Make sure the order is correct because that matters.

If your vertex shader looks like this the only uniform you need to change is the model when you are drawing the buffer containing your object's vertices. You are meant to use this in combination with a vertex array object that stores some other data about the configuration each physical 3d object has.
Thread posts: 10
Thread images: 2


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties.
Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.