Gamestudio Links
Zorro Links
Newest Posts
New FXCM FIX Plugin
by flink. 06/04/24 07:30
AlpacaZorroPlugin v1.3.0 Released
by kzhao. 05/22/24 13:41
Free Live Data for Zorro with Paper Trading?
by AbrahamR. 05/18/24 13:28
Change chart colours
by 7th_zorro. 05/11/24 09:25
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
0 registered members (), 1,454 guests, and 8 spiders.
Key: Admin, Global Mod, Mod
Newest Members
AemStones, LucasJoshua, Baklazhan, Hanky27, firatv
19058 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
vec_dist question #407241
09/10/12 06:09
09/10/12 06:09
Joined: Apr 2008
Posts: 245
GameScore Offline OP
Member
GameScore  Offline OP
Member

Joined: Apr 2008
Posts: 245
i want try to find out wich entity is the closest to the mouse_pos3d
i use a trace from mouse_pos3d like this
Code:
vec_add(vec_scale(vec_set(trace_target, mouse_dir3d), 1000), mouse_pos3d);
c_trace (mouse_pos3d,trace_target,SCAN_TEXTURE | USE_POLYGON | IGNORE_FLAG2);
vec_set(mouse_hit.x,hit.x);



and calculate the the dist

Code:
for(i=1;i<=ent_count; i++)
{	
var distance=vec_dist(ent.x[i],mouse_hit.x);
}



with this i have the distance of all counted entitys
but how can i calculate wich is the closest?

Re: vec_dist question [Re: GameScore] #407242
09/10/12 06:15
09/10/12 06:15
Joined: Mar 2008
Posts: 2,247
Baden Württemberg, Germany
Espér Offline
Expert
Espér  Offline
Expert

Joined: Mar 2008
Posts: 2,247
Baden Württemberg, Germany
use
c_scan.. it returns the you-pointer tothe closest hitten entity.


Selling my Acknex Engine Editions (A7 Com & A8 Pro):
>> click here if you are interested <<
Re: vec_dist question [Re: Espér] #407294
09/11/12 05:40
09/11/12 05:40
Joined: Apr 2008
Posts: 245
GameScore Offline OP
Member
GameScore  Offline OP
Member

Joined: Apr 2008
Posts: 245
thanks, its a good idea
but i look for a way to calculate with vec_dist

i have no idea how i can find out wich value is the smallest

i have up to 10 values stored in a array
now i want to find out wich is the smallest one

Re: vec_dist question [Re: GameScore] #407300
09/11/12 07:13
09/11/12 07:13
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Superku Offline
Senior Expert
Superku  Offline
Senior Expert

Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Seems like you are looking for a sorting algorithm, try Insertion Sort:
http://en.wikipedia.org/wiki/Insertion_sort
It's of quadratic cost, but easy to understand and implement and fast enough for 10 entities.


"Falls das Resultat nicht einfach nur dermassen gut aussieht, sollten Sie nochmal von vorn anfangen..." - Manual

Check out my new game: Pogostuck: Rage With Your Friends
Re: vec_dist question [Re: GameScore] #407303
09/11/12 07:45
09/11/12 07:45
Joined: Dec 2003
Posts: 1,225
germany
gri Offline
Serious User
gri  Offline
Serious User

Joined: Dec 2003
Posts: 1,225
germany


so go through the array, compare the values and save the smallest one in a variable

whats the problem?


"Make a great game or kill it early" (Bruce Shelley, Ensemble Studios)
Re: vec_dist question [Re: gri] #407325
09/11/12 13:51
09/11/12 13:51
Joined: Apr 2008
Posts: 245
GameScore Offline OP
Member
GameScore  Offline OP
Member

Joined: Apr 2008
Posts: 245
can u help me please how i can compare the values?
i really dont find a workingsolution

Code:
void test()
{
int i,t,p;
for(i=1 ; i<array_size ; i++)
{
t=i+1;	
if(array[i] < array[t])
{
p = array[i];
}
if(array[i] > array[t])
{
p = array[t];
}
}		
}



this only works with a array who have the size of 2

Re: vec_dist question [Re: GameScore] #407326
09/11/12 14:11
09/11/12 14:11
Joined: Nov 2002
Posts: 913
Berlin, Germany
S
SchokoKeks Offline
User
SchokoKeks  Offline
User
S

Joined: Nov 2002
Posts: 913
Berlin, Germany
I always do it like this:

Code:
void test()
{
  var dst, smallest = 99999;
  int i, smallest_i = 0;

  for (i = 0; i < array_size; i++)
  {
    dst = vec_dist((ent[i]).x, mouse_hit.x);
    if (dst < smallest)
    {
      smallest = dst;
      smallest_i = i;
    }
   }
}


Re: vec_dist question [Re: SchokoKeks] #407330
09/11/12 14:33
09/11/12 14:33
Joined: Apr 2008
Posts: 245
GameScore Offline OP
Member
GameScore  Offline OP
Member

Joined: Apr 2008
Posts: 245
Jaaaaaaaaaaaaaaaah!
thanks man!
thats what i ws locking for
i`m so thanfull

u forgot a small thing in your example
forgot the "="

Code:
for (i = 0; i <= array_size; i++)



i`m so happy now!

thank you schokokes

Re: vec_dist question [Re: GameScore] #407332
09/11/12 14:51
09/11/12 14:51
Joined: Nov 2002
Posts: 913
Berlin, Germany
S
SchokoKeks Offline
User
SchokoKeks  Offline
User
S

Joined: Nov 2002
Posts: 913
Berlin, Germany
Glad to help

Originally Posted By: GameScore

u forgot a small thing in your example
forgot the "="


no, i did that on purpose. Remember that in most programming languages counting and arrays start at 0.

so if you have an array with 2 entries (array_size=2), you access them with i=0 and i=1.

If you use i=2, there will usually be no direct crash but you access memory that does not belong to the array! that is very bad, and if you change this memory you will get a crash somewhere totally unrelated and its extremely hard to figure out where this crash comes from.

So be very carefull with array indices!

Re: vec_dist question [Re: SchokoKeks] #407335
09/11/12 16:18
09/11/12 16:18
Joined: Apr 2008
Posts: 245
GameScore Offline OP
Member
GameScore  Offline OP
Member

Joined: Apr 2008
Posts: 245
ok,
thanks


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

Gamestudio download | chip programmers | 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