Gamestudio Links
Zorro Links
Newest Posts
Blobsculptor tools and objects download here
by NeoDumont. 03/28/24 03:01
Issue with Multi-Core WFO Training
by aliswee. 03/24/24 20:20
Why Zorro supports up to 72 cores?
by Edgar_Herrera. 03/23/24 21:41
Zorro Trader GPT
by TipmyPip. 03/06/24 09:27
VSCode instead of SED
by 3run. 03/01/24 19:06
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (degenerate_762), 1,098 guests, and 2 spiders.
Key: Admin, Global Mod, Mod
Newest Members
sakolin, rajesh7827, juergen_wue, NITRO_FOREVER, jack0roses
19043 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 2 of 3 1 2 3
Re: How to randomly modify many entities that have the same model? [Re: joao13pt] #423943
06/08/13 15:48
06/08/13 15:48
Joined: Mar 2013
Posts: 30
Portugal
J
joao13pt Offline OP
Newbie
joao13pt  Offline OP
Newbie
J

Joined: Mar 2013
Posts: 30
Portugal
Now that cloning meshes works, their skins won't clone
I generated 200 randomly deformed, completelly diferent asteroids side by side, and slowed the skin modifying process so that i could se with my own eyes, in "slow motion" what hapenned
The result was ALL of the entities that started from the asteroid.mdl, shared the same skin
below im posting 2 screenshots, observe how all of the "asteroids" always have the same color




Re: How to randomly modify many entities that have the same model? [Re: joao13pt] #423948
06/08/13 16:32
06/08/13 16:32
Joined: Jan 2002
Posts: 4,225
Germany / Essen
Uhrwerk Offline
Expert
Uhrwerk  Offline
Expert

Joined: Jan 2002
Posts: 4,225
Germany / Essen
joao13pt, please, we cannot guess your mistakes. If you want us to help you gotta post your code.


Always learn from history, to be sure you make the same mistakes again...
Re: How to randomly modify many entities that have the same model? [Re: Uhrwerk] #423953
06/08/13 17:12
06/08/13 17:12
Joined: Mar 2013
Posts: 30
Portugal
J
joao13pt Offline OP
Newbie
joao13pt  Offline OP
Newbie
J

Joined: Mar 2013
Posts: 30
Portugal
Fair enough, my mistake, sorry

Code:
BMAP* texture2 = "empty.bmp";

//first, i start with this function (ignore the name) its job is to 
//color a square sized bitmap randomly, im 99% shure my problem doesn't come from this function. 
//Notice it doesn't return anything

void bmap_square_drawColor(BMAP* bmap, var alpha)
{
	var format = bmap_lock(bmap, 0);
	var pixel;
	var width = bmap_width(bmap);
	var height = bmap_height(bmap);
	var i, j;
	
	for(j=0 ; j < width ; j++)
	{
		pixel = pixel_for_vec(vector(random(255),random(255),random(255)), alpha, format);
		for(i=0 ; i< width ; i++)
		{
			pixel = pixel_for_vec(vector(random(255),random(255),random(255)), alpha, format);
			pixel_to_bmap(bmap, i, j, pixel);
		}
	}
	bmap_unlock(bmap);
	
}

//then there's the function to deform the initial cubes 
//into smaller randomly deformed spheres, actually

function cube_deform(ENTITY* model, var ray) 
{
  int i = ent_status(model,0); 
  for (; i>0; i--) 
{    														 
  	CONTACT* c = ent_getvertex(model,NULL,i);   
  	vec_normalize(c.x, ray);
  	c.y += random(50)-50;
  	c.z += random(50)-50;
  	c.v = NULL;   // set c.v to NULL to change c.x,y,z 
  	ent_setvertex(model,c,i);					 
  	}
  	
	ent_fixnormals(model, 0); // fix the not updating shading (shadow) on the model

}

//these next 2 functions serve to generate the entities
//call on them cube_deform() and bmap_square_drawColor()

function asteroid_modify(ENTITY* ast_i)
{
	set(ast_i,SHADOW);
	cube_deform(ast_i, (100 + random(50)));
	ast_i.scale_x = 0.05;
	ast_i.scale_y= 0.05;
	ast_i.scale_z = 0.05;
	ent_cloneskin(ast_i);
	bmap_square_drawColor(texture2, 255);
	ent_setskin(ast_i,texture2,1);
}

function generate_asteroids()
{
	ENTITY* asteroid[200]; //initialize asteroid array
	int i;
	for (i=0 ; i<200 ; i++)
		{
			asteroid[i] = ent_create("cube_small.mdl", vector(500,(0 + 20*i),0), NULL);
			ent_clone(asteroid[i]);
			wait(40);
			bmap_square_drawColor(texture2, 255);
			asteroid_modify(asteroid[i]);
		}
}



So, it should be: for each new asteroid in the array, when reading asteroid_modify(), first they're deformed, then scaled down, then their skin is cloned (not needed, but i used it anyway), then i call on their skin (texture2) bmap_square_drawColor() to randomly color each of them, then i set this modified skin as each of the entities's skin (texture2 after bmap_square_drawColor() being called on it)

since i call
Code:
ent_cloneskin(ast_i);
bmap_square_drawColor(texture2, 255);
ent_setskin(ast_i,texture2,1);


for each asteroid in the array, each one of them should be stuck with a diferently coloured texture2, shouldn't it?

EDIT: i know the code is a mess, and it isn't even complete, its way to big and messy, good luck finding the mistake (i know there's one somewhere)
And thank you

Last edited by joao13pt; 06/08/13 17:15.
Re: How to randomly modify many entities that have the same model? [Re: joao13pt] #423959
06/08/13 18:43
06/08/13 18:43
Joined: Mar 2012
Posts: 927
cyberspace
W
Wjbender Offline
User
Wjbender  Offline
User
W

Joined: Mar 2012
Posts: 927
cyberspace
Hi , i did not look into your code but wanted to ask if
you know how to use random_seed

If not then your color will be the same always anyway i think.


Compulsive compiler
Re: How to randomly modify many entities that have the same model? [Re: joao13pt] #423960
06/08/13 18:51
06/08/13 18:51

M
Malice
Unregistered
Malice
Unregistered
M



I can't test right now but does this work ?


Code:
BMAP* bmp_temp;
function asteroid_modify(ENTITY* ast_i)
{
        ast_i = ent_cloneskin(ast_i); // doesn't seem needed.
        bmp_temp = ent_getskin(ast_i,1);
	bmap_square_drawColor(bmp_temp, 255);
        wait_for(bmp_square_drawColor);
	ent_setskin(ast_i,bmap_temp,1);

	set(ast_i,SHADOW);
	cube_deform(ast_i, (100 + random(50)));
	ast_i.scale_x = 0.05;
	ast_i.scale_y= 0.05;
	ast_i.scale_z = 0.05;
	}

ENTITY* asteroid[200]; //initialize asteroid array
// Don't think you have to move the array to global but might be part of the problem.

function generate_asteroids()
{
		int i;
	for (i=0 ; i<200 ; i++)
		{
			asteroid[i] = ent_create("cube_small.mdl", vector(500,(0 + 20*i),0), NULL);
			ent_clone(asteroid[i]);
			wait(40);
			//bmap_square_drawColor(texture2, 255); // why 2 calls?
			asteroid_modify(asteroid[i]);
		}
}



Ok I'm just guessing and off-the-cuff trying to figure it out. If this helps, Great! if not some else probably knows better.

One thing I don't know is if after a clone the entity have a new pointer... does ent_clone(x) after the shifted entity still points to 'x' ?

@wjbender - I though random start the game (first call) at the same number not every call, is that wrong?

Last edited by Malice; 06/08/13 19:00.
Re: How to randomly modify many entities that have the same model? [Re: ] #423963
06/08/13 19:15
06/08/13 19:15
Joined: Mar 2013
Posts: 30
Portugal
J
joao13pt Offline OP
Newbie
joao13pt  Offline OP
Newbie
J

Joined: Mar 2013
Posts: 30
Portugal
@wjbender - Im completelly shure that this problem doesnt come there, i've tested it myself, thanks for the help anyways, every opinion is apreciatted here smile

@Malice - It's a good ideia, but in that array, each entity had its own clone, so even if the clone and the original have the same pointer, it wouldn't make sense for the skin to still be shared by ALL the entities with the same model, specially after i did that ent_clone.

-------------------- EDIT --------------------

I had to make a few changes to the code you wrote, because if i do this
bmp_tmp = ent_getskin(ast_i)
the function that colours the bitmaps will fail, because i think
bmap_lock(bmap, 0);
will return an error or something
but it dind't work anyways, i'll keep on trying till it works

Last edited by joao13pt; 06/08/13 19:27.
Re: How to randomly modify many entities that have the same model? [Re: joao13pt] #423967
06/08/13 19:43
06/08/13 19:43
Joined: Mar 2012
Posts: 927
cyberspace
W
Wjbender Offline
User
Wjbender  Offline
User
W

Joined: Mar 2012
Posts: 927
cyberspace
@malice im not staking my life on this statement but i almost think (if started the same everytime) that subsequent random results would follow same pattern unlesa random_seed(0) were used ..feel free to correct me.

@joa you could ignore this reply if you tested as said.. Dont want to derail

Last edited by Wjbender; 06/08/13 19:45.

Compulsive compiler
Re: How to randomly modify many entities that have the same model? [Re: Wjbender] #423970
06/08/13 20:11
06/08/13 20:11
Joined: Jan 2002
Posts: 4,225
Germany / Essen
Uhrwerk Offline
Expert
Uhrwerk  Offline
Expert

Joined: Jan 2002
Posts: 4,225
Germany / Essen
Ok, bmap_square_drawColor is generating a noise texture. I don't know if this is your original intention. A simple fill of the whole bitmap might be easier to identify as different for a start. But that's not the point.

The error is in here:
Code:
function asteroid_modify(ENTITY* ast_i)
{
	[...]
	ent_cloneskin(ast_i);
	bmap_square_drawColor(texture2, 255);
	ent_setskin(ast_i,texture2,1);
}


First you clone the entity and then you assign the same skin to all of them with ent_setskin. That does not make any sense at all. You have to call bmap_square_drawColor on every individual skin of the entities. You can grab the sking with bmap_for_entity. ent_setskin sets the skin as the name says. It does not copy any content.


Always learn from history, to be sure you make the same mistakes again...
Re: How to randomly modify many entities that have the same model? [Re: Wjbender] #423973
06/08/13 20:21
06/08/13 20:21
Joined: Mar 2013
Posts: 30
Portugal
J
joao13pt Offline OP
Newbie
joao13pt  Offline OP
Newbie
J

Joined: Mar 2013
Posts: 30
Portugal
I'VE GOT IT! grin
Thank you for your help, all of you!
I'll explain:
intially, i declared the bitmap BMAP* texture2 = "empty.bmp"
empty is a totally white 256x256 bitmap
the thing is, by setting the skin of 200 different entities to the same texture2, would, obviously make them all have the exact same skin
So i thought about this, and then i remembered bmap_createblack, which creates a black bitmap, with whatever size and format i want
eventhough i repetead the bmap declaration at the start of the script, i did something diferent:
instead of
BMAP* texture2 = "some image file";
i did this
BMAP* texture;
then, in the function that colours the bitmaps, i did some changes too

Code:
void bmap_create_draw(ENTITY* ent, var alpha)
{
	texture = bmap_createblack(256, 256, 888);
	
	var format = bmap_lock(texture, 0);
	var pixel;
	var width = bmap_width(texture);
	var height = bmap_height(texture);
	var i, j;
	
	for(j=0 ; j < width ; j++)
	{
		pixel = pixel_for_vec(vector(random(255),random(255),random(255)), alpha, format);
		for(i=0 ; i< width ; i++)
		{
			pixel = pixel_for_vec(vector(random(255),random(255),random(255)), alpha, format);
			pixel_to_bmap(texture, i, j, pixel);
		}
	}
	bmap_unlock(texture);
	
	ent_setskin(ent, texture, 1);
	
}



the algorithm's pretty much what it was initially, but now as an argument i use the pointer to the entity i want to have the skin being coloured, so that in the end i can do this
ent_setskin(ent, texture, 1);
and here's the main diference
texture = bmap_createblack(256, 256, 888);
the previously declared BMAP* texture; is now "generated" multiple times as a black bitmap, which is later coloured and skinned in one of the randomly generated and deformed asteroid entities
it works perfectly, now i have the basis to make these so called "asteroids" more realistic and generate them more dinamically

Re: How to randomly modify many entities that have the same model? [Re: joao13pt] #423974
06/08/13 20:23
06/08/13 20:23
Joined: Jan 2002
Posts: 4,225
Germany / Essen
Uhrwerk Offline
Expert
Uhrwerk  Offline
Expert

Joined: Jan 2002
Posts: 4,225
Germany / Essen
You don't need to use bmap_createblack. Use bmap_for_entity instead.


Always learn from history, to be sure you make the same mistakes again...
Page 2 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