Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Discussion / Space Sim (DBC): Need advice on a scanner showing the damaged area of a ship

Author
Message
Hangar18
18
Years of Service
User Offline
Joined: 13th Mar 2007
Location:
Posted: 24th Aug 2007 05:29
I'm building a Space game and am at the stage of building a HUD. On the HUD I want to have 2 pictures, one of the players ship and one of a "target" ship on the HUD so that when either ship takes damage, segments of the picture of the ship progressively turn red.
One painful way of doing this is to create many BMP or PNG images of each ship model for each possible "damage" scenario but surely there's a better way. Can anyone assist me?
Lucy
18
Years of Service
User Offline
Joined: 19th Apr 2007
Location: Roanoke, VA USA
Posted: 24th Aug 2007 06:12
well, a nice easy way to do it would be to use the texturemax plugin and shift the hue of the texture from green to red.

Another way that would possibly be a lot easier is just to texture a quad with the texture in question using a black and white texture and change the quad's color.

Nothing I say is intended to be rude. My autism means that I do not know what is rude and what isn't rude. I apologize if I seem rude. It is not my intention.
Sinani201
18
Years of Service
User Offline
Joined: 16th Apr 2007
Location: Aperture Science Enrichment Center
Posted: 24th Aug 2007 06:20
You can use the SET GAMMA command to give colored lighting to an image. You could give the image more red lighting each time the ship gets damaged.

Did someone say 3D scanning on my desk, or was that just an AdBot?
What happens when when you mix coke, pop rocks, vinegar, and baking soda?
Latch
18
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 24th Aug 2007 08:01
A pretty cheap way would be to have a red X or a circle with a line through it, or a red box outline with what looks like a compter readout image that you just paste over the damaged areas. You'd only need one image of that and no computation to paste it (besides position). You see the ship through it with the damage indicator on top.

Or create a box with alternate pixels between red and black. If you paste it with transparency it will be sort of like a red screen.

Enjoy your day.
Libervurto
18
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 24th Aug 2007 15:01
You could make images of the outer segments that are independent and then when damaged substitute that segment for a more damaged one.

Your signature has been erased by a mod because it was rubbish.
Hangar18
18
Years of Service
User Offline
Joined: 13th Mar 2007
Location:
Posted: 27th Aug 2007 02:26
Thanks guys, some good ideas here. Just a couple of questions:

1. I experimented with the set gamma command but it seemed to add lighting "everywhere", not just to a specified image. Is there a way to contain the gamma lighting effect to an image -i.e. so that if I paste another image next to the one I want lit up that it wont have any lighting if that makes sense?

2. Because I have 50 ship models I dont want to (unless I have to) go through each of them to manually add in "damage" effects to the BMP textures. Instead I want to create a function that looks within the range of the image and checks for the pixel colour at a point. If its black then keep going until it finds a non-black point. Then paste a damage effect at that point. Is there a command that checks the pixel colour?

Cheers.
Latch
18
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 27th Aug 2007 04:56
Quote: "Instead I want to create a function that looks within the range of the image and checks for the pixel colour at a point"


The POINT command does that directly with images on screen - but it is WAAAYYYYY too slow to use effectively unless you have tiny images. You can try it out though, it may fit your needs. A DLL for that purpose would be much better - but pixel by pixel comparisons are always relatively slow.

If you don't want to create the extra individual images for the damaged parts, then create an array that stores the pixel locations of the outline of the various damagend areas of the ships. If your radar displays are images already, then run a routine that captures those outlines (check for non black areas that are surrounded by black areas) into an array before the game even begins. From the array, you could redraw any outline in what ever color you want (remember it stores only the pixel positions of the outlines of possible damaged parts - not the fill in between or the black - for speed) pretty quickly without having to paint it by hand. You can store these outlines as images so they never have to be redrawn, or you could draw them on the fly which would take a little processing power from play.

Enjoy your day.
Hangar18
18
Years of Service
User Offline
Joined: 13th Mar 2007
Location:
Posted: 27th Aug 2007 06:41
Thanks Latch! I dont have much experience with modifying images and then storing them within DB itself so using the example below how could I get the "damaged" image restored as say image 2 with the red pixel point so I dont neeed to keep redrawing the pixel point - e.g.

Load image "ShipA.BMP",1
Make Object plain 1,10,10
Texture object 1,1
Position Object 1,-5,-5,0: Rem Ship Image at Bottom left of hud

Do
Rem pretend this sub returns X# and Y# coords for damaged area
If LaserHit=1 then Gosub GetDamageCoords
ink rgb (255,0,0),0
dot X#,Y#

Loop

But what I want to do is find the code for the bits in the " " - i.e ....

Do
If LaserHit=1 then Gosub GetDamageCoords
"DRAW red dot of damage to image 1"
"Save as image 2 or even overwrite image 1 as image 1 is stored elsewhere that I can recall if needed"
"paste image 2 to object 1 so that the damage shows up from now on" - this bit is easy - just texture object 1,2

Loop
Latch
18
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 27th Aug 2007 10:24 Edited at: 27th Aug 2007 21:56
Quote: "Thanks Latch!"

Don't thank me yet, it's not as easy to do as it is for me to suggest! Before trying that idea see the next one.

For what I was thinking, you would have to have your ship divided into areas that could show damage, unless your intention was that it could be damaged anywhere. Actually, the damaged "anywhere" might be easier to handle. Here's psuedo code of a damage anywhere scenario - it assumes you are using DBC enhanced:



And if you want the damage extended beyond a single pixel per hit, you'd have to return an area of x and y coordinates that encompases several pixels (for x= 1 to 5, for y = 10 to 15 or something like that) and each of those pixels have to be changed in the memblock.

Enjoy your day.
Dark Dragon
17
Years of Service
User Offline
Joined: 22nd Jun 2007
Location: In the ring, Kickin\' *donkeybutt*.
Posted: 27th Aug 2007 21:33 Edited at: 27th Aug 2007 21:36
that sounds like mechwarrior 2(netmech)?!?!?
instead of makeing all those images....
i'd load an object(player,eneimy,etc.) and color the limbs that are damaged red. of course, you can lock the object to the screen and at the bottom so it looks like the hud...but put a plain behind it and scale it down
Hangar18
18
Years of Service
User Offline
Joined: 13th Mar 2007
Location:
Posted: 28th Aug 2007 02:38
@Latch: Thanks! That helps I'm sure - I will try experimenting with memblock and dword (not really used these before but trial and error will hopefully get me there).

@Dark Dragon: Thanks, I had already thought of that but want to avoid using 3D objects as this will slow down the performance as my ships are fairly high in poly counts. I could use lower poly counts I guess, but thats alot of extra work.
Dark Dragon
17
Years of Service
User Offline
Joined: 22nd Jun 2007
Location: In the ring, Kickin\' *donkeybutt*.
Posted: 28th Aug 2007 16:55
i know make a program to veiw your models and to color their limbs. then, you can take snapshots and greatly reduse the time needed to get all those images.
TDK
Retired Moderator
22
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 28th Aug 2007 18:40 Edited at: 28th Aug 2007 18:44
Not sure if Latch was suggesting the same thing, but I would go with using an array too:

Dim ShipDamage(100,4,3)

This allows for up to 100 enemy ships - and your ship could be 0.

Get your ship image (found this one on the net):



Then divide it into sections - saving each one as a separate image.

Next, colour each of the sections red and save those too.

This was done rough and quick, but it should give you the idea...



Note that in the above Dim, the 4,3 corresponds to the size of the grid (0 to 4 across and 0 to 3 down).

When an enemy ship gets hit, you decide what section was hit and use something like:

ShipDamage(ShipNum,SectionX,SectionY)=1

Note you can use 0=No Damage and 1=Damaged or inc the value until a certain value has been reached.

On your hud, if you target ship 20, you use a loop to run through the grid array placing an uncoloured section on the hud if it's zero and a red section if it's 1.



This gives you something like:



[Edit] Just had a thought - might look better if the undamaged ship was green. You could also have the sections unjointed too for effect...

TDK_Man

Libervurto
18
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 28th Aug 2007 19:34
@TDK
That was what I was trying to say
Quote: "and your ship could be 0."

I don't like using 0 as there may be times when you need the 0 to be "no ships".

Your signature has been erased by a mod because it was rubbish.
Hangar18
18
Years of Service
User Offline
Joined: 13th Mar 2007
Location:
Posted: 29th Aug 2007 02:58
Thanks guys, the "image slicer" method is my last resort (but I can see it will work which is the main thing!) - I just wanted to see if a shortcut was possible to avoid going through all 50 ships images (which will mean 1000 images once sliced). Particularly so, given I want to gradually increase the colour from say green to yellow to red rather than going straight to red (this will further increase the number of sliced images to something like 5,000!!).
Libervurto
18
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 29th Aug 2007 03:22 Edited at: 29th Aug 2007 03:23
You don't need to do all that hangar, if you store the image as a memblock you can redraw the images using the appropriate colours from the data within. Green to yellow then red is fairly simple, I will post some code tomorrow for that one

PS, not sure if it would work but have you tried changing the gamma values and capturing the image?

Your signature has been erased by a mod because it was rubbish.
Latch
18
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 29th Aug 2007 06:39
@Hangar

The way TDK described it was what I was originally thinking. Ultimately, it would be very fast because you only have to reference indexed images - but you'd have to do all the legwork ahead of time making the individual slices. The slices could be done programatically if you know the relative size of each section to the size of the ship and they are consistant between ships. Each section's x and y boundaries could be calculated using a ratio.

The other method I proposed using the memblock, is a pretty fast method, and if your images for the hud aren't too big, it shouldn't be too much of a hit. When I wrote the psuedo code, I created the actual code also in case you were having trouble. I've included an attachment that has the image and the code.

The program will display two spaceships. The one on the left is the actual healthy image. The one on the right is the image created by the memblock. The values under the original image were there for me to monitor that my pixel formula was correct so I didn't exceed the size of the memblock and cause a crash.

A random x and y coordinate are returned that indicates where the image has been hit. A loop is run that expands the damged area 50x50 pixels. I only used one color, red, and I used a BITWISE AND - & - of red and the current pixel color. This emphasizes any red in the pixel and will still draw the shape of the image but as if it is gamma influenced with red. This is called a color mask. I didn't do the stages of green to yellow to red, and I only did a block of damage at a time.

You can change the algorithm to create a different pattern or area of damage.

The example is based on using a 32 bit screen depth. This is easy to use because the pixel colors are stored in 3 bytes with the forth being 0 (a nice neat DWORD). Using the bitwise &, the color to change to should be a full mask (all the bits for the color are set to 1). Good colors for the masks are:
Red = rgb(255,0,0)
Green = rgb(0,255,0)
Blue = rgb(0,0,255)
yellow = rgb(255,255,0)
Purple = rgb(255,0,255)
Cyan = rgb(0,255,255)

32/24 bit is easy, 16 bit is a little tougher. The masks are not the same and they will be based on your video card. Take a look at the attachment and let me know if you have any questions.

Enjoy your day.

Attachments

Login to view attachments
Hangar18
18
Years of Service
User Offline
Joined: 13th Mar 2007
Location:
Posted: 30th Aug 2007 05:55
@Latch: THis is excellent - exactly the effect i was after. THank you so much for doing this. Very very happy

Login to post a reply

Server time is: 2025-06-02 06:39:18
Your offset time is: 2025-06-02 06:39:18