Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!

1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


Member Since 07 Sep 2011
Offline Last Active Jun 20 2012 08:41 AM

Topics I've Started

Hello Box2D not working. What am I doing wrong?

11 March 2012 - 08:09 PM

Ok, so I set out to add box2d to my project, but I couldn't for the life of me get it to work. After hours of frustration, I decided to try to run the hello box2d from the documentation, but when I do, the body's position doesn't change, even though gravity should be taking it's tole.

my code for the hello Box2d looks like this:

int main()
	    b2World world(b2Vec2(0.0, -9.8));
b2BodyDef bodyDef;
bodyDef.position.Set(3.0, 3.0);
bodyDef.angle = 0.0f;
bodyDef.type = b2_dynamicBody;
b2PolygonShape shape;
shape.SetAsBox(10, 10);
b2FixtureDef fixtureDef;
fixtureDef.shape = &shape;
fixtureDef.density = 1.0f;
fixtureDef.friction = 0.3f;
body = world.CreateBody(&bodyDef);
  world.Step(1/60, 10, 8);
  std::cout << body->GetPosition().y << std::endl;

What am I doing wrong?

[JOGL] TextureCoords class issues

19 November 2011 - 10:44 AM

This is probably a stupid mistake on my part that I am overlook, but I have spent a good couple of hours trying to figure this out, to no avail.

I am creating a TextureCoords object from a Texture object I have loaded, but when I go to assign the texture coords, the resulting map is sideways. Here is the rendering code I have

				gl.glVertex3f(pos.x, pos.y, 0.0f);
				gl.glTexCoord2f(coords.left(), coords.bottom());
				gl.glVertex3f(pos.x + scaledW, 0, 0.0f);
				gl.glTexCoord2f(coords.right(), coords.bottom());
				gl.glVertex3f(pos.x + scaledW, pos.y + scaledH, 0.0f);
				gl.glTexCoord2f(coords.right(), coords.top());
				gl.glVertex3f(0.0f, pos.y + scaledH, 0.0f);
				gl.glTexCoord2f(coords.left(), coords.top());

pos is a Position object holding the x and y positions of the object
scaledW and scaledH are scaled versions of the texture' (as a BufferedImage) width and height.

the resulting image is this:
Posted Image

I'm obviously doing something wrong, just not sure what.

Any help appreciated.

[java] Lists, Vectors, and Iteration

22 October 2011 - 02:53 PM

I suppose the question I have is two-fold, so I will number them for clarity:

1) Am I correct in assuming that the LinkedList class is more efficient than the Vector class?

2) When working with a List (whether it be ArrayList, LinkedList, etc...) is it better to use an Iterator object to traverse the list, or to use a loop and accessor methods?

The reason I ask is because I am working on a game that the GameObject class contains a list of Component objects. when the GameObject is updated, it traverses the list, calling the update method of each component. At the moment, I am using a LinkedList and traversing it by means of an Iterator object, but I am scared that bottlenecks can arise due to the nature of Iterators.

Time scale for slow motion effects and game pausing

20 October 2011 - 03:50 PM

After finally achieving frame-rate independance (See this thread: http://www.gamedev.net/topic/613049-deltatime-issues/page__gopid__4874823#entry4874823), I am now after the implementation of a time scale.
Basically, I have a data member of my Time class that is always between 0.0f, and 1.0f. When this value is 1.0f, frame updates should behave normally, however, if the time scale is 0.0f, no frame updates should occur. Anything in between should scale the number of updates approriately. My problem is deciding what the best variable to scale by would be. I have the following update function:

public void onDrawFrame(GL10 gl) 
		float newTime = System.nanoTime() / 1000000000.0f;
		Time.deltaTime = frameTime = newTime - currentTime;
		//currentTime = newTime;
		if(frameTime > Time.maxDeltaTime)
			frameTime = Time.maxDeltaTime;
		currentTime = newTime;
		accumulator += frameTime;
		while(accumulator > Time.fixedDeltaTime)
			//Perform Fixed Updates here
			accumulator -= Time.fixedDeltaTime;
		Log.e("IMPACT","" + Time.deltaTime);
		go.transform.position.x += 10 * Time.deltaTime;///1000000000.0f;

I am assuming that I should just multiply Time.deltaTime by timeScale in order to scale it appropriately, however that only takes care of the variable frame update, not the fixed frame update (Physics calculations).

Should I also multiply the frameTime variable by timeScale or is there something better?

deltaTime issues

19 October 2011 - 08:09 PM

First of all, I should note that I am developing this engine for the android OS, so memory, CPU speed, and GPU speed are all limited. I am also using Java, however on most relatively newer android devices--provided they are running at least android 2.2--Java is JIT compiled rather than interpreted. i am also making use of the JNI and native code whenever I see fit.

At any rate, I am having some issues implementing a deltaTime variable.
I have this class"

public class Time 
	public static long timeFrameStarted = 0;	// system time at start of frame
	public static long timeOfStart;				// system time of the start of the scene
	public static float deltaTime = 0;			//time it took to complete last frame
	public static long frameCount = 0; 			// Number of rendered frames

and my update function called each from looks like so:

public void onDrawFrame(GL10 gl) 
		Time.timeFrameStarted = System.currentTimeMillis();
		Log.e("IMPACT", "" + Time.deltaTime);
		// TODO Auto-generated method stub
		go.transform.position.x += 100 * Time.deltaTime;
		Time.deltaTime = (float)((System.currentTimeMillis() - Time.timeFrameStarted)/1000.f);

go is my GameObject. Everything else should be self explanatory.

At any rate, this code does work, however as the game object is moving across the screen, it will move smoothly, then jerk forward, move smoothly again, then jerk forward again, and so on.

I am not sure if it has something to do with my implementation of deltaTime or if I simply need to optimize my openGL code inside of my draw methods.

Here is a video of the issue in case it helps: