Forum
Contact





DirectX using C#
DirectX using C++
DirectX using Visual Basic



Latest Forum posts

 Tutorial 3 for Windows Phone 7
  Posted by: Anonymous
  When: 20/05/2013 at 02:30:13

 No download link for 2d series: shooter
  Posted by: zaboleq
  When: 07/05/2013 at 15:46:28

 Collision Class?
  Posted by: Anonymous
  When: 05/05/2013 at 19:03:59

 stack overflow
  Posted by: cityguy
  When: 07/04/2013 at 01:58:38

 Meshes looks strange.
  Posted by: ab_saratov
  When: 01/04/2013 at 04:31:08

 Lamppost Not loaded
  Posted by: Anonymous
  When: 22/03/2013 at 06:43:52

 Collision Class?
  Posted by: Da_Boom
  When: 21/03/2013 at 01:23:09

 Math boggles me
  Posted by: cityguy
  When: 17/03/2013 at 03:44:48

 Collision Class?
  Posted by: Da_Boom
  When: 16/03/2013 at 03:44:42

 Tree update
  Posted by: Anonymous
  When: 15/03/2013 at 21:11:22

 XNA 4.0
  Posted by: Anonymous
  When: 15/03/2013 at 19:43:57

 Error when I try to run.
  Posted by: Anonymous
  When: 15/03/2013 at 19:21:06

 Error With the Effect File
  Posted by: Anonymous
  When: 15/03/2013 at 18:21:01

 Can only get shadowmap
  Posted by: Anonymous
  When: 15/03/2013 at 15:48:52

 Vertex and Pixel Shader Versions?
  Posted by: Anonymous
  When: 15/03/2013 at 15:07:16

 Unsupported properties
  Posted by: Anonymous
  When: 15/03/2013 at 14:23:00

 Problem Loading Skybox
  Posted by: Rana
  When: 15/03/2013 at 10:34:45

 Black Screen Of Death - Help!
  Posted by: Anonymous
  When: 15/03/2013 at 03:43:43

 2.0 anyone?
  Posted by: Anonymous
  When: 15/03/2013 at 02:19:48

 Defitinition of tha rotation axis
  Posted by: Anonymous
  When: 15/03/2013 at 00:55:14




Topic: Small Performance hint



  
Goto parent category
  
Create a new user account


   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.

  
Post a new reply
 





Google
 
Web www.riemers.net
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


News
Home
Forum
XNA 2.0 Recipes Book (8)
XNA 3.0 Recipes Book (8)
Downloads
Extra Reading (3)
Matrices: geometrical
Matrix Mathematics
Homogenous matrices
Community Projects (1)
Tutorials (160)
XNA 4.0 using C# (89)
DirectX using C# (54)
Series 1:Terrain (14)
Opening a window
Linking to the Device
Drawing a triangle
Camera
Rotation - Translation
Indices
Terrain creation
Terrain from file
DirectInput
Importing bmp files
Colored vertices
DirectX Light basics
Mesh creation
Mesh lighting
Series 2: Flightsim (19)
Series 3: HLSL (19)
Short Tuts (2)
Resizing problem
Checking Device caps
DirectX using C++ (15)
DirectX using VB (2)