Gamestudio Links
Zorro Links
Newest Posts
Change chart colours
by 7th_zorro. 05/11/24 09:25
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (AndrewAMD, Ayumi), 1,405 guests, and 4 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Hanky27, firatv, wandaluciaia, Mega_Rod, EternallyCurious
19051 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 3 1 2 3
distance between line <-> point? #283325
08/07/09 08:22
08/07/09 08:22
Joined: Jun 2006
Posts: 2,640
Earth
Germanunkol Offline OP
Expert
Germanunkol  Offline OP
Expert

Joined: Jun 2006
Posts: 2,640
Earth
Hi,
I have a huge sun entity in my level. It is passable and it can damage the spaceships by using a vec_dist(sun.x,ship.x) command to see if the ship is too close.
I also have a scanner system on the users HUD. He can scan for enemies who are within his range. Now I have two issues:

a) If there's something in the way (between player ship and enemy), the player should not be able to "see" the enemy on his scanner, meaning he can't target him either. With asteroids, it's no problem, I send a c_trace outand if it gets blocked I disable the targeting. The problem is with the sun: since it's passable, the trace doesn't hit anything. Can anyone think of a way of checking if the c_trace passed within XY quants of the sun's origin? I know about line-point calculation, but I'd like to see if there's a simpler trick.

b) For the commands "next enemy" and "previous enemy", I currently just "scroll" through an array and return the next/previous entry. Problem here is that I don't yet know how many enemies there will be at the end, and will never know, cause players can buy more objects that are also seens as enemies. So I was thinking if anyone had a doubly-linked-listed coded? You know... re-inventing the wheel and stuff.
Or can anyone think of simpler solutions?
I want to be able to add to that list (when a new enemy joins the battlefield) or remove enemies from the list, I also need to clear it somehow at the end of a round.

Last edited by Germanunkol; 08/07/09 08:23.

~"I never let school interfere with my education"~
-Mark Twain
Re: distance between line <-> point? [Re: Germanunkol] #283337
08/07/09 09:41
08/07/09 09:41
Joined: Feb 2008
Posts: 3,232
Australia
EvilSOB Offline
Expert
EvilSOB  Offline
Expert

Joined: Feb 2008
Posts: 3,232
Australia
A couple of ideas spring to mind for A)

1> How about when you do the scanner c_scan, set the sun NON-passable for the duration of the scan.

2> Change the scanner "c_scan" to INCLUDE passable objects.

B) Do a deep scan of the "Lite-C Contributions" forum for "linked-list". There IS one in there somewhere... Maybe 6 months back I think?


"There is no fate but what WE make." - CEO Cyberdyne Systems Corp.
A8.30.5 Commercial
Re: distance between line <-> point? [Re: EvilSOB] #283341
08/07/09 09:53
08/07/09 09:53
Joined: Jun 2006
Posts: 2,640
Earth
Germanunkol Offline OP
Expert
Germanunkol  Offline OP
Expert

Joined: Jun 2006
Posts: 2,640
Earth
sorry, the scanner's not using a c_scan... I just call it scanner. I'm using c_trace. Still, the solutions seem to be similar.
setting the sun non-passable and then back to passable: will that hurt any other c_move? and how about frame rate etc? is it fast? cause then this would be a great and simple idea.

linked list -> will do. exactly what I'm looking for. Do you remember if it's double-linked though? it wouldn't be terrible if not, it would just simplify things.


~"I never let school interfere with my education"~
-Mark Twain
Re: distance between line <-> point? [Re: Germanunkol] #283344
08/07/09 10:02
08/07/09 10:02
Joined: May 2004
Posts: 1,510
Denmark
Claus_N Offline
Serious User
Claus_N  Offline
Serious User

Joined: May 2004
Posts: 1,510
Denmark
a) Do you need to use IGNORE_PASSABLE in your trace code? smile

b) Yeah, a linked list does indeed sound like the best solution, and shouldn't be too hard making smile

Re: distance between line <-> point? [Re: Claus_N] #283353
08/07/09 11:15
08/07/09 11:15
Joined: Dec 2008
Posts: 271
Saturnus Offline
Member
Saturnus  Offline
Member

Joined: Dec 2008
Posts: 271
Hello!

A code with various vector functions (including distance between point/line, point/line segment etc.):
vec3d

A doubly linked list:
list

vec3d uses own vector structs, because the range of var is too limited for some operations.

Sorry, I can't give you more info about this at the moment, as I'm at work. However it's pretty well documented (in german) and I'm back at home this evening if you have any questions or problems.

Hope this helps. : )

Last edited by Kombucha; 08/07/09 11:15. Reason: link fixed
Re: distance between line <-> point? [Re: Saturnus] #283359
08/07/09 11:47
08/07/09 11:47
Joined: Mar 2009
Posts: 276
Cebu City, Philippines
boyax Offline
Member
boyax  Offline
Member

Joined: Mar 2009
Posts: 276
Cebu City, Philippines
@Kombucha:
Do you have english translation for the comments? If it's possible anyway... I'm interested with this & I'll give it a try.. Sorry, I can't understand german.

Cheers!:)

Re: distance between line <-> point? [Re: boyax] #283389
08/07/09 14:34
08/07/09 14:34
Joined: Dec 2008
Posts: 271
Saturnus Offline
Member
Saturnus  Offline
Member

Joined: Dec 2008
Posts: 271
@boyax
I've translated the header files to clumsy English. All structs and global functions are documented there. If you just want to use the code this should be sufficient, I hope. : )
vec3d_en
list_en

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

Joined: Jun 2006
Posts: 2,640
Earth
I got it to work!

Thank you very, very much. The player can now hide behind the sun, without being target-able (is that even a word?).
Awesome License :P... never heard of that one before. Had to google it first.

I really missed "ll_sphere3d_initialize"
and "ll_line3d_initialize"
functions... it took me a while to understand that I can't do line.from = ll_vector3d_1; because the from and to in the ll_line3d aren't pointers...

also, this gives me a "wrong number/type of parameters":
vec_set(temp,vector(sunEnt.x,sunEnt.y,sunEnt.z));
ll_vec3d_set(ll_sunPos,temp);
even though I did
#define acknex_h
and have acknex.h included.
What's wrong with my code there?


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

Joined: Dec 2008
Posts: 271
Originally Posted By: germanunkol
also, this gives me a "wrong number/type of parameters":
vec_set(temp,vector(sunEnt.x,sunEnt.y,sunEnt.z));
ll_vec3d_set(ll_sunPos,temp);
even though I did
#define acknex_h
and have acknex.h included.
What's wrong with my code there?

Normally the lite-C compiler automatically detects if a variable has to be passed by value or by reference. However, this does not work for overloaded functions, so you have to use the address operator here for your local structs:
Code:
LL_VECTOR3D ll_sunPos;
VECTOR temp;
...
vec_set(temp,vector(sunEnt.x,sunEnt.y,sunEnt.z));
ll_vec3d_set(&ll_sunPos, &temp); // using address operators is necessary here


Of course you can omit the &-operator for "ll_sunPos" if this vector is global.

Quote:
I really missed "ll_sphere3d_initialize" and "ll_line3d_initialize" functions...

Yes, good idea. I'll add those functions. : )

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

Joined: Jun 2006
Posts: 2,640
Earth
I am so stupid. I was using the line-Sphere intersection all along, when i should have been using the segment-sphere command.

Anyways, I build a nice little app to show you the "bug", and while posting, I realized my stupidity.
If you want the app to showcase your code, here it is. simply save it as test.c into the same folder as vec3d.c, and run it.

left click -> place first line point
right click -> place second line point
mouse wheel -> change radius

It works great, but I'm stupid... I just spent 2 hours trying to figure out why it didn't work right. maybe even longer.

Code:
#include <acknex.h>
#include <default.c>

#include "vec3d.c";


VECTOR vec1;
VECTOR vec2;
VECTOR vec3;

VECTOR temp;

LL_SPHERE sphere;
LL_LINE3D line;

STRING* toWrite = "#30";

int isIntersecting = OFF;

var radius = 100;

VECTOR center;

void draw_circle(VECTOR* pos, var radius)
{
	var angle = 0;
			vec_set(temp,vector(radius*cos(angle),radius*sin(angle),0));
		vec_add(temp,center);
	draw_line(temp,NULL,0);
	draw_line(temp,vector(255,255,255),100);
	
	while(angle <= 360)
	{
		vec_set(temp,vector(radius*cos(angle),radius*sin(angle),0));
		vec_add(temp,center);
		draw_line(temp,vector(255,255,255),100);
		angle += 10;
	}
}

void draw_info()
{
	while(1)
	{
		str_for_num(toWrite,vec1.x);
		draw_text(toWrite,20,20,vector(255,255,255));
		str_for_num(toWrite,vec1.y);
		draw_text(toWrite,20,40,vector(255,255,255));
		str_for_num(toWrite,vec1.z);
		draw_text(toWrite,20,60,vector(255,255,255));
		
		str_for_num(toWrite,vec2.x);
		draw_text(toWrite,20,80,vector(255,255,255));
		str_for_num(toWrite,vec2.y);
		draw_text(toWrite,20,100,vector(255,255,255));
		str_for_num(toWrite,vec2.z);
		draw_text(toWrite,20,120,vector(255,255,255));
		
		str_for_num(toWrite,vec3.x);
		draw_text(toWrite,20,140,vector(255,255,255));
		str_for_num(toWrite,vec3.y);
		draw_text(toWrite,20,160,vector(255,255,255));
		str_for_num(toWrite,vec3.z);
		draw_text(toWrite,20,180,vector(255,255,255));
				str_for_num(toWrite,mouse_pos.x);
		draw_text(toWrite,20,280,vector(255,255,255));
				str_for_num(toWrite,mouse_pos.y);
		draw_text(toWrite,20,300,vector(255,255,255));
		
		if(isIntersecting)
		draw_text("Intersect",20,200,vector(255,255,255));
		else
		draw_text("Don't intersect",20,200,vector(255,255,255));
		
		vec_set(temp,vec2);vec_add(temp,center);
		
		draw_line(temp,NULL,100);
		draw_line(temp,vector(255,255,255),100);
		
		vec_set(temp,vec3);vec_add(temp,center);
		draw_line(temp,vector(255,255,255),100);
		
		draw_circle(vec1,radius);
		wait(1);
	}
}


void setfirst()
{
	vec2.x = mouse_pos.x - center.x;
	vec2.y = mouse_pos.y - center.y;
}

void setsecond()
{
	vec3.x = mouse_pos.x - center.x;
	vec3.y = mouse_pos.y - center.y;
}


void main()
{
	vec_set(vec1,vector(0,0,0));
	vec_set(vec2,vector(0,0,0));
	vec_set(vec3,vector(0,0,0));
	vec_set(center,vector(screen_size.x/2,screen_size.y/2,0));
	
	mouse_mode = 4;

	on_mouse_left = setfirst;
	on_mouse_right = setsecond;


	draw_info();

	while(1)
	{
		radius += mickey.z*time_step*5;
		sphere.pos.x = vec1.x;sphere.pos.y = vec1.y;sphere.pos.z = vec1.z;
		sphere.radius = radius;
		line.from.x = vec2.x;line.from.y = vec2.y;line.from.z = vec2.z;
		line.to.x = vec3.x;line.to.y = vec3.y;line.to.z = vec3.z;
		
		isIntersecting = ll_vec3d_lineSphereIntersect(line, sphere);
		wait(1);
	}
}




~"I never let school interfere with my education"~
-Mark Twain
Page 1 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