Jump to content

  • Log In with Google      Sign In   
  • Create Account

too_many_stars

Member Since 29 May 2013
Offline Last Active Yesterday, 09:19 PM

Topics I've Started

Bitmap Font Class Help

Yesterday, 08:53 PM

Hi Guys,

 

I am looking for some general help.

 

Here's the scenario.

 

We are given a bitmap font image file with equally spaced characters (ie the user knows the width and height of each cell) but in some random order with a uniform background color (which does not match any color of an image, font in this case).

 

We are able to iterate through a double for loop and access each cell, and get the pixel data.

 

Is there a way, to parse a cell, say for the letter "z" and store the ASCII integer value?

 

I am thinking this would be very difficult to pull of given the conditions above (ie random ordering with only pixel data) but I am just thinking what other more experienced programers do in these cases.

 

Of course, an easier solution is just to use a predictable ordering such as 16 x16 ASCII order.

 

Thanks,

 

Mike


Polygon outward facing normals

23 January 2015 - 11:28 AM

Hi guys,

 

A general question about building polygons in 2D.

 

Given a set of vertices which compose a polygon we know that the lines between the vertices can have two facing normals.

 

Algorithmically, for a random polygon, how does one ensure that all normals are facing outwards, that is, away from the center of mass (given a point mass system).

 

Thanks,

 

Mike


Contact Solver problem

20 January 2015 - 04:17 PM

Hi guys,

 

I am having some issues with a contact solver and I can't quite figure out what I am doing wrong in my physics simulation.

First, I will show you what works


/////////////////////
struct ContactInfo{
	Vec2 normal;
	float e;
	float pen;

};

/////////////////////

class Contact{
public:
	Contact(Rigid *b1, Rigid *b2, ContactInfo ci);

	void solveImpulse();
	void solvePenetration();
	float calcSepVel();
private:
	Rigid *b1;//holds two bodies
	Rigid *b2;
	ContactInfo ci;
};



/////////////////////

std::vector<Rigid*> bodies;


//missing lines
for(auto out=bodies.begin();out!=bodies.end();out++){
	for(auto in=out+1;in!=bodies.end();in++){
		ContactInfo ci;
		if(someCollision()){
			Contact contact((*out),(*in),ci);
 			contact.solveImpulse();
			 contact.solvePenetration();
		}
	}
			
}

Using the above algo, everything works fine

 

However, I need to solve each frame int the following manner

		std::vector<Rigid*> bodies;
                std::vector<Contact> contacts;
                //missing lines


                
                contacts.clear();
		for(auto out=bodies.begin();out!=bodies.end();out++){
			for(auto in=out+1;in!=bodies.end();in++){
				
				ContactInfo ci;
				if(someCollision())){
					
					
					
					contacts.push_back(Contact((*out),(*in),ci));
				}
			}
			
		}
		
		for(auto it=contacts.begin();it!=contacts.end();it++){
			it->solveImpulse();
		}
		for(auto it=contacts.begin();it!=contacts.end();it++){
			it->solvePenetration();
		}

Basically, I will be adding other collisions, such as cables, and I need to solve all contacts in one loop after all collisions from whatever physical source are added to the collision vector.

 

The second way is adding the contacts to the vector correctly, but it's not solving them accuretly. I have shapes falling through each other and only the first contact appears to be solved (temporarly).

 

If any one has any ideas what I am doing wrong please let me know.

 

Thanks,

 

Mike


Polymorphic pairwise collision testing implementation

19 December 2014 - 10:58 AM

Hi guys,

 

A quick question about the above title. Give a baseclass called "RigidBody" from which are dervied shapes such as circlces, AABB, OBB etc., I am currently implementing the following code. Please forgive any typos as I am unable to cut and paste right now.

std::vector<RigidBody*> bodies;
//missing lines of code

//pairwise collision handling
for(int i=0;i<bodies.size();i++){
    for(int j=i+1;j<bodies.size();j++){

        if(bodies[i]->type==CIRCLE && bodies[j]->type==CIRCLE){
             Circle *c1=dynamic_cast<Circle*>(bodies[i]);
             Circle *c2=dynamic_cast<Circle*>(bodies[j]);
             if(circleVsCircleCollision(c1,c2){
                 //do something
             }
         if(bodies[i]->type==AABB && bodies[j]->type==CIRCLE){
              AABB *b=dynamic_cast<AABB*>(bodies[i]);
              Circle *c=dynamic_cast<Circle*>(bodies[j]);
              if(circleVsAABBCollision(c,b){
                //do something
              }
         if(bodies[i]->type==CIRCLE && bodies[j]->type==BODY){
              AABB *b=dynamic_cast<AABB*>(bodies[j]);
              Circle *c=dynamic_cast<Circle*>(bodies[i]);
              if(circleVsAABBCollision(c,b){
               //do something
              }

        }


    }


}

As you can see, the above code is not very elegant, it's repetative, and can lead to errors. As I add more rigid bodies as well, it just blows up in size.

 

I am wondering if anyone has any ideas for a cleaner implementation

 

 


continous velocity aligned rotation problem

05 November 2014 - 12:31 AM

Hi Guys,

 

I am having some problems with my enemy class. The world is 2d, with enemy agents running around. I need every update step for the enemies to orient themselves to their normalized velocity vector called "heading".

 

here is the rotation algorithm

void rot(float angle){
		for(int i=0;i<points.size();i++){
			float x=((points[i].x-center.x)*cos(PI/180.0f*angle))-((center.y-points[i].y)*sin(PI/180.0f*angle))+center.x;
			float y=((points[i].y-center.y)*cos(PI/180.0f*angle))-((points[i].x-center.x)*sin(PI/180.0f*angle))+center.y;
			points[i].x=x;
			points[i].y=y;
		}
	}


Here is part of the enemy constructor

velocity.x*=speed;
velocity.y*=speed;
setHeading();
rotation=(float)atan2(heading.x,heading.y)*180.0f/PI+180;
rot(rotation);

the setHeading func

void setHeading(){
		heading=velocity;//heading and velocity are vectors with x,y components
		heading.normalize();
	}

and lastly, the enemy update

void update(double dt){
	
		for(int i=0;i<3;i++)//each enemy is a triangle
			points[i]+=velocity*dt/1000.0f;
		center+=velocity*dt/1000.0f;//center of the enemy
		
		setHeading();

		//NEED TO HANDLE AUTONOMOUS ROTATION HERE BASED ON NEW VELOCITY
                //currently the velocity is constant to keep the func simple to read

	}

Everything is set correctly in the constructor, with respect to the initial rotation, however, the issue is in the update method. Since the roation algo is a function of center, all vertecis, and angle, if it's constantly updated the object keeps spinning except for the case of 0 angle.

 

What i need is for the enemy update method to as smoothly as possible rotate the enemy if I apply impulses, forces etc to the object in the direction of the new normalized velocity, preferably polling each update step for the most accurate result.

 

Could someone please describe, and or show how I can implement a rotation algo which will in real time align the orientation of the enemy object with velocity?

 

Thanks,

 

Mike

 

 


PARTNERS