Stilllegung des Forums
Das Forum wurde am 05.06.2023 nach über 20 Jahren stillgelegt (weitere Informationen und ein kleiner Rückblick).
Registrierungen, Anmeldungen und Postings sind nicht mehr möglich. Öffentliche Inhalte sind weiterhin zugänglich.
Das Team von spieleprogrammierer.de bedankt sich bei der Community für die vielen schönen Jahre.
Wenn du eine deutschsprachige Spieleentwickler-Community suchst, schau doch mal im Discord und auf ZFX vorbei!
Werbeanzeige
Community-Fossil
Beruf: Teamleiter Mobile Applikationen & Senior Software Engineer
Eine Parallelprojektion ist eine orthographische Projektion und auch eine orthogonale. Das ist alles dasselbe. Die Projektion allein hilft Dir dabei nicht mit dem Problem der verzerrten Seitenverhältnisse, sondern nur ein Faktor, der diese Verhältnisse beinhaltet. Den hast Du scheinbar im Zuge der Projektion ordentlich mit verbaut, aber das Verständnis fehlt scheinbar noch etwas für das, was Du (?) da gebaut hast.Ich meinte natürlich Orthographische Projektion
Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von »BlueCobold« (01.10.2014, 12:15)
C-/C++-Quelltext |
|
1 |
Shader_Sprite.SetUniform_ProjectionMatrix(CMatrix44::Build_OrthographicProjectionMatrix(-g_nWidth/2.0f, g_nWidth/2.0f, -g_nHight/2.0f, g_nHight/2.0f, 0.0f, 1.0f)); |
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
void CSprite::Draw(int nCenterPosX, int nCenterPosY, float fScaleX, float fScaleY, float fAngle) { CMatrix33 m33Scale; CMatrix33 m33Rot; CMatrix33 m33Trans; CVector2 Vertex[6]; CVector2 Texture[6]; CVector3 v3Temp; int i; float fX1; float fX2; float fY1; float fY2; // use texture width and hights to calculate coordinates fX1 = (float)((CTexture_2D*)GetTexture2D())->m_nWidth/-2.0f; fX2 = (float)((CTexture_2D*)GetTexture2D())->m_nWidth/2.0f; fY1 = (float)((CTexture_2D*)GetTexture2D())->m_nHeight/2.0f; fY2 = (float)((CTexture_2D*)GetTexture2D())->m_nHeight/-2.0f; // triangle 1 Vertex[0] = CVector2(fX1,fY1); Vertex[1] = CVector2(fX1,fY2); Vertex[2] = CVector2(fX2,fY2); // triangle 2 Vertex[3] = CVector2(fX1,fY1); Vertex[4] = CVector2(fX2,fY2); Vertex[5] = CVector2(fX2,fY1); m33Scale = CMatrix33::Build_2DScaleMatrix (fScaleX, fScaleY); m33Rot = CMatrix33::Build_2DRotationMatrix (fAngle); m33Trans = CMatrix33::Build_2DTranslationMatrix((float)nCenterPosX, (float)nCenterPosY); for(i=0; i<6; i++) { Vertex[i] = m33Scale * Vertex[i]; Vertex[i] = m33Rot * Vertex[i]; Vertex[i] = m33Trans * Vertex[i]; } // texture trianngle 1 Texture[0] = CVector2(0.0f, 1.0f); Texture[1] = CVector2(0.0f, 0.0f); Texture[2] = CVector2(1.0f, 0.0f); // texture trianngle 2 Texture[3] = CVector2(0.0f, 1.0f); Texture[4] = CVector2(1.0f, 0.0f); Texture[5] = CVector2(1.0f, 1.0f); glBindVertexArray(m_unVAO); { glBindBuffer(GL_ARRAY_BUFFER, m_unVBO); glBufferData(GL_ARRAY_BUFFER, sizeof(Vertex) + sizeof(Texture), NULL, GL_DYNAMIC_DRAW); glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(Vertex), Vertex); glBufferSubData(GL_ARRAY_BUFFER, sizeof(Vertex), sizeof(Texture), Texture); glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, (GLvoid*)0); glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 0, (GLvoid*)sizeof(Vertex)); glEnableVertexAttribArray(0); glEnableVertexAttribArray(1); glEnable(GL_BLEND); glDepthMask(GL_FALSE); glDrawArrays(GL_TRIANGLES, 0, 6); glDepthMask(GL_TRUE); glDisable(GL_BLEND); glDisableVertexAttribArray(0); glDisableVertexAttribArray(1); glBindBuffer(GL_ARRAY_BUFFER, 0); } glBindVertexArray(0); } |
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
static char sVertexShader[] = "#version 330\n" "precision highp float;\n" "precision highp int;\n" "\n" "layout (location = 0) in vec2 _v2Vertex;\n" "layout (location = 1) in vec2 _v2Texture;\n" "\n" "uniform mat4 u_m4PM;\n" "\n" "out vec2 _v2Texture_;\n" "\n" "void main (void)\n" "{\n" " _v2Texture_ = _v2Texture;\n" " gl_Position = u_m4PM * vec4(_v2Vertex.x, _v2Vertex.y, -0.5, 1.0);\n" <--- Hier die mul. mit PM "}\n"; |
Community-Fossil
Beruf: Teamleiter Mobile Applikationen & Senior Software Engineer
Genau da:Dann sag mal wo der Faktor bei mir steckt ...
Die Projection Matrix kannst Du auch mit -1..+1 bauen, was wohl vorher scheinbar der Fall war (oder Du hast gar keine gesetzt). Jetzt setzt Du eine mit dem richtigen Faktor.Shader_Sprite.SetUniform_ProjectionMatrix(CMatrix44::Build_OrthographicProjectionMatrix(-g_nWidth/2.0f, g_nWidth/2.0f, -g_nHight/2.0f, g_nHight/2.0f, 0.0f, 1.0f));
Administrator
"Height" schreibt man übrigens mit "e".
Genau da:Dann sag mal wo der Faktor bei mir steckt ...Die Projection Matrix kannst Du auch mit -1..+1 bauen, was wohl vorher scheinbar der Fall war (oder Du hast gar keine gesetzt). Jetzt setzt Du eine mit dem richtigen Faktor.Shader_Sprite.SetUniform_ProjectionMatrix(CMatrix44::Build_OrthographicProjectionMatrix(-g_nWidth/2.0f, g_nWidth/2.0f, -g_nHight/2.0f, g_nHight/2.0f, 0.0f, 1.0f));
C-/C++-Quelltext |
|
1 2 3 4 |
float fX1 = 2.0f * (float)nSpritePosX / (float)nScreenWidth - 1.0f; float fX2 = 2.0f * ((float)nSpritePosX + (float)nSpriteWidth) / (float)nScreenWidth - 1.0f; float fY1 = -2.0f * (float)nSpritePosY / (float)nScreenHight + 1.0f; float fY2 = -2.0f * ((float)nSpritePosY + (float)nSpriteHight) / (float)nScreenHight + 1.0f; |
Alter Hase
Beruf: Softwareentwickler (aktuell Web/Node); Freiberuflicher Google Proxy
"Height" schreibt man übrigens mit "e".
Ja ... sehr schön ...
C-/C++-Quelltext |
|
1 2 3 |
int main() { MaineKlasse obje ckt = MaineKlasse(Vecktor3(1, 1, 1), Vecktor3 (2, 3, 4)); } |
Hmm... eventuell verstehe ich Dich falsch, aber es funktioniert jetzt bei Dir? Dann ist doch prima. Ziemlich ineffizient, für jedes Sprite einen eigenen DrawCall aufzumachen, aber es geht zumindest erstmal. Gute Sache.
"Height" schreibt man übrigens mit "e".
Ja ... sehr schön ...
Stell dir mal vor, jemand anderes liest deinen Code irgendwann.
Stell dir mal vor, du liest den (deutschen, *schauder*) Code von jemand anderem und siehst sowas:
C-/C++-Quelltext
1 2 3 int main() { MaineKlasse obje ckt = MaineKlasse(Vecktor3(1, 1, 1), Vecktor3 (2, 3, 4)); }
(obje_ckt wird geblockt. GJ David!)
Code soll sprechend sein. Sprechend kann Code nur sein, wenn man ihn flüssig lesen kann, ohne lang nachzudenken, was genau gemeint ist, weil der Dev mit Rechtschreibfehlern um sich wirft.
C-/C++-Quelltext |
|
1 |
// use texture width and hights to calculate coordinates
|
Werbeanzeige