Particles in 3d
#1
Posted 06 July 2012 - 10:32 AM
I was thinking about efficiency as well since we all know gm is kinda slow on drawing polys and having a lot of little models won`t prove to be too fast.
#2
Posted 06 July 2012 - 12:16 PM
Still, if is a top-down camera you could use normal floors, small ones; avoid to call everytime d3d_draw_floor, instead make a model at the begin with d3d_model_floor and use it for every particle, is way faster!
To get the particle position you dont need to make a lot of objects, that would lag a lot, make a single object, with a 3d array eg. ParticleArray[1,1,1]; ParticleArray[2,2,2]; ParticleArray[3,3,3] etc...
So the 1,1,1 will be xyz of the 1, 2,2,2 will be the xyz of the 2, and so on...
Atleast this would be the way i would do i case i need particles, maybe isnt the best one but give it a try!
#3
Posted 06 July 2012 - 02:27 PM
#4
Posted 06 July 2012 - 03:07 PM
Iccurd told me that objects aren't the main source of particle lag, so using an array wouldn't help. He said the lag is the seperate calls to d3d_draw_ floor.particles in GM's built-in 3d are slow, i think there's no way to make it efficient...
Still, if is a top-down camera you could use normal floors, small ones; avoid to call everytime d3d_draw_floor, instead make a model at the begin with d3d_model_floor and use it for every particle, is way faster!
To get the particle position you dont need to make a lot of objects, that would lag a lot, make a single object, with a 3d array eg. ParticleArray[1,1,1]; ParticleArray[2,2,2]; ParticleArray[3,3,3] etc...
So the 1,1,1 will be xyz of the 1, 2,2,2 will be the xyz of the 2, and so on...
Atleast this would be the way i would do i case i need particles, maybe isnt the best one but give it a try!
He goes into more detail here, and posts an idea of how to speed things up: http://gmc.yoyogames...l=&fromsearch=1
#5
Posted 06 July 2012 - 06:23 PM
Despite that, don't make too many objects. in GM, even empty objects slightly slow your game. If they have sprites/use collision detect, the problem is far, far worse.Iccurd told me that objects aren't the main source of particle lag, so using an array wouldn't help. He said the lag is the seperate calls to d3d_draw_ floor.
One thing to notice is that you can make a single "particle" model facing toward the camera at the beginning of each draw phase, then draw it for each particle without rotation or translation. Scaling can be used for changing particle size.He goes into more detail here, and posts an idea of how to speed things up: http://gmc.yoyogames...l=&fromsearch=1
Some other things to note: icuurd's solution checks visibility for every particle, every step, even after they are too far away to be seen. Consider destroying each particle as it leaves the visible area.
#6
Posted 15 July 2012 - 01:41 PM
Just want to clarify one thing, array[x,y,z] don't work that way. the [x,y,z] values in the array refers to the position in a 3d array where a value is stored, the [x,y,z] are not the actual values.
if he were to make an array to store the values, it would look like this:
particle[0,0] = x
particle[0,1] = y
particle[0,2] = z
particle[1,0] = xx
particle[1,1] = yy
particle[1,2] = zz
the first argument in the array refers to which particle we are defining the position of, and the second one refers to if it's x, y, or z that we are defining.
Edited by Pandaboy, 15 July 2012 - 01:46 PM.
#7
Posted 16 July 2012 - 08:42 AM
Really? Isnt particle[0] a value, Isnt particle[0,0] another, Isnt particle[0,0,0] another one? :|@RevenantGhost
Just want to clarify one thing, array[x,y,z] don't work that way. the [x,y,z] values in the array refers to the position in a 3d array where a value is stored, the [x,y,z] are not the actual values.
if he were to make an array to store the values, it would look like this:
particle[0,0] = x
particle[0,1] = y
particle[0,2] = z
particle[1,0] = xx
particle[1,1] = yy
particle[1,2] = zz
the first argument in the array refers to which particle we are defining the position of, and the second one refers to if it's x, y, or z that we are defining.
#8
Posted 18 July 2012 - 12:09 AM
Really? Isnt particle[0] a value, Isnt particle[0,0] another, Isnt particle[0,0,0] another one? :|
@RevenantGhost
Just want to clarify one thing, array[x,y,z] don't work that way. the [x,y,z] values in the array refers to the position in a 3d array where a value is stored, the [x,y,z] are not the actual values.
if he were to make an array to store the values, it would look like this:
particle[0,0] = x
particle[0,1] = y
particle[0,2] = z
particle[1,0] = xx
particle[1,1] = yy
particle[1,2] = zz
the first argument in the array refers to which particle we are defining the position of, and the second one refers to if it's x, y, or z that we are defining.
yes, and no. particle[0] and particle[0,0] can never be part of the same array, because particle[0] is a one-dimensional array and particle[0,0] is two-dimensional.
A one dimensional array, written as array[a], is like a list. the number inside the [] is the row on the list where the value is stored. for example:
//Create event!
array[0] = "Peter Griffin";
array[1] = 47;
array[2] = "beer"
show_message("hi, my name is "+array[0]+", I'm "+string(array[1])+" years old and I like "+array[2]);
//This will show the message: "Hi, my name is Peter Griffin, I'm 47 years old and I like beer"A two-dimensional array is like a grid, written as array[a,b], where a,b is the coordinates on the grid where the value is stored. You can see it as a collection of different lists, where A is the list number, and B is the row of the currently selected list. So each particle will have it's own "list" (A), and a bunch of different "rows" (
so to create 10 different circles, at different positions, with different sizes and colors, this is what you do (and the same way you would keep track of the particle x,y and z, and even color and size if you wanted to):
//CREATE EVENT
//Creating a 2 dimensional array that will be used to draw 10 different circles
var i;
i = 0;
repeat(10) {
array[i,0] = random(room_width); //x
array[i,1] = random(room_height); //y
array[i,2] = random_range(4,16); //size
array[i,3] = make_color_rgb(random(255),random(255),random(255)); //color
i += 1;
}//DRAW EVENT
//Drawing 10 circles from the values in the 2D array
var i, size, color;
i = 0;
repeat(10) {
x = array[i,0];
y = array[i,1];
size = array[i,2];
color = array[i,3];
draw_circle_color(x,y,size,color,color,false);
i += 1;
}3-dimensional arrays, written as array[a,b,c], are rarely used, because a 2-dimensional array is almost always enough. so I won't talk a lot about them ;p
hope that clears it up a bit
Edited by Pandaboy, 18 July 2012 - 12:18 AM.
#9
Posted 18 July 2012 - 12:03 PM
#10
Posted 19 July 2012 - 11:33 PM
http://sandbox.yoyog...frame-animation
#11
Posted 26 July 2012 - 01:46 AM
Oh, then sorry :D I was wrong =)
hehe that's fine, just thought I would clear it up, I also thought arrays worked like that back before I learned how to actually use them ^^!
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users














