Gamestudio Links
Zorro Links
Newest Posts
Zorro 2.70
by jcl. 09/29/25 09:24
optimize global parameters SOLVED
by dBc. 09/27/25 17:07
ZorroGPT
by TipmyPip. 09/27/25 10:05
assetHistory one candle shift
by jcl. 09/21/25 11:36
Plugins update
by Grant. 09/17/25 16:28
AUM Magazine
Latest Screens
Rocker`s Revenge
Stug 3 Stormartillery
Iljuschin 2
Galactic Strike X
Who's Online Now
2 registered members (TipmyPip, 1 invisible), 18,789 guests, and 8 spiders.
Key: Admin, Global Mod, Mod
Newest Members
krishna, DrissB, James168, Ed_Love, xtns
19168 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
get closest entity in scan #120065
03/29/07 13:35
03/29/07 13:35
Joined: Mar 2006
Posts: 752
Portugal
demiGod Offline OP
User
demiGod  Offline OP
User

Joined: Mar 2006
Posts: 752
Portugal
Hi,

I want to calculate the closest entity given in a scan range each time to a target point, please see the image:




1 - Entity 1 has a scan range using SCAN_ENTITY;

2 - Inside that scan range the event_detec its used to enumerate the scanned entities and saved the handle;

Code:


if(event_type == event_detect)
{
TEMP_SCANNED_ENTITY = you;
ds_scan_array_list[ds_scanEntityID] = you;
ds_scan_array_list[ds_scanEntityID] = handle(TEMP_SCANNED_ENTITY);
ds_scanEntityID += 1;





3 - Get the closest detected entity to the target point every time;

Code:


function getClosestEntity(&obj) //obj will be target point
{
var iDist;
var i;
you = 0;
my = obj;
while(i < ds_scanEntityID)
{
if(ds_scan_array_list[i] == 0)
{
i += 1;
continue;
}
ds_TEMP_CLOSEST_ENTITY = ptr_for_handle(ds_scan_array_list[i]);
i += 1;
if(!ds_TEMP_CLOSEST_ENTITY)
{
continue;
}
if(you == 0 || vec_dist(ds_TEMP_CLOSEST_ENTITY.x,my.x) < iDist)
{
you = ds_TEMP_CLOSEST_ENTITY;
iDist = vec_dist(you.x,my.x);
}
}
ds_SCANNED_CLOSEST_ENTITY = you;
return (iDist);
}




4 - So, ds_SCANNED_CLOSEST_ENTITY should be always the closest detected entity to the target point, but sometimes it gives strange results. Sometimes it returns the closest entity and sometimes dont work it gives another entity.

What´s the problem in here?

5 - One last question: how can i implement the code in order to enumerate the closest entities to the target point by descendant order?

Thanks in advance.

Re: get closest entity in scan [Re: demiGod] #120066
03/29/07 15:32
03/29/07 15:32
Joined: Jan 2007
Posts: 651
Germany
R
RedPhoenix Offline
User
RedPhoenix  Offline
User
R

Joined: Jan 2007
Posts: 651
Germany
my = obj; ???

I don't understand this line, why do you fill a pointer with a vector? I'm not really up to date with the latest engine commands but I don't think that that's possible. I would do it by simply using vec_dist (obj,you.x) and not using my at all.

Re: get closest entity in scan [Re: RedPhoenix] #120067
03/29/07 15:50
03/29/07 15:50
Joined: Mar 2006
Posts: 752
Portugal
demiGod Offline OP
User
demiGod  Offline OP
User

Joined: Mar 2006
Posts: 752
Portugal
Well, i was trying so hard to reuse all the code that i didnt saw that. This function had been used for entities and pointers and now, with a vector of course it will not work such way.. in c-script.

Now it works like a charm, thank you RedPhoenix for pointing that.

BTW, if you have an idea about the last question just tell me.
Thanks.

Re: get closest entity in scan [Re: demiGod] #120068
03/29/07 15:53
03/29/07 15:53
Joined: Mar 2006
Posts: 2,758
Antwerp,Belgium
frazzle Offline
Expert
frazzle  Offline
Expert

Joined: Mar 2006
Posts: 2,758
Antwerp,Belgium
I assume obj is an entity, so don't write it as my = obj but obj = my ^^
But for the rest I havn't checked your code to great detail but this was just one strange line I marqued.

Cheers

Frazzle


Antec® Case
Intel® X58 Chipset
Intel® i7 975 Quad Core
8 GB RAM DDR3
SSD OCZ®-VERTEX2 3.5 x4 ; HD 600 GB
NVIDIA® GeForce GTX 295 Memory 1795GB
Re: get closest entity in scan [Re: frazzle] #120069
03/29/07 20:17
03/29/07 20:17
Joined: Oct 2004
Posts: 1,655
T
testDummy Offline
Serious User
testDummy  Offline
Serious User
T

Joined: Oct 2004
Posts: 1,655
The following is probably faulty. It uses a plugin and it may not actually emulate the functionality you seek...?
Reference: eLL
Code:


entity* ent0;
entity* ent1;
function getClosest(_what, &_centerPoint, _radius, &_point) {
var dist0; dist0 = 99999;
var dist1; dist1 = dist0;
ent0 = NULL;
eLLNextReset(_what);
ent0 = eLLNext(_what);
ent1 = NULL;
while(ent0 != NULL) {
if (vec_dist(_centerPoint, ent0.x) <= _radius) {
dist1 = vec_dist(ent0.x, _point);
if (dist1 < dist0) {
dist0 = dist1;
ent1 = ent0;
}
}
ent0 = eLLNext(_what);
}
//ent1 should now be NULL or the closest thing of type _what to _point
/// also in sphere centered at _centerpoint with _radius?
}



Re: get closest entity in scan [Re: testDummy] #120070
03/30/07 08:36
03/30/07 08:36
Joined: Mar 2006
Posts: 752
Portugal
demiGod Offline OP
User
demiGod  Offline OP
User

Joined: Mar 2006
Posts: 752
Portugal
Thanks for the reference testDummy.


Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1