Question about GDI and collission detection.

  • Thread starter Thread starter Flare
  • Start date Start date
F

Flare

Hi. I know ms.public.dotnet.framwork.drawing was a better choice for this
qustion, but noone in there ssems to have an answere, so here we go.

Im trying to make a little tank game in C#. Everything is working out great.
Now i
need to check if my tank is colliding with an obstacle (a collection of
Rectangles).

Now when i paint my tank i use transformations like this:

....onPaint(...)
grfx.TranslateTransform(Placement.X,Placement.Y);
grfx.RotateTransform(Direction);
// This is my Tank(!);
grfx.FillRectangle(Brushes.GreenYellow, -15f, -30f, 32, 60);
grfx.RotateTransform(-Direction);
grfx.ResetTransform();

As you see it can rotate as it moves. But when I calculate the now possition
for the tank i also want to check if the tank is Intersecting with one of my
Obstacles (an arrayList with Rectangles).

But HOW do i create an Reactangle object wich is simular to the
FillRectangle is draw in my PainEvent so I can compare it to my reactangles
in the Arraylist of obstacles?

Im stuck and hope for at good advice.

(How is collission nomally done...i mean things gets more complicate as i
see when things aint Rectangles anymore?)

Reagards
Anders J, Denmark
 
This is not a GDI issue at all.

Come up with your own solution - make your own objects, make your own check
algos. 3d programmers do this all the time.

--
Regards

Thomas Tomiczek
THONA Software & Consulting Ltd.
(Microsoft MVP C#/.NET)
(CTO PowerNodes Ltd.)
 
This is not a GDI issue at all.

I know. Im not blaming GDI for my problems.
Come up with your own solution - make your own objects, make your own check
algos. 3d programmers do this all the time.

I havent done much 3d programming. sorry. but i do have all my graphics
object as....objects...but when i transform them with GDI I loose
information on where they are. Eg. Transform.Rotate(45);

Know my graphics object is drawn rotatet 45 degree. But my graphics obejct
dosent know about this transformation and i cant transfer this rotation info
into my object.

But obviously I miss some basic undestanding of graphic programming...:(

Regards
Anders
 
No, you do not.

Your problem is that you try to make the collision detection with the
graphics object.

You should do so with a separate data structure.

--
Regards

Thomas Tomiczek
THONA Software & Consulting Ltd.
(Microsoft MVP C#/.NET)
(CTO PowerNodes Ltd.)
 
You should do so with a separate data structure.

Ill try redesign my code with that in mind. Thank you for you time :)

Anders
 
Back
Top