Jump to content

  • Log In with Google      Sign In   
  • Create Account

Awesome job so far everyone! Please give us your feedback on how our article efforts are going. We still need more finished articles for our May contest theme: Remake the Classics

FireViper

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))
			{
				jpeg_destroy_decompress(&cinfo);
				fclose(infile);
				return NULL;
			}

			jpeg_create_decompress(&cinfo);
			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);
			jpeg_destroy_decompress(&cinfo);
			fclose(infile);
			return big_buff;
	 	 }

PARTNERS