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
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 |
[...] int DrawScene() { int sc=40; glLoadIdentity(); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //[.......] glPushMatrix(); glTranslated(300, -100, 0); glScalef(sc,sc ,0); glColor3f(0.5,0.5,0.5); glRotatef(110,0,0,1); glEnableClientState(GL_VERTEX_ARRAY); glVertexPointer(2, GL_FLOAT, 0, q2); glDrawArrays(GL_QUADS, 0, 4); glDisableClientState(GL_VERTEX_ARRAY); glPopMatrix(); return 0; } //[.....] int main(int argc, char** argv) { sf::RenderWindow App(sf::VideoMode(1024, 768, 32), "OpenGL", sf::Style::Close); sf::Clock Clock; //[.....] // getting real-time input for event handling (continious move, etc.) const sf::Input& Input = App.GetInput(); std::ostringstream out; while (App.IsOpened()) { // Start game loop float Framerate = 1.f / App.GetFrameTime(); float ElapsedTime = Clock.GetElapsedTime(); Clock.Reset(); //[....] InitViewMatrix2D(); glMatrixMode(GL_PROJECTION); glTranslated(TranslationX, TranslationY, 0); glScalef(Scale,Scale,0); glMatrixMode(GL_MODELVIEW); glEnable (GL_CULL_FACE); //enables faceculling glFrontFace (GL_CCW); glCullFace (GL_BACK); DrawScene(); App.PreserveOpenGLStates(true); txt.SetText(temp); App.Draw(txt); App.PreserveOpenGLStates(false); // Finally, display rendered frame on screen App.Display(); } return EXIT_SUCCESS; } |
idontknow
unregistriert
Und dieser Tipp bewegt mich doch glatt dazu auszuprobieren die festen Objekte auf einem Grid und die beweglichen Objekte in einem Quadtree zu verwalten - meinen grossen Bruder G frage ich dann nochmal was es mit der Bounding-Volume-Hierarchy auf sich hat. Ei, ich glaub das wird ne lange Nacht ..... Ich melde mich dann nochmal.Zitat
Abgesehen davon hindert dich auch Nichts dran verschiedene Ansätze zu kombinieren
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 |
class Grid { private: std::vector< std::vector<Field> > mFields; int mSize; // mSize*mSize = Fields sf::String s; public: //ctor Grid () {}; //ctor Grid (int pSize) { for (int i=0; i<pSize; i++) { for (int a=0; a<pSize; a++) { this->mFields.push_back(std::vector<Field>(pSize)); } } for (int i=0; i<pSize; i++) { for (int a=0; a<pSize; a++) { this->mFields[i][a].y = i; //row,y this->mFields[i][a].x = a; //col, x } } this->mSize = pSize; s.SetSize(10); s.SetColor(sf::Color(60,60,60)); s.SetScale(1.2,1.2); } //add the [] operator to vector member inline std::vector<Field> & operator[](int i) { return mFields[i]; } void Render(sf::RenderWindow& win, int tx, int ty, int sc) { for (int i=0; i<mSize; i++) { for (int a=0; a<mSize; a++) { if (sc*mFields[i][a].x+tx<0) continue; if (sc*mFields[i][a].x+sc+tx>1280) continue; if (sc*mFields[i][a].y+ty<0) continue; if (sc*mFields[i][a].y+sc+ty>1024) continue; glPushMatrix(); glTranslated(a,i,0); glScalef(1,1,0); glColor3f(0.65,0.65,0.65); glBegin(GL_LINES); glVertex3f(0,0,0); glVertex3f(1,0,0); glVertex3f(0,0,0); glVertex3f(0,1,0); if (a<mSize) { glVertex3f(1,0,0); glVertex3f(1,1,0); } if (a<mSize) { glVertex3f(0,1,0); glVertex3f(1,1,0); } glEnd(); glPopMatrix(); } } } }; |
C-/C++-Quelltext |
|
1 2 |
const Field& operator ()(int x, int y) const { return ...; } Field& operator ()(int x, int y) { return ...; } |
Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von »dot« (14.07.2011, 20:42)
Werbeanzeige