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 / Target Box around Ship

Author
Message
BN2 Productions
20
Years of Service
User Offline
Joined: 22nd Jan 2004
Location:
Posted: 13th Sep 2010 05:45
So the aspect of my current project involves flying and fighting in space dogfights (yes, it is a huge project that involves pretty much everything I have asked about on the forums all summer). I want some way to identify enemy ships visually, rather than having to identify them visually.

Ideally, I would like the program to draw a box (either with a textured plain or with sprites) around them. My problem is that some enemies will be very large while others will be small and I cannot figure out a way to draw the box around the objects visible bounds. Since there is no "Object Screen Size X" command, I cannot see how wide the object is, nor can I see how tall it is on screen.

Any ideas here? Does it at least make sense (it's been a long day I'm confusing myself as it is)?

Great Quote:
"Time...LINE??? Time isn't made out of lines...it is made out of circles. That is why clocks are round!" -Caboose
Dia
19
Years of Service
User Offline
Joined: 16th Jan 2005
Location:
Posted: 13th Sep 2010 15:47 Edited at: 13th Sep 2010 17:25
the problem with spaceships is that picking the aspect is important if you want to get accurate bounding boxes. I try to ignore the aspect and just go off the max diagonal size. this only works unless your space ships are long and thin

Give this a bash and see if it is close to what you are after. It is a cut down version of a system I was trying to use a little while back



hope that is the kind of thing you are after.

p.s. I left a bunch of useless code in there commented out - just ignore it

*edit* just had a thought. Dunno if all of this will work in DBC, I was in DBPro when i did that, but I *think* it is adaptable

This is not the Sig you are looking for....
Latch
17
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 13th Sep 2010 18:45
@BN2

Or perhaps, at the extremes of the spaceship (max and min x,y,z) , place an invisible plane object. Get the screen x and y of the plane object(s) - find the 2 max and 2 min of the screen xs and ys, and draw a box by connecting those.

If you record the extremes ahead of time based on the center of the object and store them in an array, then plotting the 3d coordinates is only a matter of offsetting the extreme positions based on the position of the spaceship.

You can use a single plane and just reposition it for all of the points and all of the spaceships in the check.

Enjoy your day.
BN2 Productions
20
Years of Service
User Offline
Joined: 22nd Jan 2004
Location:
Posted: 13th Sep 2010 20:22
Well, very glad I got some responses here. After I posted I went into a calculus frenzy. I actually almost pulled it off but was stuck when it came how to find the real world coordinates of a point on a 3d plane that's at any given orientation (it was one of those "I know it and it seems easy but I just can't figure it out" moments).

Will give those a try later today.

Great Quote:
"Time...LINE??? Time isn't made out of lines...it is made out of circles. That is why clocks are round!" -Caboose
BN2 Productions
20
Years of Service
User Offline
Joined: 22nd Jan 2004
Location:
Posted: 14th Sep 2010 04:33
Sorry for double post, but I got it to work, and thanks for the suggestions.

Ultimately, I ended up using a mixture of both of yours and it works pretty well.

The solution:

This part was done within a 3d modeling program but with some work (which I am debating doing) it can be done completely in DBC). I just didn't want to lose the frames (figure once its all done I will be fighting enough for them).

Place an incredibly small object (I did a plane with dimensions .1,.1) at each of the 8 corners of a box around the object (top front left, top front right, bottom front left, bottom front right, etc etc). Name each one PlaneXX where XX is the number (and completely useless for all lintents and purposes, the important part is making sure all of the corners are named the same but with a name not used by any other limb).

In DBC

Scan through all limbs in the object. If its name begins with "plane" then position a temporary plane (again, I used a .1x.1 plane) at the limbs coordinates and record the screen locations in an array.

Once all 8 have been recorded, go through each for 4 pieces of data: The top most, left most, right most, and bottom most screen coordinates. Record these in variables.

Draw lines based on the Top,Left,Right, and Bottom variables.

Here's the function, I apologize in advance for the uncommentednes. I will revise it and put in comments tomorrow (out of time for today).



Great Quote:
"Time...LINE??? Time isn't made out of lines...it is made out of circles. That is why clocks are round!" -Caboose
Latch
17
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 14th Sep 2010 05:16
Nice! and clever too!

With those points as limbs, you'll be able to rotate the box without any trig!

You might be able to speed the function up a bit if you build the ship(s) with those "marker" limbs as the same limb numbers every time. That way you wouldn't have to use the checklist commands and could query the limbs' positions directly.

Also, if this is in DBC, another speed up would be to draw your lines using the BOX command instead of the line command. As long as the lines are drawn left to right and/or top to bottom.


would be faster as



Enjoy your day.
29 games
18
Years of Service
User Offline
Joined: 23rd Nov 2005
Location: not entirely sure
Posted: 14th Sep 2010 23:38
Ah, I seem to have turned up late. Never mind

I was having a read of this last night and it looked like a really interesting problem and I started to have a think about it.

I was going along the same lines as you've used but instead of using limbs I thought about getting the vertex position, placing a "marker" object at the vertex and then using this to get the screen x and y coordinates.





I don't know if this is quicker then what you're doing (I'm getting about 30 to 40 fps but that's caused by the drawing of the lines) but it does save on the modelling work

I also discovered that you can still get the screen x and y coordinates when the object itself is invisible.


Anyway, glad you found a solution.
BN2 Productions
20
Years of Service
User Offline
Joined: 22nd Jan 2004
Location:
Posted: 15th Sep 2010 09:28
In all honesty, I am writing this in DBPro for simplicity in using Sparky's (the DBC version isn't as user friendly) but I want to make it all compilable in DBC.

I thought of the vertex stuff but DBPro seems to format its information in the memblock about the mesh differently and I got a bit confused by it.

Great Quote:
"Time...LINE??? Time isn't made out of lines...it is made out of circles. That is why clocks are round!" -Caboose
Dia
19
Years of Service
User Offline
Joined: 16th Jan 2005
Location:
Posted: 15th Sep 2010 15:55
hrmmm interesting take on it.

I tried a variation on that just using null objects as limbs rather than very small plane objects in my 3d modeller. It works pretty darn well so thanks for the idea!

@29 Games - yeah the 2d line command is pretty much bollocks, i only used it for testing purposes, so there wasn't any media to download in the example. In the real project I use textured plains to draw my target/select boxes (see the newsletter tutorial on HUD implementation, it is DBPro but still perfect for this purpose), which is heaps quicker

This is not the Sig you are looking for....
29 games
18
Years of Service
User Offline
Joined: 23rd Nov 2005
Location: not entirely sure
Posted: 15th Sep 2010 22:02
I tried to use a plane but couldn't orientate properly and I didn' fancy thrashing through the trig.

I followed Latch's suggestion of using the 2D box command rather than the 2D line command and I got 60 fps. Yay!



Incidentally, bollocks is one of my favourite words. I can't tell you what my absolute favourite word is. I'd rather this thread didn't get locked!
29 games
18
Years of Service
User Offline
Joined: 23rd Nov 2005
Location: not entirely sure
Posted: 15th Sep 2010 22:06
I tried to use a plane but couldn't orientate properly and I didn' fancy thrashing through the trig.

I followed Latch's suggestion of using the 2D box command rather than the 2D line command and I got 60 fps. Yay!



Incidentally, bollocks is one of my favourite words. I can't tell you what my absolute favourite word is. I'd rather this thread didn't get locked!

@ BN2 Productions

I've been struggling with DBP memblocks as well but I did put together an example of how to make an object from a mesh in DBP which you might find helpful.

http://forum.thegamecreators.com/?m=forum_view&t=175619&b=1

The code snippet is about 9 posts down.
Latch
17
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 24th Sep 2010 23:51
I though of a simpler way to do this. Actually, two. But here's one:

1. Make an image of the target reticle you want to put around the ship. It should be a certain size based on a certain range and a certain ship (so you could have targeting for a large or small ship)

2. Create a hidden sprite of the image.

3. Use the object's screen x and y, paste the sprite at the location offsetting it to the center so the ship is framed.

4. Scale the sprite based on the range.

You could do something similar with a plain - and you wouldn't have to scale it.

Enjoy your day.
Dar13
15
Years of Service
User Offline
Joined: 12th May 2008
Location: Microsoft VisualStudio 2010 Professional
Posted: 26th Sep 2010 18:13 Edited at: 26th Sep 2010 18:17
Couldn't you put a 3D box, pretty much the bounding box, textured to be transparent except the edges? Then you'd just lock the bounding box to the ship's rotation/position, and voila.



Note: the 2nd cube should be transparent with only the edges colored.


BN2 Productions
20
Years of Service
User Offline
Joined: 22nd Jan 2004
Location:
Posted: 26th Sep 2010 21:36
I considered this, but it seemed even more tricky to determine which edges should be colored (it could just color all of them red but then you would get a line going through the middle of the box if you weren't looking directly at one of the sides).

Great Quote:
"Time...LINE??? Time isn't made out of lines...it is made out of circles. That is why clocks are round!" -Caboose
Dar13
15
Years of Service
User Offline
Joined: 12th May 2008
Location: Microsoft VisualStudio 2010 Professional
Posted: 27th Sep 2010 03:47
I see what you mean. Either way would work fine, I just thought my way would be a bit less complicated.


BN2 Productions
20
Years of Service
User Offline
Joined: 22nd Jan 2004
Location:
Posted: 27th Sep 2010 04:26
Very true, but I tend to like to over complicate things. I may try out both so as to see which one works best in the final build

Great Quote:
"Time...LINE??? Time isn't made out of lines...it is made out of circles. That is why clocks are round!" -Caboose

Login to post a reply

Server time is: 2024-04-26 02:08:42
Your offset time is: 2024-04-26 02:08:42