You are not logged in.
Pages: 1
Alright so I tried to research the exact_gauss() script by looking up guass things all over the internet, but I still don't have a solid concept on how it works... I was hoping someone could explain it to me using an example, that'd be very useful. Currently, I want to make a guass random curve that varies from 0 to 360 and is mostly attracted to 180, but at the same time I want to be able to change how much the attraction to 180. (Sometimes i want the random to be very close to 180 (very tight bell curve), and other times I want it to be very far from it(closer to a regular, linear distribution) how can I do this?)
I'm sorry for posting this, but I really just have no clue how it works and I REALLY want to understand it (I have tried doing research!). Thanks for any help.
So after a lot of messing and asking around, I made a script that will return a ds list with the a, b and c coefficients (in that order) of the quadratic formula (where [tex]ax^2 + bx + c = 0[/tex]) that crosses the three given points. So um, here's the script:
/*
** Usage:
** list = get_quadratic(x1,y1,x2,y2,x3,y3);
**
** Arguments:
** x1, y1 first point on the parabola
** x2, y2 second point on the parabola
** x3, y3 third point on the parabola
**
** returns:
** list ds_list containing the a, b and c coefficients
** (in that order) of the quadratic equation where
** ax^2 + bx + c = 0
** - OR -
** -1 when no solution can be found.
*/
var x1, x2, x3, y1, y2, grid, list, D, val;
x1 = argument0; y1 = argument1;
x2 = argument2; y2 = argument3;
x3 = argument4; y3 = argument5;
grid = ds_grid_create(3,4); list = ds_list_create();
ds_grid_set(grid, 0, 0, sqr(x1)); ds_grid_set(grid, 1, 0, sqr(x2)); ds_grid_set(grid, 2, 0, sqr(x3));
ds_grid_set(grid, 0, 1, x1); ds_grid_set(grid, 1, 1, x2); ds_grid_set(grid, 2, 1, x3);
ds_grid_set(grid, 0, 2, 1); ds_grid_set(grid, 1, 2, 1); ds_grid_set(grid, 2, 2, 1);
ds_grid_set(grid, 0, 3, y1); ds_grid_set(grid, 1, 3, y2); ds_grid_set(grid, 2, 3, y3);
D = ds_grid_get(grid, 0, 0)*(ds_grid_get(grid, 1, 1)*ds_grid_get(grid, 2, 2)
-ds_grid_get(grid, 1, 2)*ds_grid_get(grid, 2, 1))
-ds_grid_get(grid, 1, 0)*(ds_grid_get(grid, 0, 1)*ds_grid_get(grid, 2, 2)
-ds_grid_get(grid, 0, 2)*ds_grid_get(grid, 2, 1))
+ds_grid_get(grid, 2, 0)*(ds_grid_get(grid, 0, 1)*ds_grid_get(grid, 1, 2)
-ds_grid_get(grid, 0, 2)*ds_grid_get(grid, 1, 1));
if(D==0)return-1;
val = (ds_grid_get(grid, 0, 3)*(ds_grid_get(grid, 1, 1)*ds_grid_get(grid, 2, 2)
-ds_grid_get(grid, 1, 2)*ds_grid_get(grid, 2, 1))
-ds_grid_get(grid, 1, 3)*(ds_grid_get(grid, 0, 1)*ds_grid_get(grid, 2, 2)
-ds_grid_get(grid, 0, 2)*ds_grid_get(grid, 2, 1))
+ds_grid_get(grid, 2, 3)*(ds_grid_get(grid, 0, 1)*ds_grid_get(grid, 1, 2)
-ds_grid_get(grid, 0, 2)*ds_grid_get(grid, 1, 1)))/D
ds_list_add(list, val);
val = (ds_grid_get(grid, 0, 0)*(ds_grid_get(grid, 1, 3)*ds_grid_get(grid, 2, 2)
-ds_grid_get(grid, 1, 2)*ds_grid_get(grid, 2, 3))
-ds_grid_get(grid, 1, 0)*(ds_grid_get(grid, 0, 3)*ds_grid_get(grid, 2, 2)
-ds_grid_get(grid, 0, 2)*ds_grid_get(grid, 2, 3))
+ds_grid_get(grid, 2, 0)*(ds_grid_get(grid, 0, 3)*ds_grid_get(grid, 1, 2)
-ds_grid_get(grid, 0, 2)*ds_grid_get(grid, 1, 3)))/D
ds_list_add(list, val);
val = (ds_grid_get(grid, 0, 0)*(ds_grid_get(grid, 1, 1)*ds_grid_get(grid, 2, 3)
-ds_grid_get(grid, 1, 3)*ds_grid_get(grid, 2, 1))
-ds_grid_get(grid, 1, 0)*(ds_grid_get(grid, 0, 1)*ds_grid_get(grid, 2, 3)
-ds_grid_get(grid, 0, 3)*ds_grid_get(grid, 2, 1))
+ds_grid_get(grid, 2, 0)*(ds_grid_get(grid, 0, 1)*ds_grid_get(grid, 1, 3)
-ds_grid_get(grid, 0, 3)*ds_grid_get(grid, 1, 1)))/D
ds_list_add(list, val); ds_grid_destroy(grid);
return list;
This uses Cramer's Rule to find the coefficient (That's why I made a ds_grid). Anyway, improvements and faster methods are welcomed/encouraged!
Definitely
But for simple, GM standards, I think your script is perfect (Since it has the same arguments as draw_ellipse)
Wow impressive stuff, although what the script is doing is way over my head >_<. Thanks a lot, though!
Yeah I'm from long island too, I'll probably be moving out to college next year, but then again I'm not sure which college I plan on attending. All "iffy" stuff.
//point_in_ellipse(point_x, point_y, x1, y1, x2, y2);
var x1, y1, x2, y2, cenx, ceny, major, minor, foc1, foc2, R1, R2;
x1 = min(argument2, argument4); y1 = min(argument3, argument5);
x2 = max(argument2, argument4); y2 = max(argument3, argument5);
cenx = x1 +(x2-x1)/2;
ceny = y1 +(y2-y1)/2;
major = max(x2-x1, y2-y1);
minor = min(x2-x1, y2-y1);
if(major==(x2-x1)) {
foc1 = cenx -sqrt(sqr(major/2) - sqr(minor/2));
foc2 = cenx +sqrt(sqr(major/2) - sqr(minor/2));
R1 = point_distance(argument0, argument1, foc1, ceny);
R2 = point_distance(argument0, argument1, foc2, ceny);
} else {
foc1 = ceny -sqrt(sqr(major/2) - sqr(minor/2));
foc2 = ceny +sqrt(sqr(major/2) - sqr(minor/2));
R1 = point_distance(argument0, argument1, cenx, foc1);
R2 = point_distance(argument0, argument1, cenx, foc2);
}
return(R1+R2 <= major);
I'm sure there are plenty of things that can be made more efficient, but it still works, so there.
Oh. nvm then ^o^
hehe.. it was only natural I would come for you, ;p
Yeah, I've been getting suggestions about making that, and have been tweaking with methods on how to do it. Guess I'll take the advice and just do it T-T
OK.. so usually when I try to create destructible terrain for my projects, I simply use surfaces and sprites, for example.
var surf;
surf = surface_create(room_width,room_height);
surface_set_target(surf);
draw_clear(c_black,1);
draw_sprite(sprite_index,0,0,0);
draw_set_color(c_black);
draw_circle(mouse_x,mouse_y,50,0);
surface_reset_target();
sprite_delete(sprite_index);
sprite_index = sprite_create_from_surface(...);
surface_free(surf);
And that's a usually fast method for me, since I use it once every time I click somewhere. However.. I've come up with a new concept for a game, which will have a unique method of destructible terrain.
Basically, instead of destroying terrain when you do something once, in this project, I want to destroy all the terrain farther than a certain radius, from a certain object. So basically..
Everything outside of those green circles, would not be visible. I also need to have collision detection, so I have to also have it as a mask (unless there's some other way to achieve this) and thus, I've come here. Currently, what I'm doing is using the following code.
var surf1, surf2;
surf1 = surface_create(room_width,room_height);
surf2 = surface_create(room_width,room_height);
surface_set_target(surf1);
draw_clear(c_black);
draw_set_blend_mode(bm_subtract);
draw_circle(mouse_x,mouse_y,50,0);
draw_set_blend_mode(bm_normal);
surface_set_target(surf2);
draw_clear(c_black);
draw_sprite(sprite0,0,0,0);
draw_surface(surf1,0,0);
surface_reset_target();
sprite_delete(sprite_index);
sprite_index = sprite_create_from_surface(surf2,0,0,room_width,room_height,1,1,0,0,0,0);
surface_free(surf1);
surface_free(surf2);
It works perfectly, but it utterly RAPES my fps. So.. I need another method of achieving this.
-------------------------------------------------------------------------
Also, I'm certain that the main reason causing the problem is the sprite_create_from_surface, so if anyone has any solutions that avoid using them, please comment. Thanks.
-------------------------------------------------------------------------
Uploaded a side GMK with my code. You can see the problem first hand.. click
Thanks for reading.
After using this a lot, and learning something from torigara over at the GMC, here's an optimization of the script.
/*
** Usage:
** map_rooms(ds_map)
**
** Arguments:
** ds_map map to which all rooms are loaded.
**
** Notes:
** Fills the map with {key=name, val=index} pairs.
** To find the maximum number of rooms, it creates an extra
** room. The name of this room will be added to the map
** unless a room with the same name already exists.
**
** Returns:
** the index of the created room
**
** GMLscripts.com
*/
{
var i,ds_map;
ds_map = argument0
for (i=room_first;i>=0;i=room_next(i)) {
if (room_exists(i)) {
ds_map_add(ds_map,room_get_name(i),i);
}
}
}
Does the same thing as the original script, it just doesn't need to create an extra room to accomplish it.
Pages: 1