Jump to content

  • Log In with Google      Sign In   
  • Create Account

CyanPrime

Member Since 08 Jun 2010
Offline Last Active Jul 13 2012 04:20 PM

Topics I've Started

Free .ms3d animated loader - need help with getting joint position/rotation

08 July 2012 - 10:30 AM

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!
https://dl.dropbox.c...ointConnect.zip

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
[source lang="java"][background=white]new Vector3f(0.5f, 2.0f, 1.0f)[/background][/source]

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]
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.

Errors displaying MD5MESH file in Java

18 January 2012 - 05:40 PM

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 the instructions here. 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:

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();
    }

And

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);
        }
    }


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 just direct you to here if you need more info.

Billboarding woes

13 December 2011 - 07:03 PM

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?

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();

	}

Nothing showing up on screen?

13 April 2011 - 10:52 AM

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.)

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
	}

'Enemy' was not declared in this scope?

12 April 2011 - 04:05 PM

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

#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


And here is enemy.h

#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


Anyone know whats going on and how to fix it?

PARTNERS