Gamestudio Links
Zorro Links
Newest Posts
zorro license, IB connection
by AndrewAMD. 12/06/23 17:16
Newbie Questions
by fairtrader. 12/06/23 11:29
Zorro Trader GPT
by TipmyPip. 12/04/23 11:34
Square root rule
by Smallz. 12/02/23 09:15
RTest not found error
by TipmyPip. 12/01/23 21:43
neural function for Python to [Train]
by TipmyPip. 12/01/23 14:47
Xor Memory Problem.
by TipmyPip. 11/28/23 14:23
Training with command line parameters
by TipmyPip. 11/26/23 08:42
AUM Magazine
Latest Screens
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Tactics of World War I
Who's Online Now
5 registered members (AndrewAMD, miwok, TipmyPip, 3run, 1 invisible), 631 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
fairtrader, hus, Vurtis, Harry5, KelvinC
19019 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
handling two things #268634
05/30/09 12:07
05/30/09 12:07
Joined: Apr 2009
Posts: 18
U
umphafiz Offline OP
Newbie
umphafiz  Offline OP
Newbie
U

Joined: Apr 2009
Posts: 18
hi smile

i am designing a ray-tracer using c-script in SED and a WED file to design an indoor environment. I have a transmitter and receiver in the room and some other material as well (like table chair, glass etc). So far, my program traces the path followed by a ray from transmitter to receiver and records some data. when a ray hits some object, the program calculated the direction of reflected (using law of reflection) and keeps doing until it hits the receiver.

Now i want to implement refraction as well. in my WED file, there is only one mirror (object or entity). it means when a ray hits this obstacle (glass), it should split up into two rays; reflected and refracted rays. Reflected ray is already being tracked. Now i want my program to track refracted ray as well. There is no problem in finding the direction of refracted ray etc.

the problem is:

how can my program track the two rays simultaneously?if threading is answer, could anyone please help me in how to deal threads in c-scripting?

asif

Re: handling two things [Re: umphafiz] #268647
05/30/09 13:28
05/30/09 13:28
Joined: Feb 2008
Posts: 3,232
Australia
EvilSOB Offline
Expert
EvilSOB  Offline
Expert

Joined: Feb 2008
Posts: 3,232
Australia
Its a bit hard to say, with having seen pretty much your whole code.
But, if you can, or have, the main "ray" being managed by a single action,
then when you hit glass, spawn a new ray and actions for it.


"There is no fate but what WE make." - CEO Cyberdyne Systems Corp.
A8.30.5 Commercial
Re: handling two things [Re: EvilSOB] #268653
05/30/09 13:42
05/30/09 13:42
Joined: Jan 2004
Posts: 2,062
Hamburg, Germany
slacer Offline
Expert
slacer  Offline
Expert

Joined: Jan 2004
Posts: 2,062
Hamburg, Germany
If you ray hits a surface which creates two resulting rays, you would call the raytracing function once for each new vector in sequencial order.

You have to store the result of the first trace and start the next trace.
If you have both results you could simply add them and normalize the result in order to make sure the RGB components don't exeed 1.0 or 255 depending on your color model.

As far as I know, you cannot use threading with recursive function calls in gamestudio.

Re: handling two things [Re: EvilSOB] #268743
05/30/09 23:03
05/30/09 23:03
Joined: Apr 2009
Posts: 18
U
umphafiz Offline OP
Newbie
umphafiz  Offline OP
Newbie
U

Joined: Apr 2009
Posts: 18
here is my main function
***********************************************************
function follow_path()
{
// SHOULD SET/RESET all the global Vars :
my = RTransmitter;
you = null;// RReceiver;
var temp_here[3];
var temp_target[3];
var temp_dir[3];
var temp_bounce[3];
var temp_normal[3];
var temp_range = 0;
var temp_traveled = 0;
var temp_bounce_num = 0;
var reached = 0 ; // 0 , or else we have reached the vicinity !
fp_disttl_clicks = fp_disttl * level_scaling_factor;
fp_receiver_radius_clicks = fp_receiver_radius * level_scaling_factor;
vec_set(fp_angle_to_receiver,nullvector);
vec_set(temp_here,fp_start_pos);
vec_set(temp_dir,fp_gra_vec);
temp_dir.roll = 0;
temp_bounce_num = 0;
reached = 0;
fp_dist_to_receiver = 0;
fp_result = 0;
while ((temp_traveled<fp_disttl_clicks)&&(reached==0)&&((fp_max_bounce<0)||(temp_bounce_num<=fp_max_bounce)))
{
vec_set(temp_target,nullvector);
temp_target.x = fp_disttl_clicks; //fp_disttl_clicks - temp_traveled;
vec_rotate(temp_target,temp_dir);
vec_add(temp_target,temp_here); // the target POINT <<
//trace_mode = IGNORE_ME + IGNORE_YOU + IGNORE_SPRITES + IGNORE_PASSENTS + IGNORE_PASSABLE + activate_sonar + scan_texture;
trace_mode = IGNORE_ME + IGNORE_SPRITES + scan_texture + IGNORE_PASSABLE + activate_sonar ; // + IGNORE_YOU + IGNORE_PASSENTS
temp_range = trace(temp_here,temp_target);
//now reflection is implemented. goal is to go to the direction of reflected ray
vec_set(temp_target, target);
vec_set(temp_normal, normal);
vec_to_angle(temp_bounce, temp_normal);
vec_scale(temp_bounce,2);
vec_inverse(temp_dir);
ang_add(temp_bounce,temp_dir);
ang_add(temp_bounce,vector(-180,0,0)); // now we are right in the direction of reflected ray
temp_range = int(temp_range);
temp_traveled += temp_range;
if (temp_traveled > fp_disttl_clicks)
{
file_str_write(resultfile," died midair (travel>disttl)");
fp_result = FP_RES_DIED_MIDAIR;
fp_dist_to_receiver = 0;
vec_set(fp_angle_to_receiver,nullvector);
return (fp_result);
}
if (temp_range < 0) // started inside belly
{
file_str_write(resultfile," INS SIN ");
fp_result = FP_RES_ERROR;
fp_dist_to_receiver = -1;
//file_var_write(resultfile,fp_disttl);
vec_set(fp_angle_to_receiver,nullvector);
scroll_message("INS INS SIN !");
//Lets say... End of the LINE ! But this should not have happened... So Debug/Redesign
return (fp_result);
}
if (temp_range == 0) // nothing hit, return zero
{
//file_str_write(resultfile," nothing hit (range 0)");
fp_result = FP_RES_DIED_MIDAIR;
fp_dist_to_receiver = 0;
vec_set(fp_angle_to_receiver,nullvector);
return (fp_result);
}
else
{
if (temp_range > 0)
{
//file_str_write(resultfile," hit ");
if (you != null) // entity hit, check details !
{
//file_str_write(resultfile," entity ");
if (you == RTransmitter) // hit back to me, discard this one !
{
file_str_write(resultfile," myself ");
scroll_message("Self Hit !");
fp_result = FP_RES_HIT_MYSELF;
fp_dist_to_receiver = 0;
vec_set(fp_angle_to_receiver,nullvector);
return (fp_result);
}
if (you == RReceiver) //((you == RReceiver)||(you == player)) // JACKPOT !
{
scroll_message("JACKPOT...!");
reached = 1;
vec_set(fp_angle_to_receiver,temp_dir);
fp_result = temp_traveled;
fp_dist_to_receiver = float(fp_result)/level_scaling_factor;
file_var_write(resultfile,fp_gra_vec[0]);
file_str_write(resultfile," ");
file_var_write(resultfile,fp_gra_vec[1]);
file_str_write(resultfile," ");
file_var_write(resultfile, temp_traveled);
file_str_write(resultfile," ");
file_var_write(resultfile,temp_traveled/level_scaling_factor);
file_str_write(resultfile," ");
file_var_write(resultfile,temp_bounce_num);
file_str_write(resultfile," ");
file_var_write(resultfile,fp_angle_to_receiver[0]);
file_str_write(resultfile," ");
file_var_write(resultfile,fp_angle_to_receiver[1]);
file_asc_write(resultfile,13);
file_asc_write(resultfile,10);
return (fp_result);
}
}
}
vec_set(temp_here,temp_target);
vec_set(temp_dir, temp_bounce); //for refraction, only this needs to be changed.
//i think, temp_dir will keep moving in the same direction but a displacement will be added equal to the
size of the glass object.
temp_bounce_num += 1;
} // else
} // while ((temp_traveled<fp_disttl_clicks)&&(reached==0)&&((fp_max_bounce<0)||(temp_bounce<=fp_max_bounce)))

fp_result = temp_traveled;
fp_bounce_num = temp_bounce_num-1;
fp_dist_to_receiver = float(fp_result)*level_scaling_factor;
return (fp_result);
}
*************************************************************
in this function for reflection, everything remains the same but when you == glass, then there will be two rays one in the direction set by the command
vec_set(temp_dir, temp_bounce);

and second (refracted ray) should be in the same directed but displaced equal to the size of the glass.

i want to handle these two rays simultaneously.


asif

Re: handling two things [Re: slacer] #268995
06/01/09 10:07
06/01/09 10:07
Joined: Apr 2009
Posts: 18
U
umphafiz Offline OP
Newbie
umphafiz  Offline OP
Newbie
U

Joined: Apr 2009
Posts: 18
hi smile ,

two more thing!

1. for the command,
vec_add(my.x,vector(1,2,3));

what are the units of (1,2,3)? is it in quants or what?


2. i have an entity named uwbstick.mdl. I want to check whether it is hit or not, I wrote this way

entity* glass;
glass = <uwbstick.mdl>;

and then i check

if (you == glass)

but it gives me errors. could any one explain it?


asif

Last edited by umphafiz; 06/01/09 19:04.
Re: handling two things [Re: umphafiz] #269273
06/02/09 13:29
06/02/09 13:29
Joined: Feb 2008
Posts: 3,232
Australia
EvilSOB Offline
Expert
EvilSOB  Offline
Expert

Joined: Feb 2008
Posts: 3,232
Australia
1> The vec_add() itself has no units, nor does the vector() function.
So vec_add(my.x,vector(1,2,3)); gets its units from my.x, which IS in quants.

2> In THEORY this is correct, but glass = <uwbstick.mdl>; is not a valid way to create an entity.
Check the manual. Take too long to explain otherwise.


Back to your original question.

Blleacchhh. What an evil piece of coding. Not bad, just VERRRY complex.
i wont pretend to understand even 5% of it.
But I see where its going, and I can give a "general" description of what you need to do.
But the hard work is going to be up to you, I hope you stll understand it all, you'll need to.
I dont believe its possible to use "external" threading without lite-c, but I may be wrong.

This function (if I understand it correctly) handles the travelling RAY, right
from its spawn-time until its "success" or "death".
It handles the bouncing, duration of life, and if it gets to the intended target.

I THINK what you need to do is when you "split" the ray, you need to create a
dummy "transmitter" at the split location, call another instance of this function
and let if run through, then remove the dummy transmitter.
And then trigger a success event if the child had one, otherwise continue with this run.
You'll need to add to this function the ability to know if it is the parent or the child.

Thats the best i can think of.

Best of luck.


"There is no fate but what WE make." - CEO Cyberdyne Systems Corp.
A8.30.5 Commercial
Re: handling two things [Re: EvilSOB] #269443
06/03/09 06:16
06/03/09 06:16
Joined: Apr 2009
Posts: 18
U
umphafiz Offline OP
Newbie
umphafiz  Offline OP
Newbie
U

Joined: Apr 2009
Posts: 18
Hi!

Thanks for your reply. I am done with handling two rays in a sequential style.

However, I don't know how to calculate the size of the object (entity, picture etc.).For instance, if it is a mirror, i would like to calculate thickness, length etc. of the mirror. How is it possible?

asif

Re: handling two things [Re: umphafiz] #269855
06/04/09 21:19
06/04/09 21:19
Joined: Apr 2009
Posts: 18
U
umphafiz Offline OP
Newbie
umphafiz  Offline OP
Newbie
U

Joined: Apr 2009
Posts: 18
hi!


is there any one to answer...?please quick


asif

Re: handling two things [Re: umphafiz] #269861
06/04/09 21:50
06/04/09 21:50
Joined: Jan 2004
Posts: 2,062
Hamburg, Germany
slacer Offline
Expert
slacer  Offline
Expert

Joined: Jan 2004
Posts: 2,062
Hamburg, Germany
You could try to use the bounding box value or step through the models vertices and stor min/max for each dimension (xyz)


Moderated by  HeelX, rvL_eXile 

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