• Content count

  • Joined

  • Last visited

Community Reputation

142 Neutral

About alejandro

  • Rank
  1. OpenGL Collision Detection

    struct Rect { float x, y; float w, h; // true means there's a collision bool checkCollision(Ball & ball) { return ball.x > x && ball.x < x + w && ball.y > y && ball < y + w } }; struct Ball { float x, y; float w, h; float dir_x, dir_y; }; Rect paddle; Ball ball; void display(void) { if(paddle.checkCollision(ball)) { ball.dir_x *= -ball.dir_x; } } This may work :)
  2. Movement behaviour is a common topic on any AI for games  book, you can check this oune out:
  3. Game Architecture/Design Pattern?

    As i see, there's no best pattern... though I like to use managers since it's easier to me to read the code like this.
  4. Game Architecture/Design Pattern?

    Thank you very mucho for all your comments, I liked the idea on Performance vs Maintainability, also because a lot of the code I do is also read by other team members so it's important to have maintanable code   I'll take a look at the Game Engine book   Until know there's no clear best one, it appears as everyone has different approaches, that's what I am searching, how people create the architecture of the code.   Does anyone has an example on how MVC pattern will work in a videogame? particulary on Unity
  5. Hello,   I want to know if there are any game architectures that are recommended, well, actually I don't know if I can call them architectures or design patterns.   Basically what I want to know is how do you structure your games at a logical for example I tend to the following.   I create an object named GameMaster, this object controls the game (enemies, ambient, etc) and knows the state of everything in the game, the control is done through Managers, for example EnemieManager, AmbientManager, etc. This managers don't communicate directly, the communication has to go throught the GameMaster.   In a more plactical way say we have the following:   class GameMaster { Player player; EnemyManager enemyManager; GameStatus status; void update() { if(enemyManager.enemies == 0) { status = GameStatus.EndGame; } if(status == GameStatus.EndGame) { player.stopInteraction(); } } void draw() { drawString(status); } }   Sure, the managers can also have control of a few elements... what I see in some friends code is more like...   class Player { GameStatus status; void update() { if(status == GameStatus.EndGame) { player.stopInteraction(); } } void draw()     {          drawString(status);     } } class EnemiesManager { Player player; int enemies; void update() { if(enemies == 0) { player.status = GameStatus.EndGame; } } } So my doubt are, what is better? what is worse? are there any architecture/patterns for structuring the objects in the videogames?.   I follow the GameMaster pattern because it's easier to me to structure things like this, but maybe this is not the best pattern...     Any literature on the topic is appreaciated
  6. Switching from 2D to 3D for drawing object

    You could try using fbo's, [url=""]here's[/url] a good tutorial with a working example
  7. Applying Look At matrix

    Solved, if I inverse the matrix I get the results that I expected, at the end the code is like the following [CODE] void camera::drawDebug() { glm::mat4 res = glm::lookAt(eye, target, up); res = glm::inverse(res); glMultMatrixf(&res[0][0]); glTranslatef(-eye.x, -eye.y, -eye.z); glutWireCube(1.5); } [/CODE] Don't know exactly why this works.
  8. Applying Look At matrix

    I try it, still not there, it looks similar to previous result.
  9. Applying Look At matrix

    I'm developing a camera class on OpenGL in C++, I want to see the position and rotation that the camera has when using gluLookAt(), for this I'm using glm::lookAt() function, it retrieves a matrix 4x4 and then I multiply the current stack matrix with the one that was retrieve, and then I translate the camera to the position. So my code looks like this [CODE] void camera::drawDebug() { glm::mat4 res = glm::lookAt(eye, target, up); glMultMatrixf(&res[0][0]); glTranslatef(-eye.x, -eye.y, -eye.z); glutWireCube(1.5); } [/CODE] with this code I get the following image, considering that the red cube is at the center(0, 0, 0), and the wire cube is the camera, eye is (0, 5, 5), target is (0, 0, 0), up is (0, 1, 0) [img][/img] As you can see it appears that the rotation is applied correctly but the translation is not correct. I'm doing -eye translation because of what it says on the documentation of [url=""]glulookat[/url]. [quote] ...gluLookAt is equivalent to glMultMatrixf(M); glTranslated (-eyex, -eyey, -eyez); [/quote] Any ideas on how to fix the translation?
  10. Switching from 2D to 3D for drawing object

    Hi, A few weeks ago I was messing with the same stuff, you can get a working example in [url=""]here[/url](sorry for all the messy code, hope it's useful). Basically your display function will look something like this. [CODE] void display() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // you can get the width and height using glutGet(GLUT_WINDOW_WIDTH) or HEIGHT height = height==0 ? 1 : height; float ratio = width * 1.0 / height; // dibujado en 3D glEnable(GL_DEPTH_TEST); glEnable(GL_LIGHTING); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(45.0f, ratio, .1f, 1000.0f); glMatrixMode( GL_MODELVIEW ); glLoadIdentity(); gluLookAt( eyex, eyex, eyez, centerx, centery, centerz, upx, upy, upz ); glPushMatrix(); { // draw 3D things in here } glPopMatrix(); // 2D drawing glDisable(GL_DEPTH_TEST); glDisable(GL_LIGHTING); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluOrtho2D(0, width, height, 0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glPushMatrix(); { // draw 2D things in here } glPopMatrix(); glutSwapBuffers(); } [/CODE]
  11. Exporting obj on Maya 2012

    Everything loads correctly now, what I did was, change the .mtl file in the line where's kd 0.000 0.000 0.000 to 1.000 1.000 1.000 and I was not correctly binding the texture.
  12. Exporting obj on Maya 2012

    I'm a total noob on Maya, so far I know how to place a cube and map it through UV Mapping editor . I want to export the model in an .obj file with the texture (.dds) and then add it to the Game Engine (using Assimp). The obj loads correctly and the texture loads ok, but the model is black, so I try loading the obj on Assimp viewer and the model is black though it loads correctly the texture, so I'm thinking that there's something wrong with the obj file and the uv coords. Though in maya everything looks ok Can you tell me how to export correctly the model? The steps I follow are, select the obj, then file>Export Selection>*.obj, save Thanks!
  13. This page has a few OpenGL 4.0 tutorials: and this site has almost any new functionality on OpenGL with an example
  14. I'm trying OpenGL 4.0 Tessellation and I want to apply it to an stablished model, my model is on .md2 format, I'm assuming that a Bezier evaluation will do with the evaluation shader, though I may be very very wrong. Anyways I'm stuck with the following instructions [code] draw() { glBindBuffer( GL_ARRAY_BUFFER, vboid) { ... glPatchParameteri(GL_PATCH_VERTICES, 3); glDrawArrays( GL_PATCHES, 0, size ); // size = how many vertices the model has ... } glBindBuffer( GL_ARRAY_BUFFER, 0) } [/code] The problem is that when it renders the model looks all messy and it certainly doesn't look like when I rendered it using glDrawArrays(GL_TRIANGLES, 0, size). Any suggestions on what parameters to use on glPatchParam... and glDrawArrays? Thank you
  15. [quote name='karwosts' timestamp='1313425340' post='4849445'] Are you using GLEW? [/quote] Yes, glew 1.6 [quote name='karwosts' timestamp='1313425340' post='4849445'] Can you make sure that it is loading glBindFragDataLocation? [/quote] I'm not sure how can I do that, but if I go to the definition on VS 2010 I found the header definition of the function [quote name='karwosts' timestamp='1313425340' post='4849445'] Maybe you can try using glBindFragDataLocationExt instead. [/quote] It worked, at least no compile errors, though I don't see anything