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 / Could do with some help with selection box system

Author
Message
toipot2
21
Years of Service
User Offline
Joined: 14th Nov 2003
Location:
Posted: 22nd May 2004 13:31
Heya
I have been working on a selection box system for my game for some while, but there are still bugs in the on i have got here. Im using the 'brute force' approach, checking the distance between the player and every object within a certain range (5-54 inclusive). In my game I dont think a collision-sphere based system would work to well, the loading times are large enough already, and the framerate is slowly decreasing as i add more features. Although a bit laggy, this method seems to be the quickest approach to the problem.

To avoid a for t=5 to 54 loop right in the middle of my game loop (which may slow things down the code begins like this:



---------------------------------------------
and ends with



so each run through of the loop, it checks a different object. Within the loop there is this following section of code:

Note - a# is the object for which the selection box must be positioned against, and gloopfunctionglobals(1) is the last object to have the box positioned against it, the prox_obj and posit_boxes functions are as below:



Problem is with this code, it seems to work for one object in the world (the first one it selects) and then for all of the others it just flickers on them for a moment and then returns zero, im probably missing something really obvious (its always the way) but I can't see it.

I'd be grateful for any help

Thanks
Toipot

P.s dont worry about the lack of a 'delete sprite' command to get rid of the sprite when there is nothing to position it against, left it out for debug purposes
GameKit
22
Years of Service
User Offline
Joined: 6th Mar 2003
Location: USA, Staring Blankly at a Computer
Posted: 24th May 2004 03:20
I noticed one thing... Change your distance formula to this...

dist#=sqrt((x#-object position x(t))^2+(y#-object position y(t))^2+(z#-object position z(t))^2)

Then adjust all the numbers based on your previous distance formula to one squarerooth (is that a word?) of thier value... example... 90000 would be 300... that should simplify things...

Other than that, I dont see anything out of place...

...Well... I hope I helped anyways...

Previously known as "Game_Creator".
The question is, why am I talking to myself? ...... And more importantly, why am I waiting for a reply?
Phaelax
DBPro Master
22
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 24th May 2004 03:48
What is the selection system suppose to do? Are we talking about drawing a box on the screen and selecting all objects within that box?

"eureka" - Archimedes
toipot2
21
Years of Service
User Offline
Joined: 14th Nov 2003
Location:
Posted: 24th May 2004 21:53 Edited at: 24th May 2004 21:55
@Gamekit
Thanks for the advice but thats intentional
the sqrt() function's pretty CPU intensive, so it's just easier to remove it and to square all the checks. I want to make sure the object is within 300 units, so i can use 3d pythagoras, but i remove the costly sqrt operation and square the check (300) so it becomes 90000, a big number but it's less of a crunch on the processor.
Nicely spotted though
@Phaelax
What it's supposed to do Is this:

Cycle through a list of 'interactive' obects (as I call them)
The objects are numbered 5-54 inclusive.
If an object is within 300 distance units (is there a better word for that?) Then the code places a particular 'square box' sprite upon the object, and writes the name of the object below (interdat$ is the array containing all the information on these 'interactive objects' indexed by their object numbers). There are probs, like, if two objects are within 300 units it should flicker evenly between the two (not good design but ill work on that later) in the example level i'm running it does, but stays over the second object for only a fraction of a second before returning for longer over the first object it selected. The system is used so that the player can right click and use an object in the world (the one that is highlighted by this box) e.g switches, terminals etc.

Probably a bit over complicated but hey.

Thanks for the interest, it was looking like nobody wanted to read this post
Phaelax
DBPro Master
22
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 25th May 2004 03:04
A simple check at the beginning get exclude a few objects right from the start. If the object's X or Y position is more than 300 units away, then skip it. Otherwise calculate its distance.


"eureka" - Archimedes
toipot2
21
Years of Service
User Offline
Joined: 14th Nov 2003
Location:
Posted: 25th May 2004 19:47
Umm, ok, ill see if I can rebuild the system around this, should speed things up a little anyway. The code i've got for it is a bit messy anyway, DB's auful for spaghetti coding

Thanks for the help

Toipot
Arkheii
21
Years of Service
User Offline
Joined: 15th Jun 2003
Location: QC, Philippines
Posted: 25th May 2004 20:06
Spaghetti coding?

Login to post a reply

Server time is: 2025-05-24 00:28:08
Your offset time is: 2025-05-24 00:28:08