Gamestudio Links
Zorro Links
Newest Posts
Help with plotting multiple ZigZag
by degenerate_762. 04/30/24 23:23
M1 Oversampling
by 11honza11. 04/30/24 08:16
Trading Journey
by howardR. 04/28/24 09:55
Zorro Trader GPT
by TipmyPip. 04/27/24 13:50
Data from CSV not parsed correctly
by jcl. 04/26/24 11:18
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (AndrewAMD, 7th_zorro), 935 guests, and 3 spiders.
Key: Admin, Global Mod, Mod
Newest Members
firatv, wandaluciaia, Mega_Rod, EternallyCurious, howardR
19050 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 2 of 3 1 2 3
Re: distance between line <-> point? [Re: Germanunkol] #283448
08/07/09 20:06
08/07/09 20:06
Joined: Dec 2008
Posts: 271
Saturnus Offline
Member
Saturnus  Offline
Member

Joined: Dec 2008
Posts: 271
Thank you for this example, Germanunkol!

Up to now I have used these vector functions only to select edges/lines with the mouse cursor. However it was possible to do some simple obstacle avoidance with them as well. : )

Now I have added initialization functions for spheres and lines/line segments:
vec3d (09AUG07)

ll_line3d_set()
ll_sphere_set()

They are overloaded like ll_vec3d_set(), so you can pass LL_VECTOR3D, VECTOR or individual values.

I have modified the while loop from your example and implemented the initialization functions:
Code:
while(1)
{
	radius += mickey.z*time_step*5;
	ll_sphere_set(&sphere, &vec1, (ll_vec3dtype)radius);
	ll_line3d_set(&line, &vec2, &vec3);
	isIntersecting = ll_vec3d_segSphereIntersect(line, sphere);
	wait(1);
}



BTW: In my previous post I mistakenly wrote that "you can omit the &-operator for 'll_sunPos' if this vector is global". What I actually meant was, that you can omit this operator if 'll_sunPos' is a pointer.

Re: distance between line <-> point? [Re: Saturnus] #283452
08/07/09 20:25
08/07/09 20:25
Joined: Jun 2006
Posts: 2,640
Earth
Germanunkol Offline OP
Expert
Germanunkol  Offline OP
Expert

Joined: Jun 2006
Posts: 2,640
Earth
Great, thank you smile

I changed the "line" to segment in my code, and it works like a charm now. No targeting if the sun's in the way.


~"I never let school interfere with my education"~
-Mark Twain
Re: distance between line <-> point? [Re: Germanunkol] #283465
08/07/09 21:34
08/07/09 21:34
Joined: Dec 2008
Posts: 271
Saturnus Offline
Member
Saturnus  Offline
Member

Joined: Dec 2008
Posts: 271
That's nice to hear. : )

Please let me know if you have suggestions for impovements or if you encounter any bugs.

Re: distance between line <-> point? [Re: Saturnus] #283612
08/08/09 19:45
08/08/09 19:45
Joined: Jun 2006
Posts: 2,640
Earth
Germanunkol Offline OP
Expert
Germanunkol  Offline OP
Expert

Joined: Jun 2006
Posts: 2,640
Earth
suggestions:
idea behind these is that I want to add entities to a list.
given any one entity I want to then find the next and the previous entity in the list easily. Sorry, I don't see a way of doing it without these functions

//change this to return the index of the newly added element:
int ll_list_add(LL_LIST* self, void* data);

//returns the element with the current index
//returns NULL if element with index not found.
LL_LIST_ELEM* ll_list_find(LL_LIST* self, int index);

//of course the second function would require that the object is not yet in the list.

the implementation I would then use would be something like this:
Code:
my.listIndex = ll_list_add(ll_entity_list, my );
//...
//...
LL_LIST_ELEM* currentElement;
currentElement = ll_list_find(targetEnt.listIndex);

while(currentElement != NULL)
{
   if(isMyEnemey(currentElement.data) == ON) break;
   currentElement = currentElement.next;
}
if(currentElement != NULL)
targetEnt = currentEnt.data;



Or is there some easier way?


Last edited by Germanunkol; 08/08/09 19:45.

~"I never let school interfere with my education"~
-Mark Twain
Re: distance between line <-> point? [Re: Germanunkol] #283627
08/08/09 21:48
08/08/09 21:48
Joined: Dec 2008
Posts: 271
Saturnus Offline
Member
Saturnus  Offline
Member

Joined: Dec 2008
Posts: 271
Lets see if i have fully understood what you want to achieve here. : )

Code:
//returns the element with the current index
//returns NULL if element with index not found.
LL_LIST_ELEM* ll_list_find(LL_LIST* self, int index);


This function is already implemented:
LL_LIST_ELEM *ll_list_getNth(LL_LIST *self, int index)

Code:
//change this to return the index of the newly added element:
int ll_list_add(LL_LIST* self, void* data);


According to my changelog this function should be overloaded (so you can either pass a list element or a void* as second parameter) and return a pointer to the added element. However, this is not the case obviously.^^

I've re-implemented this now: list 09AUG08

So you can use ll_list_add() like this:
Code:
// 1)
elem = ll_lelem_create(data);
ll_list_add(list, elem);

// 2) directly adds the data
// element is created internally and returned by the function
elem = ll_list_add(list, data);


As ll_list_add() appends elements at the end of the list the index of the added element will always be list->count - 1. So it's not necessary to return an elements index.

In your code you store the index of the list element in which an entity is contained. However, it would be better to store a pointer to the element instead. This would be faster (static instead of linear complexity). Also the index of an element can change, if elements are inserted in or removed from the list.

Does this answer your question?

Re: distance between line <-> point? [Re: Saturnus] #283751
08/09/09 20:32
08/09/09 20:32
Joined: Jun 2006
Posts: 2,640
Earth
Germanunkol Offline OP
Expert
Germanunkol  Offline OP
Expert

Joined: Jun 2006
Posts: 2,640
Earth
"Does this answer your question?"

It does, but only if I can put that pointer into a skill of an entity? then all of this won't be a problem...


~"I never let school interfere with my education"~
-Mark Twain
Re: distance between line <-> point? [Re: Germanunkol] #283753
08/09/09 21:04
08/09/09 21:04
Joined: Dec 2008
Posts: 271
Saturnus Offline
Member
Saturnus  Offline
Member

Joined: Dec 2008
Posts: 271
Quote:
It does, but only if I can put that pointer into a skill of an entity?

Yes, you can.
I regularly do this to associate entities with structs.

entity->listElem = ll_list_add(entity_list, (void *)enity);
elem = entity->listElem;

Works fine. : )

Re: distance between line <-> point? [Re: Saturnus] #283805
08/10/09 08:07
08/10/09 08:07
Joined: Jun 2006
Posts: 2,640
Earth
Germanunkol Offline OP
Expert
Germanunkol  Offline OP
Expert

Joined: Jun 2006
Posts: 2,640
Earth
great!
I had never thought of doing this...

yes, then all of this works. I don't even think I'll need an index any more (an index changes, after all, when I remove a part of the list... doesn't it?).

I'll just work with .next and .prev to scroll through the list and return the previous and the next target. Thank you again!


~"I never let school interfere with my education"~
-Mark Twain
Re: distance between line <-> point? [Re: Germanunkol] #283823
08/10/09 09:30
08/10/09 09:30
Joined: Dec 2008
Posts: 271
Saturnus Offline
Member
Saturnus  Offline
Member

Joined: Dec 2008
Posts: 271
Quote:
yes, then all of this works. I don't even think I'll need an index any more (an index changes, after all, when I remove a part of the list... doesn't it?).

Yes, when adding or removing an element, the indices of all following elements will change. Searching list elements by their index (and in general) is slow anyway, as you have only sequential access to them. So to access list elements randomly, storing pointers to them is the best and fastest way.

Re: distance between line <-> point? [Re: Saturnus] #283950
08/10/09 20:33
08/10/09 20:33
Joined: Jun 2006
Posts: 2,640
Earth
Germanunkol Offline OP
Expert
Germanunkol  Offline OP
Expert

Joined: Jun 2006
Posts: 2,640
Earth
grrr, I'm sorry, but I can't figure this out.

I create the list like this:

LL_LIST* ll_objectList = NULL; //global
//...
if(ll_objectList == NULL) ll_objectList = ll_list_create();
else ll_list_clear(ll_objectList,NULL);

in the entity function, I call this at the beginning:
my.objectListElement = ll_list_add(ll_objectList,(void*) my);

and this at the end:
ll_list_remove(ll_objectList,my.objectListElement,NULL);

but it gives me a "crash in ll_list_remove".

I also tried:
LL_LIST_ELEM* ll_objectTempElem = NULL;
//...
ll_objectTempElem = my.objectListElement;
ll_list_remove(ll_objectList,ll_objectTempElem,NULL);

But it says the same thing.
I'm probably doing something stupid again... sorry frown


~"I never let school interfere with my education"~
-Mark Twain
Page 2 of 3 1 2 3

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