//set the 3d view
d3d_view()
//Set the 3d object to -1, this says as of now, that their is no object under the mouse
Object3D = -1
//clear the color in black (ObjAr000), this means that when you get the color black r0,g0,b0, it will return a - value
draw_clear(0);
//set hidden to 1
d3d_set_hidden(1)
//globalize the variables so that it applies to all objects
globalvar ObjAr, R, G, B;
//set the initial 3-d array 0,0,0 to -1, so this means the color black has a value of -1
Ray3Set(0,0,0,-1)
//set R to 1
R = 1;
//set G to 1
G = 1;
//set B to 1
B = 1;
//make a temp var called N
var N;
//set N to 0
N = 0;
//Global variable for the current camera and the minimal distance to draw at
globalvar FogD, Cam;
//perform a while loop that will continue until the N value has reached the size of the list containing all objects to check
while(N < ds_list_size(ObjList))
{
//make a temp var Obj
var Obj;
//set Obj to the object in the list
Obj = ds_list_find_value(ObjList,N)
//execute the code with the Obj instance, this will E.G. check all objects of Ellipse when N is 0,
//if you know how lists work, then this should be no problem for you, if not, then im sorry, but
//im not going to go into depth on how lists work, and what there functions are, try searching
//the forums for something that might help you/
with(Obj)
{
if (point_distance(x,y,Cam.x,Cam.y)<FogD)
{
//set the current color to R,G,B so that it will get a unique identifier
draw_set_color(make_color(R,G,B))
//draw the model in the color set from R,G,B
d3d_model_draw(Model,x,y,z,-1)
//set the Ray value for the color given to the id of the object being drawn
Ray3Set(R,G,B,id)
//add 1 to r, if r is greater than 254, set it to 0 and add 1 green, do the same for green, all the way till it reaches blue
//this is done so that you could have all the way up to 253*253*253 objects that could be checked (*this makes sure each color is unique)
R += 1;
if R > 254
{
R = 0
G += 1
}
if G > 254
{
G = 0;
B += 1;
}
}
}
N += 1;
}
//Make a temp variable for the color that is under the mouse
var MouseCol;
//set the var MouseCol to the color under the mouse
MouseCol = draw_getpixel(window_view_mouse_get_x(0),window_view_mouse_get_y(0))
//retrieve the id of the object (if any) from the color taken from the Color under the mouse
Object = Ray3Get(color_get_red(MouseCol),color_get_green(MouseCol),color_get_blue(MouseCol))
//if the color is indeed unique, and an instance exists for that color, set the global value for the obects to check with that value compared to their
//id
if instance_exists(Object)
{
//set the variables
Object3D = Object;
globalvar ObjectId;
ObjectId = Object;
}
//reset the lighting to default (UseLight)
//d3d_set_lighting(global.UseLight)
//Reset the fog if it is on
globalvar Fog, FogC;
// d3d_set_fog(Fog,FogC,32,FogD);
}