CyanPrime

Member
  • Content count

    50
  • Joined

  • Last visited

Community Reputation

105 Neutral

About CyanPrime

  • Rank
    Member
  1. I got a really cool gift for you! It's a simple to use animated model loader! Here is the entire package you'll need to start your 3d animated modeled games today! [url="https://dl.dropbox.com/u/28109593/JointConnect.zip"]https://dl.dropbox.c...ointConnect.zip[/url] Here is how to use it: [source lang="java"]AnimatedModel model = new AnimatedModel([filename], [scale vector]); [/source] Where [filename] is something like "C:\models\model.ms3d" and [scale vector] is a LWJGL Vector3f that re-sizes the model based on it's content. For example to make a half width double height model you'd say[background=white] [/background] [source lang="java"][background=white]new Vector3f(0.5f, 2.0f, 1.0f)[/background][/source][background=white] [/background] So that's that, and now you may all be wondering why I'm posting this in a help section? Well, you see. It's because I need a bit of help on a thing I'm trying to implement, where you can attach other models to joints of a master model (like master warrior is holding a sword in his left hand) what it boils down to is that I can't figure out how to get the accessory model to stay , or even get to the right place. This is the code the accessory model uses to get it's position and rotation. It's in AnimatedModel.java [source lang="java"] [background=white]public Vector3f[] getJointInfo(float frame, int jointID, float myYaw){ Vector3f[] jointInfo = new Vector3f[2]; jointInfo[0] = new Vector3f(0,0,0); jointInfo[1] = new Vector3f(0,0,0); advanceAnimation(frame, true); Matrix4f worldMatrix = new Matrix4f(); worldMatrix.load(fjm[jointID]); worldMatrix.invert(); worldMatrix.rotate((float) Math.toRadians(myYaw), new Vector3f(0,1,0)); VectorRotate(joints.get(jointID).pos, worldMatrix, jointInfo[0]); /*roll*/jointInfo[1].z = (float) Math.toDegrees(Math.atan2(worldMatrix.m10, worldMatrix.m00)); /*pitch*/jointInfo[1].x = (float) - Math.toDegrees(Math.asin(worldMatrix.m20)); /*yaw*/jointInfo[1].y = (float) Math.toDegrees(Math.atan2(worldMatrix.m01, worldMatrix.m22)); return jointInfo; } [/background] [/source][background=white] [/background]So, if anyone wants to download the .ms3d model loader package and take a look at that method and help me figure out why it's not working it'd help out not only me, but everyone who decides to use this model loader.
  2. I've been working on creating a MD5 model viewer in Java, and while I've managed to read the data, and format it I can't for the life of me figure out why I can't display it properly. I'm following [url="http://tfc.duke.free.fr/coding/md5-specs-en.html"]the instructions here[/url]. but it's just giving me a garbled mess. Can anyone help me? First I'd like to post the important parts of my code: [CODE]private void render(){ GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT); GL11.glLoadIdentity(); GL11.glTranslatef(0, 0, -500); GL11.glColor3f(1.0f, 1.0f, 1.0f);//white int meshNum = 0; texture.bind(); GL11.glBegin(GL11.GL_TRIANGLES); for(int i = 0; i < model.meshes.get(meshNum).numTris; i++){ Tri t = model.meshes.get(meshNum).tris.get(i); GL11.glTexCoord2f(0,0); GL11.glVertex3f(model.vertices.get(t.vert1).x,model.vertices.get(t.vert1).y,model.vertices.get(t.vert1).z); GL11.glTexCoord2f(1,0); GL11.glVertex3f(model.vertices.get(t.vert2).x,model.vertices.get(t.vert2).y,model.vertices.get(t.vert2).z); GL11.glTexCoord2f(1,1); GL11.glVertex3f(model.vertices.get(t.vert3).x,model.vertices.get(t.vert3).y,model.vertices.get(t.vert3).z); } GL11.glEnd(); }[/CODE] And [CODE]public void computeVertices(Mesh m){ for(int i = 0; i < m.numVerts; i++){ Vector3f pos = new Vector3f(0,0,0); int start = m.verts.get(i).weightIndex; int count = m.verts.get(i).weightElement; for(int j = count; j < count + start; j++){ Joint joint = joints.get(m.weights.get(j).jointIndex); Vector3f temp = joint.pos; Vector3f wt = applyQuat(m.weights.get(j).pos, joint.orient); Vector3f.add(temp, wt, temp); temp.scale(m.weights.get(j).value); Vector3f.add(pos, temp, pos); } vertices.add(pos); } }[/CODE] My blog I set up just now has more links, like the full source code, and what not. I don't want to link all those links here cause I think it'd be too many links, so I'll [url="http://cyandev.shiftarch.com/?p=5"]just direct you to here[/url] if you need more info.
  3. Billboarding woes

    Got it working, finally ;D ;D ;D ;D ;D ;D ;D [code] public void drawBillBoardSprite(Texture texture, Vector3f sprPos, float r, float g, float b, int sprWidth, int sprHeight){ // store the current model matrix GL11.glPushMatrix(); GL11.glTranslatef(sprPos.x, 0, sprPos.z); // bind to the appropriate texture for this sprite texture.bind(); FloatBuffer modelview = BufferUtils.createFloatBuffer(16); // get the current modelview matrix GL11.glGetFloat(GL11.GL_MODELVIEW_MATRIX, modelview); // Note that a row in the C convention is a column // in OpenGL convention (see the red book, pg.106 in version 1.2) // right vector is [1,0,0] (1st column) // lookAt vector is [0,0,1] (3d column) // leave the up vector unchanged (2nd column) // notice the increment in i in the first cycle (i+=2) for(int i=0; i<3; i+=2 ) for(int j=0; j<3; j++ ) { if ( i==j ) modelview.put(i*4+j, 1.0f); else modelview.put(i*4+j, 0.0f); } // set the modelview matrix GL11.glLoadMatrix(modelview); // draw a quad textured to match the sprite GL11.glBegin(GL11.GL_QUADS); GL11.glTexCoord2f(0,0); GL11.glVertex3f( - (sprWidth/2), (sprHeight/2), 0); // Top left Of The Quad (Left) GL11.glTexCoord2f(texture.getWidth(), 0); GL11.glVertex3f( + (sprWidth/2), (sprHeight/2), 0); // Top right Of The Quad (Left) GL11.glTexCoord2f(texture.getWidth(), texture.getHeight()); GL11.glVertex3f( + (sprWidth/2), -(sprHeight/2), 0); // Bottom right Of The Quad (Left) GL11.glTexCoord2f(0, texture.getHeight()); GL11.glVertex3f( - (sprWidth/2), -(sprHeight/2), 0); // Bottom left Of The Quad (Left) GL11.glEnd(); // restore the model view matrix to prevent contamination GL11.glPopMatrix(); } [/code]
  4. I'm trying to get Billboarding in my game, but I can't seem to get it to work. I've tried both Lighthouse's and NeHe's tutorials, but no matter what there are problems. My current code uses gl rotate, and translate, but the sprites seem to rotate too slowly, and rotate also based on the distance of the player/camera from the sprite. Here is the code, can anyone help me? [code] public void drawBillBoardSprite(Texture texture, Vector3f sprPos, float r, float g, float b, int sprWidth, int sprHeight){ // store the current model matrix GL11.glPushMatrix(); GL11.glTranslatef(sprPos.x, 0, sprPos.z); // bind to the appropriate texture for this sprite texture.bind(); Vector3f objToCam = new Vector3f(player.pos.x - sprPos.x, 0, player.pos.z - sprPos.x); Vector3f look = new Vector3f(0,0,1); objToCam.normalise(); float angleCosine = Vector3f.dot(look, objToCam); Vector3f upAux = new Vector3f(0,0,0); Vector3f.cross(look, objToCam, upAux); if ((angleCosine < 0.9999999) && (angleCosine > -0.9999999)) { float angle = (float) (Math.toDegrees(Math.acos(angleCosine))); GL11.glRotatef(angle, upAux.x, upAux.y, upAux.z); } // draw a quad textured to match the sprite GL11.glBegin(GL11.GL_QUADS); GL11.glTexCoord2f(0,0); GL11.glVertex3f( - (sprWidth/2), (sprHeight/2), 0); // Top left Of The Quad (Left) GL11.glTexCoord2f(texture.getWidth(), 0); GL11.glVertex3f( + (sprWidth/2), (sprHeight/2), 0); // Top right Of The Quad (Left) GL11.glTexCoord2f(texture.getWidth(), texture.getHeight()); GL11.glVertex3f( + (sprWidth/2), -(sprHeight/2), 0); // Bottom right Of The Quad (Left) GL11.glTexCoord2f(0, texture.getHeight()); GL11.glVertex3f( - (sprWidth/2), -(sprHeight/2), 0); // Bottom left Of The Quad (Left) GL11.glEnd(); // restore the model view matrix to prevent contamination GL11.glPopMatrix(); } [/code]
  5. Nothing showing up on screen?

    [quote name='karwosts' timestamp='1302714254' post='4798017'] Couple thoughts: 1) You call LoadIdentity in the beginning of render on an unspecified matrix stack. Does this clear the projection matrix on the first pass, as that stack is still bound when you exit the setup function? 2) What color is your quad supposed to be? Why is texturing enabled? 3) Your quad is lying on the near plane, not sure how the clipping calculations work exactly but I'm not positive if things exactly on the near plane get clipped or not. [/quote] yup, it was 1, the LoadIdentity. Thank you very much
  6. Alright, so I'm converting my engine to Java using LWJGL, and when I draw stuff it doesn't show up on screen. I'm doing the same thing I did in c++, but maybe I got something wrong? (Note, you should be able to read this and answer if you know c++, as it's the same thing with GL11. in frount of everything.) [code] private void initGL(int Width, int Height) { GL11.glViewport(0, 0, Width, Height); GL11.glClearColor(0.0f, 0.0f, 0.0f, 0.0f); // This Will Clear The Background Color To Black GL11.glClearDepth(1.0); // Enables Clearing Of The Depth Buffer GL11.glDepthFunc(GL11.GL_LESS); // The Type Of Depth Test To Do GL11.glDisable(GL11.GL_DEPTH_TEST); // Enables Depth Testing //glShadeModel(GL_SMOOTH); // Enables Smooth Color Shading GL11.glEnable(GL11.GL_TEXTURE_2D); // Enable Texture Mapping ( NEW ) GL11.glShadeModel(GL11.GL_FLAT); GL11.glMatrixMode(GL11.GL_PROJECTION); GL11.glEnable(GL11.GL_BLEND); GL11.glBlendFunc(GL11.GL_SRC_ALPHA , GL11.GL_ONE_MINUS_SRC_ALPHA); GL11.glHint(GL11.GL_PERSPECTIVE_CORRECTION_HINT, GL11.GL_NICEST); GL11.glAlphaFunc(GL11.GL_GREATER, 0.5f); GL11.glMatrixMode(GL11.GL_PROJECTION);//configuring projection matrix now GL11.glLoadIdentity();//reset matrix GL11.glOrtho(0, 640, 0, 480, 0.0f, 100.0f);//set a 2d projection matrix } private void render() { GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT); // Clear The Screen And The Depth Buffer GL11.glLoadIdentity(); // Reset The Current Modelview Matrix GL11.glMatrixMode(GL11.GL_MODELVIEW);//configuring modelview matrix now GL11.glLoadIdentity();//reset matrix GL11.glBegin(GL11.GL_QUADS); // Draw A Quad GL11.glVertex3f(0, 50, 0); // Top Left GL11.glVertex3f(50,50, 0); // Top Right GL11.glVertex3f(50,100,0); // Bottom Right GL11.glVertex3f(0,100, 0); // Bottom Left GL11.glEnd(); // Done Drawing The Quad } [/code]
  7. [quote name='mrchrismnh' timestamp='1302646831' post='4797683'] Capital E [/quote] What do you mean?
  8. Okay, so thats my error: 'Enemy' was not declared in this scope.The error is in the map.h file, even though map.h includes enemy.h as shown [code] #ifndef MAP_H_INCLUDED #define MAP_H_INCLUDED #include <iostream> #include <fstream> #include <string> #include <vector> #include "enemy.h" #define MAX_TILE_TYPES 20 using namespace std; class Map{ public: Map(); void loadFile(string filename); int** tile; int** ftile; bool solid[MAX_TILE_TYPES]; int width; int height; int tileSize; vector<Enemy> enemies; }; #endif // MAP_H_INCLUDED [/code] And here is enemy.h [code] #ifndef ENEMY_H_INCLUDED #define ENEMY_H_INCLUDED #include "global.h" #include "map.h" class Enemy{ public: Enemy(); Enemy(float nx, float ny, float nstate); void update(Map lv); bool rectangleIntersects(float rect1x, float rect1y, float rect1w, float rect1h, float rect2x, float rect2y, float rect2w, float rect2h); void update(); float x; float y; Vector2f velo; float speed; float maxFallSpeed; int state; int frame; int width; int height; int maxStates; int *maxFrames; int frameDelay; bool facingLeft; bool onGround; bool dead; int drawType; }; #endif // ENEMY_H_INCLUDED [/code] Anyone know whats going on and how to fix it?
  9. That worked. Thank you rep++
  10. Hello, I'm trying to draw a 2d character sprite on top of a 2d tilemap, but when I draw the character he's got odd stuff behind him. This isn't in the sprite, so I think its the blending. This is how my openGL is set up: [code] void InitGL(int Width, int Height) // We call this right after our OpenGL window is created. { glViewport(0, 0, Width, Height); glClearColor(0.0f, 0.0f, 0.0f, 0.0f); // This Will Clear The Background Color To Black glClearDepth(1.0); // Enables Clearing Of The Depth Buffer glDepthFunc(GL_LESS); // The Type Of Depth Test To Do glDisable(GL_DEPTH_TEST); // Enables Depth Testing //glShadeModel(GL_SMOOTH); // Enables Smooth Color Shading glEnable(GL_TEXTURE_2D); // Enable Texture Mapping ( NEW ) glShadeModel(GL_FLAT); glMatrixMode(GL_PROJECTION); glEnable(GL_BLEND); glBlendFunc(GL_ONE , GL_ONE_MINUS_SRC_ALPHA); glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); glAlphaFunc(GL_GREATER, 0.5f); glMatrixMode(GL_PROJECTION);//configuring projection matrix now glLoadIdentity();//reset matrix glOrtho(0, Width, 0, Height, 0.0f, 100.0f);//set a 2d projection matrix }[/code] How should I set this up to work properly (i.e. drawing the sprite without odd stuff behind him. This is what I am talking about: [url="http://i.imgur.com/cmotJ.png"]http://i.imgur.com/cmotJ.png[/url] PS: I need to be able to put transparent/semi-transparent images on top of each other and have whats behind them visible too
  11. OpenGL glOrtho - how does it work?

    That worked! Thank you!
  12. I'm trying to get it so I can draw on openGL's screen like a normal sdl screen, so 1 unit in GL space is 1 pixel. I heard you can use glOrtho to do this, but all my attempts have failed. This is what I got so far: [code] void InitGL(int Width, int Height) // We call this right after our OpenGL window is created. { glViewport(0, 0, Width, Height); glClearColor(0.0f, 0.0f, 0.0f, 0.0f); // This Will Clear The Background Color To Black glClearDepth(1.0); // Enables Clearing Of The Depth Buffer glDepthFunc(GL_LESS); // The Type Of Depth Test To Do glEnable(GL_DEPTH_TEST); // Enables Depth Testing //glShadeModel(GL_SMOOTH); // Enables Smooth Color Shading glEnable(GL_TEXTURE_2D); // Enable Texture Mapping ( NEW ) glShadeModel(GL_FLAT); glMatrixMode(GL_PROJECTION); glEnable(GL_BLEND); glBlendFunc(GL_ONE , GL_ONE_MINUS_SRC_ALPHA); glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); glLoadIdentity(); // Reset The Projection Matrix gluPerspective(45.0f,(GLfloat)Width/(GLfloat)Height,0.1f,1000.0f); // Calculate The Aspect Ratio Of The Window glMatrixMode(GL_MODELVIEW); glOrtho(0, Width, 0, Height, 0.0f, 100.0f); } [/code] and this is where I draw: [code] void DrawGLScene() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear The Screen And The Depth Buffer glLoadIdentity(); // Reset The View glTranslatef(-1.5f,0.0f,-995.0f); // Move Left 1.5 Units And Into The Screen 6.0 // draw a square (quadrilateral) glBindTexture(GL_TEXTURE_2D, tilemap); glBegin(GL_QUADS); // start drawing a polygon (4 sided) // Front Face for(int x = 0; x < lv.width; x++){ for(int y = 0; y < lv.height; y++){ if((x * lv.tileSize) - worldX > -lv.tileSize && (y * lv.tileSize) - worldY > -lv.tileSize && (x * lv.tileSize) - worldX < 640 && (y * lv.tileSize) - worldY < 480){ int tileXCoord = 0; int tileYCoord = 0; tilemapWidth = 192; // glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &tilemapWidth); int tileSheetWidth = tilemapWidth / lv.tileSize; if (lv.tile[x][y] != 0) { tileXCoord = lv.tile[x][y] % tileSheetWidth; tileYCoord = lv.tile[x][y] / tileSheetWidth; } glTexCoord2f(tileXCoord* (1.0f/(tilemapWidth/lv.tileSize)) + 0.05, (tileYCoord + 1) * (1.0f/(tilemapWidth/lv.tileSize)) - 0.05); glVertex3f(x * lv.tileSize, y * lv.tileSize, 1.0f); // Bottom Left Of The Texture and Quad glTexCoord2f((tileXCoord + 1) * (1.0f/(tilemapWidth/lv.tileSize)) - 0.05, (tileYCoord + 1) * (1.0f/(tilemapWidth/lv.tileSize)) - 0.05); glVertex3f((x + 1) * lv.tileSize, y * lv.tileSize, 1.0f); // Bottom Right Of The Texture and Quad glTexCoord2f((tileXCoord + 1) * (1.0f/(tilemapWidth/lv.tileSize)) - 0.05, tileYCoord* (1.0f/(tilemapWidth/lv.tileSize)) + 0.05); glVertex3f((x + 1) * lv.tileSize, (y + 1) * lv.tileSize, 1.0f); // Top Right Of The Texture and Quad glTexCoord2f(tileXCoord* (1.0f/(tilemapWidth/lv.tileSize)) + 0.05, tileYCoord* (1.0f/(tilemapWidth/lv.tileSize)) + 0.05); glVertex3f(x * lv.tileSize, (y + 1) * lv.tileSize, 1.0f); // Top Left Of The Texture and Quad /* glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, -1.0f, 1.0f); // Bottom Left Of The Texture and Quad glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, -1.0f, 1.0f); // Bottom Right Of The Texture and Quad glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, 1.0f, 1.0f); // Top Right Of The Texture and Quad glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, 1.0f, 1.0f); // Top Left Of The Texture and Quad */ // apply_surface(tileXCoord * lv.tileSize, tileYCoord * lv.tileSize, lv.tileSize, lv.tileSize, (x * lv.tileSize) - worldX, (y * lv.tileSize) - worldY, tilemap, screen); } } } glEnd(); // done with the polygon // swap buffers to display, since we're double buffered. SDL_GL_SwapBuffers(); } [/code] Can anyone tell me what I'm doing wrong?
  13. clamp to edge didn''t help, so I gave up and did the -/+ 0.05px thing It works, but I don't like having hacks in my programs.
  14. 'GL_TEXTURE_2D_ARRAY' was not declared in this scope 'GL_CLAMP_TO_EDGE' was not declared in this scope
  15. Alright, so I'm moving my engine to openGL and When I try to draw the tilemap there are white lines through it, so I wanna know how to get rid of them (hopefully without doing the +/- 0.5 of a pixel thing). This is my initGL [code] void InitGL(int Width, int Height) // We call this right after our OpenGL window is created. { glOrtho(0, 640, 0, 480, 0.0f, 100.0f); glViewport(0, 0, Width, Height); glClearColor(0.0f, 0.0f, 0.0f, 0.0f); // This Will Clear The Background Color To Black glClearDepth(1.0); // Enables Clearing Of The Depth Buffer glDepthFunc(GL_LESS); // The Type Of Depth Test To Do glEnable(GL_DEPTH_TEST); // Enables Depth Testing //glShadeModel(GL_SMOOTH); // Enables Smooth Color Shading glEnable(GL_TEXTURE_2D); // Enable Texture Mapping ( NEW ) glShadeModel(GL_FLAT); glMatrixMode(GL_PROJECTION); glEnable(GL_BLEND); glBlendFunc(GL_ONE , GL_ONE_MINUS_SRC_ALPHA); glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); glLoadIdentity(); // Reset The Projection Matrix gluPerspective(45.0f,(GLfloat)Width/(GLfloat)Height,0.1f,100.0f); // Calculate The Aspect Ratio Of The Window glMatrixMode(GL_MODELVIEW); } [/code] And my texture loading is: [code] GLuint load_texture(const char* file) { SDL_Surface* surface = IMG_Load(file); GLuint texture; glPixelStorei(GL_UNPACK_ALIGNMENT,4); glGenTextures(1, &texture); glBindTexture(GL_TEXTURE_2D, texture); SDL_PixelFormat *format = surface->format; if (format->Amask) { gluBuild2DMipmaps(GL_TEXTURE_2D, 4, surface->w, surface->h, GL_RGBA,GL_UNSIGNED_BYTE, surface->pixels); } else { gluBuild2DMipmaps(GL_TEXTURE_2D, 3, surface->w, surface->h, GL_RGB, GL_UNSIGNED_BYTE, surface->pixels); } SDL_FreeSurface(surface); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST); // Linear Filtering glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST); // Linear Filtering return texture; } [/code] This is what I'm talking about for white lines, by the way: http://i.imgur.com/GKztG.png