| Topic: Small Performance hint
|
|
 | Small Performance hint | |  |
| Poster | : default0 | | Posts | : 1 | | Country | : Frankreich | | City | : Paris |
| | | | Posted by default0 on 12/03/2010 at 11:09:10
| | Hi Guys,
if you have the same problem like me, this is, that the method is quite slow, I have a small hint for you.
Change the TexturesCollide method to the following:
private Vector2 TexturesCollide(Color[,] tex1, Matrix mat1, Color[,] tex2, Matrix mat2)
{
Matrix mat1to2 = mat1 * Matrix.Invert(mat2);
int width1 = tex1.GetLength(0);
int height1 = tex1.GetLength(1);
int width2 = tex2.GetLength(0);
int height2 = tex2.GetLength(1);
Vector2 vec = new Vector2(0, 0);
for (int x1 = 0; x1 < width1; x1 += 2)
{
for (int y1 = 0; y1 < height1; y1 += 2)
{
vec.X = x1;
vec.Y = y1;
Vector2 pos2 = Vector2.Transform(vec, mat1to2);
float x2 = pos2.X;
float y2 = pos2.Y;
if ((x2 >= 0) && (x2 < width2))
{
if ((y2 >= 0) && (y2 < height2))
{
if (tex1[x1, y1].A > 0)
{
if (tex2[(int)x2, (int)y2].A > 0)
{
Vector2 screenPos = Vector2.Transform(vec, mat1);
return screenPos;
}
}
}
}
}
}
return new Vector2(-1, -1);
} |
This reduces accuracy, as it only checks 1/4th of the pixels, but depending on what you're doing, this might be the better solution.
Feel free to replace x1 += 2 with x1 += 3 or even greater for more performance, but you should be aware, that the more you increase x1 or y1 per loop, the less accurate the detection becomes!
Best regards | |
|
| | | | | | Poster | : Anonymous | | Posts | : | | Country | : | | City | : |
| | | | Posted by Anonymous on 27/07/2012 at 11:49:38
| | | Imagine an ipod. You're lying on your bed after an relaxing long day, litnesing to your favorite music beats that you downloaded off the Internet. The high quality expensive earphones are loud in your ears. Suddenly, you hear a pop. Both your eardrums pop causing you to bleed all over your earphones that cost you thousands of dollars. Imagine at school. You're sitting in one of those long and boring classes as usual. The teachers standing there are speaking gibberish, causing half of the class to fall asleep. He assigned you an assignment that is due in the end of the class. You're sitting there thinking this is the first time he gave out an assignment and thought this must be boring. Hopefully, you think someone will give you the answers to all the questions in the last minute of class. You turned on your new, latest and most expensive ipod you just brought with all your savings. Both of your ears are plugged in that you could not hear the teacher screaming and barking at you. The teacher got mad then came over and took the ipod away, saying that he will give it back the next day. The next day, the ipod was missing from the teacher's desk. Imagine walking on the streets. The roads are busy and the sun is bright. Drivers in the car are half asleep. Hundreds of people are walking across the street but no one have earphones plugged in their ears. You are the only one litnesing to your ipod and dancing to the music while crossing the road at the same time. Suddenly, people are running as fast as they could to the other side of the road. You turned around and boom. You woke up in the emergency room with the earphones still in your ears.Imagine taking modern transports. What do you think is the most entertaining item you can bring on a long and boring trip? Of course, the latest ipod available. These things can play music, videos , pictures and games that can be downloaded for free on the Internet. If you are a person that gets bored easily or any average person the ipod will entertain you for the whole trip.Although the ipod or any other mp3 players can be entertaining but they can be deadly too be sure to choose wisely. I do wonder what is the whole message you are trying to convey in your material it sound contrasting but the end seems lacking something that appropriates a closing. Try to think of better way to end your material. i felt the rhythm went out on the ending. | |
|
|
 | | |  |
|
|
|
If you appreciate the amount of time I spend creating and updating these pages, feel free to donate -- any amount is welcome !
|
- Website design & DirectX code : Riemer Grootjans - ©2006 Riemer Grootjans
|
|