Imdsm's Profile
Reputation: 102
Stalwart
- Group:
- Contributors
- Active Posts:
- 358 (0.23 per day)
- Joined:
- 21-March 09
- Profile Views:
- 11,805
- Last Active:
Sep 19 2012 02:06 AM- Currently:
- Offline
Previous Fields
- Country:
- GB
- OS Preference:
- Windows
- Favorite Browser:
- Chrome
- Favorite Processor:
- Intel
- Favorite Gaming Platform:
- PC
- Your Car:
- Who Cares
- Dream Kudos:
- 175
Latest Visitors
-
CodingSup3rna... 
11 Feb 2013 - 10:52 -
macosxnerd101 
22 Nov 2012 - 17:35 -
darek9576 
23 Aug 2012 - 08:16 -
Guitartripp 
18 Aug 2012 - 04:50 -
olibenu 
04 Aug 2012 - 01:49
Posts I've Made
-
In Topic: C# - trying to find a smaller image inside a larger image, need HELP
Posted 27 Feb 2012
Your code is all mixed up and jumbled. You have .Width on Y's and .Height on X's, rows for y's and columns for x's. It's like spaghetti bolognese on my screen..
skybomb0, on 27 November 2010 - 11:29 PM, said:If I understand what you want correctly, this is what you need. It seems to me that your problem was in converting the image into a color array. For clarity, I used a multidimensional array in the shape of the image so it was easier to test to make sure I had the right pixels in the right spots. There also seemed to be a problem in the comparison loop where you forgot to add the starting position of the (0, 0) pixel. So if you thought the image started at pixel 30, you have to add on 30 to the index for pixels1. Here's what I came up with:
public Form1() { InitializeComponent(); } public int[,] isImageThere(Bitmap fullImage, Bitmap smallImage) { Color[,] fullPixels = ImageToArray(fullImage); Color[,] smallPixels = ImageToArray(smallImage); // Iterate through every row for (int fullRow = 0; fullRow < fullImage.Width; fullRow++) { // Iterate through every pixel in the row for (int fullColumn = 0; fullColumn < fullImage.Height; fullColumn++) { // If the current pixel on the full image is the // same as the top left pixel on the small image... if (fullPixels[fullColumn, fullRow] == smallPixels[0, 0]) { // So far, we haven't found a mismatched pixel bool badPixel = false; // Iterate through every row in the small image for (int smallRow = 0; smallRow < smallImage.Width; smallRow++) { // Iterate through every pixel in the row for (int smallColumn = 0; smallColumn < smallImage.Height; smallColumn++) { // If the pixel on the full image isn't the same as on the small image... if (fullPixels[fullColumn + smallColumn, fullRow + smallRow] != smallPixels[smallColumn, smallRow]) { // There is a mismatched pixel so set bad pixel to true badPixel = true; // Break out of inner loop break; } } // If we found a bad pixel, break out of outer loop if (badPixel == true) { break; } } // If we passed through all pixels in small image, return location if (badPixel == false) { int[,] res = new int[,] { { fullColumn, fullRow } }; return res; } } } } // If we looped until here, not match was found return null; } private Color[,] ImageToArray(Bitmap image) { // Create an array of colors the size of the image Color[,] colors = new Color[image.Width,image.Height]; // Iterate through every row for (int y = 0; y < image.Width; y++) { // Iterate through every pixel in the row for (int x = 0; x < image.Height; x++) { // Set color in array to color in image colors[x, y] = image.GetPixel(x, y); } } return colors; } private void button1_Click(object sender, EventArgs e) { int[,] message = isImageThere((Bitmap)pictureBox1.Image, (Bitmap)pictureBox2.Image); if (message != null) { MessageBox.Show("Found at: " + message[0,0] + "," + message[0,1]); } else { MessageBox.Show("Not found!"); } } -
In Topic: How do I move an object towards a vector destination?
Posted 29 Aug 2011
Excellent, thank you! -
In Topic: Directional velocity, not going in right direction, have images &
Posted 27 Aug 2011
Strangely enough when I recreate the calculations in a new, fresh project, it works correctly..

Time for me to get a coffee and find the obviously stupid bug which is hiding somewhere.
Thanks for the help
Edit: I can confirm the problem is with my "drag" code, I will try and fix this and let you know, for the sake of future forum readers
// introduce some drag to slow ship down // doesn't exist in space but for the sake of the game.. if (gameTime.TotalGameTime - previousDragTime > dragReductionTime) { previousDragTime = gameTime.TotalGameTime; if (Velocity.X > 0) Velocity = new Vector2(Velocity.X - DEFAULT_DRAG_REDUCTION_AMOUNT, Velocity.Y); else if (Velocity.X < 0) Velocity = new Vector2(Velocity.X + DEFAULT_DRAG_REDUCTION_AMOUNT, Velocity.Y); if (Velocity.Y > 0) Velocity = new Vector2(Velocity.X, Velocity.Y - DEFAULT_DRAG_REDUCTION_AMOUNT); else if (Velocity.Y < 0) Velocity = new Vector2(Velocity.X, Velocity.Y + DEFAULT_DRAG_REDUCTION_AMOUNT); }
Edit 2: Managed to fix it, the new drag code is:
float dt = (float)gameTime.ElapsedGameTime.TotalSeconds; Velocity = new Vector2( Velocity.X - (Velocity.X * DEFAULT_DRAG_FACTOR) * dt, Velocity.Y - (Velocity.Y * DEFAULT_DRAG_FACTOR) * dt);
where DEFAULT_DRAG_FACTOR in this case was 0.05f -
In Topic: Directional velocity, not going in right direction, have images &
Posted 27 Aug 2011
Thanks for the snippet but your maths code gives me the exact same results as my maths calculations:
Angle: 85 degrees, 1.48353 rads
(your) Direction: 0.9961947, -0.0871558
(mine) Direction: 0.9961947, -0.08715584
When on an odd angle, it doesn't actually fly in that direction, while it does give a nice flying effect, it's not actually going forwards. Any idea why?
Thanks
// Mine Matrix rotMatrix = Matrix.CreateRotationZ(MathHelper.ToRadians(Angle)); Direction = Vector2.Transform(Up, rotMatrix); // up is 0,-1 // Yours Direction2 = new Vector2( (float)(Math.Cos(MathHelper.ToRadians(Angle) - MathHelper.PiOver2)), (float)(Math.Sin(MathHelper.ToRadians(Angle) - MathHelper.PiOver2))); -
In Topic: Directional velocity, not going in right direction, have images &
Posted 26 Aug 2011
I wish I knew where the problem was so I could, my friend, but I'm not sure which part is going wrong, hence why I've linked to the file I'm working on. I will pick out a few bits though..
// adding velocity if (ks.IsKeyDown(Keys.W)) Velocity += Direction; if (ks.IsKeyDown(Keys.S)) Velocity -= Direction; // update the direction Matrix rotMatrix = Matrix.CreateRotationZ(MathHelper.ToRadians(Angle)); Direction = Vector2.Transform(Up, rotMatrix); // up is 0,-1 // add velocity position Position += Velocity;
The above snippets are the velocity having the direction added to it, below that, the direction being calculated and below that, the velocity being added to the position.
I am assuming part of this is what's causing the problem
P.S, it's not an online repository it's just a pastebin - I've been brought up not to spam pages and pages of code!
My Information
- Member Title:
- D.I.C Regular
- Age:
- 23 years old
- Birthday:
- September 13, 1989
- Gender:
-
- Location:
- Manchester, UK
- Interests:
- Programming, Photography, Engineering
- Years Programming:
- 10
- Programming Languages:
- ANSI C, PHP, C#, B, VB, VB.NET, ASP.NET, MySQL, T-SQL, XHTML, CSS
Contact Information
- E-mail:
- Click here to e-mail me
- Website URL:
-
http://imdsm.blogspot.com/
- Facebook:
- http://www.facebook.com/deanoez
- Twitter:
- http://twitter.com/Imdsm
|
|


Find Topics
Find Posts
View Reputation Given


|
Comments
Imdsm has no profile comments yet. Why not say hello?