|
Just want to make sure i understand what you are saying
Lets say we have rectangle with dimensions X1,Y1
and circle with Centre point x,y.
i have the values of all Xs and Ys
So checking if the circle is inside the possible collision region
1/2(width + radius), 1/2(height + radius)
if its outside
radius*radius>| circle center - corner|^2. Im sorry i dont understand can you please clarify.
For example you can explain it by something more or less like this, for rectangle with coordinate (x1, y1, w, h) and circle(x2,y2,r)
if (x1 > x2 + r || x1 + 30 < x2 || y1 > y2 + r || y1 + 30 < y2)
it could be more clearer if you can put explain it this way
Thanks
|
|
|
|
|
If your rectangle is already axis-oriented you don't have to rotate, so the transformation is trivial: the circle's centre in rectangle space is (x2-(x1+½w), y2-(y1+½h)). Call this [x' y'].
Now check if the circle is possibly colliding:
if(!(x' in range [-(r + ½w), r + ½w]) || (y' in range [-(r + ½h), r + ½h])) no collision;
That accounts for the 99% case where there is definitely no collision, and you can avoid any further processing.
Then check the easy cases:
if((x' in range [-½w, ½w]) || (y' in range [-½h, h])) collision;
Finally check distance to corners. The closest corner is the closest independently along the two axes:
var dx1 = x' - ½w, dx2 = x' + ½w, dy1 = y' - ½h, dy2 = y' + ½h;
var dx_closest = min(dx1, dx2), dy_closest = min(dy1, dy2);
if(r² > (dx² + dy²)) collision;
|vector| is the vector magnitude function, i.e. distance; in a standard 2D system this is the Pythagorean distance as expanded above.
If you care about the collision vector, in the easy case it is [1, 0], [-1, 0], [0, 1] or [0, -1] depending on which side you intersected with, and in the closest-corner case it is along [dx_closest, dy_closest].
|
|
|
|
|
hi, here is how i tried putting all this in code. and i got the error
{"Object reference not set to an instance of an object."}
Im sure that has something to do with my code here it is
public class Ball
{
Player square;
public float x, y, yvel, radius;
public Brush brush;
public Ball(int gameWidth,int gameHeight,Random r)
{
x = r.Next(gameWidth);
y = r.Next(gameHeight);
yvel = r.Next(2) + 2;
radius = r.Next(10) + 5;
brush = new SolidBrush(Color.Blue);
}
public void Move(int gameHeight)
{
if (y + radius >= gameHeight - 315)
{
y = 0;
}
y += yvel;
if ((y + radius) > gameHeight - 315 && collision(square))
{
MessageBox.Show("Collision");
}
}
public void Draw(Graphics g)
{
g.FillEllipse(brush, new RectangleF(x-radius,y - radius, radius * 2, radius * 2));
}
public bool collision(Player player)
{
float X = (x - (player.x + 15));
float Y = y - (player.y + 15);
return (!(-(radius + 15) < X || X < (radius + 15) || -(radius + 15) < Y || Y < (radius + 15)));
}
}
|
|
|
|
|
This exception is usually easy to track down. You passed a null to something, and you can tell what from the line it's thrown on. Have a look at that line, see what object you're trying to call methods on and then see why you passed a null.
(clue: you never assign Player)
|
|
|
|
|
I am trying to do a program about imageprocessing. I want to firstly object tracking I use meanshift algorithm but I take video frames on disk, I have to fast so How can I get video(only Y from YUV) from usb cam buffer?
|
|
|
|
|
Hi,
I have class library in my project and i wanna to encrypt it so when i build my project if any one use tools to open my project source(like resource hacker) can't see the class.
|
|
|
|
|
Google for "obfuscator".
Binding 100,000 items to a list box can be just silly regardless of what pattern you are following. Jeremy Likness
|
|
|
|
|
As Richard says, Obfuscation is the way to go - but do not expect it to be foolproof. Remember that the processor has to be able to read your code in order to execute it, so a competent and determined programmer can too!
Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water
|
|
|
|
|
You can use Assembly.Load(byte[]) to load a binary image. Thus one can load an encrypted file, decrypt it, then load it as an assembly.
|
|
|
|
|
This is the road I've gone down. (I encrypt by the licence information file, so if you change that, the program won't run.) But once someone gets a running version, they can decompile the shell, make it dump the working inner assembly to disk and look at it, or link to the shell assembly and grab the inner one while it's running.
|
|
|
|
|
|
No. Don't even go down that road. If you really want to protect your code, hide it behind a webservice (and even then the server is going to get hacked someday and someone will have your code). Otherwise the code has to be decryptable by the user - how else is he going to run it? You can put a nice big lock on a door, if you put the key under the mat it's still useless. Until processors implement public key encryption (and I hope to god they never will), there is nothing you can do.
You can obfuscate the code, but remember that it won't stop anyone but a bored teenager in his moms basement. And maybe not even him.
|
|
|
|
|
I am trying to draw two paraller curves side by side.
Width of both curves should be increased or decreased. Also the sweep angle is variable and can be increased or decreased. What is the best possible way to do this using C#?
I am actually writing this for Paint.Net but for support I am writing this code first in visual Studio using C#.
|
|
|
|
|
|
Hi, Thank you for your reply. I have done the same and acheived the basic result but the problem is when I increase the width of the Pen then it increase on both sides and thus overlap the second Arc. I have also tried to change the Arc position when the pen width increases but it not remains the same and looses symmetry when i give the higher pen width.
|
|
|
|
|
And you are sure you have offset the Rect properly to compensate?
"You get that on the big jobs."
|
|
|
|
|
Hi everyone.
I have drawn a square on the screen/form using GDI. Now I want to move this object around using keyboard inputs. I just want it to move along the x-axis using left and right arrow keys. I can assign the keys but the problem is making that object move. You help on this is highly appreciated.
|
|
|
|
|
How you move it is going to depend to a large extent on how you drew it / are drawing it.
The basics are pretty obvious though: two integers, one for X and one for Y. Up key decreases Y value, Down increases it. Left key decreases X, right increases.
But there are three common ways to draw a rectangle:
1) On a panel or similar control. In this case, use the new X and Y values on the Panel.Location to move it.
2) On the form via the Paint event: In your Paint handler, use the X and Y to set the top left position of the rectangle. When you modify X or Y, use the Form.Invalidate method to force a re-draw.
3) On the form via getting a graphics context for the form and using Graphics.DrawReactangle. In this case, don't. Use method 2 instead. Trust me on this!
If you have used another method, tell us what it is!
Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water
|
|
|
|
|
OriginalGriff wrote: Trust me on this!
Only a fool would not.
Binding 100,000 items to a list box can be just silly regardless of what pattern you are following. Jeremy Likness
|
|
|
|
|
|
OriginalGriff wrote: the nicest thing anyone said to me all day!
It's only 11 o'clock.
Binding 100,000 items to a list box can be just silly regardless of what pattern you are following. Jeremy Likness
|
|
|
|
|
Thank you.
I got it just after sending this message. I used the option 2.
|
|
|
|
|
Capture the information about the new coordinates based on key presses, then in your OnPaint() method you redraw the object at the new coordinates. Something like:
OnKeyPress(int key)
{
if (key == LEFT)
pointx -= 1;
if (key == RIGHT)
pointx += 1;
}
OnPaint()
{
DrawSquare(pointx, pointy);
}
Binding 100,000 items to a list box can be just silly regardless of what pattern you are following. Jeremy Likness
|
|
|
|
|
Thank you.
|
|
|
|
|