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 25 Jan 2004
Offline Last Active Sep 30 2012 01:08 PM

Topics I've Started

Collision detection with Verlet integration

27 September 2012 - 01:25 PM

I recently read an article on Verlet integration (http://lol.zoy.org/b...motion-in-games) and wanted to apply it. It seems to work, but I'm not sure how to use it with my collision detection code. My update function looks something like this:

[source lang="cpp"]void State::Update(float dt){ Vector accel = Vector(...) //get accelreation based on user input Vector oldVel = vel; vel += (accel) * dt; pos += (oldVel + vel) * 0.5 * dt; if( if_collision_is_enabled ) { Vector newpos = CollideWithWorld(pos,vel); //get new position //update velocity & position based on the new position vel = newpos - pos; pos = newpos; }}[/source]

It seems to work, but the movement isnt as smooth as it is without collision. I assume I'm not updating the velocity and position correctly after the collision. Does anyone know a better way to do this?

Jpeglib texture loading issue

12 May 2012 - 05:25 PM

I'm trying to load jpg files using jpeglib, and found this example (http://www.efkhoury....ing-ijg-libjpeg)
I got it to work but the textures are being rendered incorrectly. I have to open them using mspaint, rotate them 180 degrees and flip them horizontally, in order for them to render correctly. I noticed the same thing happened when I tried to load png files. After searching google, I found out I have to swap the rows of the texture buffer before loading it in to opengl. However, I couldn't to find any code (or pseudo code) on it. If someone could tell me how to do this, it would be great.

This is the function I'm using to load the texture:
   	 unsigned char* LoadJPG(const string& filename, int& width,int& height, int& nChannel)
	   	 unsigned char * big_buff;
			struct jpeg_decompress_struct cinfo;
			struct my_error_mgr jerr;

			FILE * infile;		
			JSAMPARRAY buffer;	
			int row_stride;		

			if ((infile = fopen(filename.data(), "rb")) == NULL)
				return NULL;

			cinfo.err = jpeg_std_error(&jerr.pub);
			jerr.pub.error_exit = my_error_exit;

			if (setjmp(jerr.setjmp_buffer))
				return NULL;

			jpeg_stdio_src(&cinfo, infile);

			(void) jpeg_read_header(&cinfo, TRUE);
			(void) jpeg_start_decompress(&cinfo);
			row_stride = cinfo.output_width * cinfo.output_components;

			buffer = (*cinfo.mem->alloc_sarray) ((j_common_ptr) &cinfo, JPOOL_IMAGE, row_stride, 1);
			big_buff = (unsigned char*)malloc(cinfo.output_height * cinfo.output_width * cinfo.output_components);

			while (cinfo.output_scanline < cinfo.output_height)
				JDIMENSION read_now = jpeg_read_scanlines(&cinfo, buffer, 1);
				memcpy(&big_buff[(cinfo.output_scanline - read_now) * cinfo.output_width * cinfo.output_components], buffer[0], row_stride);

			width  =  cinfo.output_width;
			height = cinfo.output_height;
			nChannel = cinfo.num_components;

			(void) jpeg_finish_decompress(&cinfo);
			return big_buff;

player vs player collision

18 January 2010 - 11:57 AM

I've recently read the Improved Collision detection and Response article, and implemented player-vs-world collision system. I was wondering what is the best way to do play-vs-play collision? Since the "Collision Response" part of the algorithm only needs an intersectionPoint and intersectionDistance, I assume the only thing that needs to change is "Collision Detection" part. If one of the player is defined as a unit sphere(after being scaled by the Ellipsoid Vector Space) and the other player is an ellipsoid (assuming it doesn't have the same radii as the first player) what is the best way to determine if an intersection has occurred, and if so, find the intersection point?

Smooth skinning algorithm

28 April 2008 - 10:19 AM

I've read a few articles (and skimmed through a bunch of posts) about CPU skinning. I've tried to implement it for a while, but it just doesn't seems to work for me.

I know that the equation looks something like this,
v' = sum( Weight[i] * TransformMatrix[i] * ReferencePose[i]^-1 ) * v;
But when I try to implement this on a single point, it fails.

Below are 2 screen shots I took.

The first pic is a skeleton in its reference pose, with left arm rotated at -90 degrees in the z axis, and the right arm rotated in 90 degrees in the z axis.
and the blue point is a vertex of a mesh, its coords are (19.426800, 9.168850, 0.129585)

the second pic is the skeleton's right arm is in its default pose, where all its matrices are set to their identities.

since the blue point is at the edge, I assume its under the influence of just 1 bone. So I don't have to calculate the sum of the weights, I just calculate:

v'= TransformMatrix * ReferencePose^-1 * v

v = (19.426800, 9.168850, 0.129585)
TransformMatrix = Identity Matrix
ReferencePose^-1 = the inverse matrix of 90 degrees in the z axis

And when I compute the result, I get v'=(9.168850, -19.426800, 0.129585)
As you can see in the second pic, that is not where v' should be.

Any ideas on what I'm doing wrong?

Skeleton Animation reference pose

02 March 2008 - 02:10 PM

As far as I know, a models reference pose shouldn't affect the model's animation, as long as you store the inverse matrix of the reference pose during the binding process, and multiply it with the Bone's transformation matrix during the rendering process. When i searched the net and found the vertex transformation code looks something like, v = v` * M[i]^-1 * M[i] * w[i]
v = untransformed vertex
M[i] = transformation matrix
M[i]^-1 = inverse of M
w[i] = bone's weigth
i = number of bones influenced by v

In the reference pose, the model is spreading its arms, to form a 'T' shape. However, during the an animation, when I rotate the arm bones by 90 degrees in the z axis. The arm bones get transformed just fine, but the arm vertices are transformed down to the models knees. I'm not sure if its my code, or the reference pose that Im makimg a mistake with.