reading BMAP's

Posted By: Nowherebrain

reading BMAP's - 07/11/09 12:27

I'm having some issues with reading hit.skin2...I just simply don't know how to return the values from it....lol here is what I am basically trying to accomplish....
Code:
function get_ambient()
{
	c_trace(my.x,vector(my.x,my.y,(my.z - 500)),IGNORE_ME|IGNORE_PASSABLE|IGNORE_SPRITES|SCAN_TEXTURE);
	my.ambient = -55;
	my.ambient = my.ambient + ((hit.red + hit.green + hit.blue) / 3);
}


I want to read from skin 2 though...any pointers would be appreciated.
Posted By: Nowherebrain

Re: reading BMAP's - 07/11/09 12:58

The following is out of the manual. If you search for "hit", so this is telling me that it is already reading the second skin, but I can tell it is not.

"hit.blue,green,red... Pixel color of the second texture (f.i. a lightmap) at the contact position, for 24-bit textures only."
I want to return the values from hit.skin2.

Posted By: EvilSOB

Re: reading BMAP's - 07/11/09 13:03

According to the manual, hit.blue/green/red IS from the second skin.
Or do I misunderstand the question?

(note, you arent checking a hit was made before changing values in your example)

[EDIT] you posted while I was typing.
But according the the manual blah, blah, again.

ANOTHER way would be to...(untested code)
Code:
function get_ambient()
{
	c_trace(my.x,vector(my.x,my.y,(my.z - 500)),IGNORE_ME|IGNORE_PASSABLE|IGNORE_SPRITES|SCAN_TEXTURE);
	my.ambient = -55;
	/////
	var fmt, pxl;  COLOR tmpC;
	fmt = bmap_lock(hit.skin2,0);
	pxl = pixel_for_bmap(hit.skin2,hit.u1,hit.v1);
	bmap_unlock(hit.skin2);
	pixel_to_vec(tmpC, NULL, fmt, pxl);
	/////	
	my.ambient = my.ambient + ((tmpC.red + tmpC.green + tmpC.blue) / 3);
}
//


Posted By: Nowherebrain

Re: reading BMAP's - 07/11/09 13:30

EvilSOB to the rescue again.
Copy>Paste>test...brb
Posted By: Pappenheimer

Re: reading BMAP's - 07/11/09 13:36

Does this mean the code was okay, but the trace was too short?^^
Posted By: Nowherebrain

Re: reading BMAP's - 07/11/09 14:11

Getting a crash invalid pointer>then crash inside the function.....I have company over now...will check more later.
Posted By: EvilSOB

Re: reading BMAP's - 07/11/09 14:57

Couple of ideas, for when you get back to it.

1> You werent checking for a valid hit...
Code:
function get_ambient()
{
	var fmt, pxl;  COLOR tmpC;
	c_trace(my.x,vector(my.x,my.y,(my.z - 500)),IGNORE_ME|IGNORE_PASSABLE|IGNORE_SPRITES|SCAN_TEXTURE);
	if(trace_hit)
	{
		my.ambient = -55;
		fmt = bmap_lock(hit.skin2,0);
		pxl = pixel_for_bmap(hit.skin2,hit.u1,hit.v1);
		bmap_unlock(hit.skin2);
		pixel_to_vec(tmpC, NULL, fmt, pxl);
		my.ambient = my.ambient + ((tmpC.red + tmpC.green + tmpC.blue) / 3);
	}
}
//


2> Does a second skin even exists if it is a WED block? This could generate the error.
Posted By: Nowherebrain

Re: reading BMAP's - 07/11/09 15:42

I am getting the vec color from a terrain(hmp)and yes a second skin exists.

I do not understand the following line....
var fmt, pxl; COLOR tmpC;
the "var" seems to be an array???I'm not a well rounded programmer..lol
I'm guessing "COLOR" is a "C" prdefined vector.
should there be a "wait" in there for bmap_unlock/lock?
I am calling this from the same player action you helped me with before BTW...
Posted By: Nowherebrain

Re: reading BMAP's - 07/11/09 15:57

Here is the entire piece.
Code:
var run_speed = 550;

function get_ambient()
{
	//	c_trace(my.x,vector(my.x,my.y,(my.z - 500)),IGNORE_ME|IGNORE_PASSABLE|IGNORE_SPRITES|SCAN_TEXTURE);
	//	my.ambient = -55;
	//	my.ambient = my.ambient + ((hit.red + hit.green + hit.blue) / 3);

	var fmt, pxl; COLOR tmpC;

	c_trace(my.x,vector(my.x,my.y,(my.z - 500)),IGNORE_ME|IGNORE_PASSABLE|IGNORE_SPRITES|SCAN_TEXTURE);
	if(trace_hit)
	{
		my.ambient = -55;
		fmt = bmap_lock(hit.skin2,0);
		pxl = pixel_for_bmap(hit.skin2,hit.u1,hit.v1);
		bmap_unlock(hit.skin2);
		pixel_to_vec(tmpC, NULL, fmt, pxl);
		my.ambient = my.ambient + ((tmpC.red + tmpC.green + tmpC.blue) / 3);
	}
}
//




action guss()
{

	var anim_cycle;
	var ground_dist;
	VECTOR ground_00;
	
	player = my;
	c_updatehull(my,11);
	wait(1);
	//	set(my,SHADOW);
	my.material = mat_alphatest;
	while(1)
	{
		player_exists = 1;
		get_ambient();///////here I call it, obviously
		
		c_trace(my.x,vector(my.x,my.y,(my.z - 500)),IGNORE_ME|IGNORE_PASSABLE|IGNORE_SPRITES);//|USE_BOX
		if(hit.z != 0)
		{
			hit.z += 24;
			player.z = hit.z;
		}

		
		if(key_w == 1)
		{
			c_move(my,vector(run_speed*time_step/16,0,0),nullvector,IGNORE_PASSABLE|IGNORE_SPRITES|GLIDE);
			
			ent_animate(my,"run",anim_cycle,ANM_CYCLE);
			anim_cycle += 10 * time_step;
			anim_cycle %= 100;
		}
		
		if(key_any == 0)
		{
			ent_animate(my,"stand",anim_cycle,ANM_CYCLE);
			anim_cycle += 8 * time_step;
			anim_cycle %= 100;
		}
		
		my.pan -= mouse_force.x + mouse_force.x;
		
		wait(1);
	}
}


Posted By: Widi

Re: reading BMAP's - 07/11/09 16:13

var fmt, pxl; COLOR tmpC;

is the same as:

var fmt;
var pxl;
COLOR tmpC;

And yes, COLOR is a Vector (tmpC.red, tmpC.green, tmpC.blue)
Posted By: Nowherebrain

Re: reading BMAP's - 07/11/09 16:24

thank you...I considered the fact that as long as I do not assign a value to a var I can go on forever(just about).
var ah, ba, ca, da, ga, ma, re = 0;
that would initialize all to 0 correct? or am I on some sort of drug?
Posted By: Widi

Re: reading BMAP's - 07/11/09 16:37

No, use
var ah = 0, ba = 0, da = 14, ga =15325678, ma = 4;
Posted By: Nowherebrain

Re: reading BMAP's - 07/11/09 17:35

ok, thanks.

I'm still getting these errors...I have no idea why...
Empty pointer...thought it was player, but I moved the code to the players action and I get the same result...no surprise really.
The second skin also exists...so that should not be the cause.
Finally the BMAP is not locked or messed with unless c_trace hit something so....I am at a loss.
I will read some more...
Posted By: EvilSOB

Re: reading BMAP's - 07/11/09 17:51

The big question is, does it work?
It wont work for the wiki's "Terrain MultiTex" terrain. Here

If thats the case, use this
Code:
var fmt, pxl; COLOR tmpC;

	c_trace(my.x,vector(my.x,my.y,(my.z - 500)),IGNORE_ME|IGNORE_PASSABLE|IGNORE_SPRITES|SCAN_TEXTURE);
	if(trace_hit)
	{
		my.ambient = -55;
		BMAP* shadows = ent_getskin(you,3);  //<<shadowmap skin number
		fmt = bmap_lock(shadows,0);
		pxl = pixel_for_bmap(shadows,hit.u1,hit.v1);
		bmap_unlock(shadows);
		pixel_to_vec(tmpC, NULL, fmt, pxl);
		my.ambient = my.ambient + ((tmpC.red + tmpC.green + tmpC.blue) / 3);
	}


Posted By: Nowherebrain

Re: reading BMAP's - 07/11/09 17:57

No, but I am using a multitexture shader, skin2 is the shadow map.
I moved it into the terrain action and replaced my with player.
I also changed hit.skin2 to my.skin2...which is giving me new problems....
I will try this. I may need to find a new method..I have pent all day trying to get this working.
Posted By: Nowherebrain

Re: reading BMAP's - 07/11/09 18:02

Yes, that was it....so setting a bmap pointer to the appropriate entskin....
good thinking, thank you...I'm sorry you practically wrote this for me.....give me a heads up if I can give you a hand with something sometime...like a mafia thing.
Posted By: EvilSOB

Re: reading BMAP's - 07/11/09 18:13

Sounds like youre going the wrong way, this should go into the PLAYER action.
And you have to stick with HIT.skin2 as the entity structure doesnt have a
skin1 or skin2 property.

I take it your trying to get your player to change his brightness according
to the ground (shadowmap) underneath him.

Try this, just before the wait(1) at the end of the player-action main loop.
Code:
...
my.ambient = -55;
var fmt, pxl;	COLOR tmpC;
you = NULL;
c_trace(my.x,vector(my.x,my.y,(my.z - 500)),IGNORE_ME|IGNORE_PASSABLE|IGNORE_MAPS|IGNORE_MODELSS|IGNORE_SPRITES|SCAN_TEXTURE);
if(you)
{
	fmt = bmap_lock(hit.skin2,0);
	pxl = pixel_for_bmap(hit.skin2,hit.u2,hit.v2);
	bmap_unlock(hit.skin2);
	pixel_to_vec(tmpC, NULL, fmt, pxl);
	my.ambient = my.ambient + ((tmpC.red + tmpC.green + tmpC.blue) / 3);
}
...
...


Posted By: Nowherebrain

Re: reading BMAP's - 07/11/09 18:40

I wanted to keep it separate as I will likely call it for many models during their first few frames(static models)...I initially am setting it for the player..who in time will get it called only at key intervals...key_pressed/key_any or whatever best will suit it.
here is how I set it now...
Code:
function player_ambient()
{
var fmt, pxl; COLOR tmpC;

	c_trace(my.x,vector(my.x,my.y,(my.z - 500)),IGNORE_ME|IGNORE_PASSABLE|IGNORE_SPRITES|SCAN_TEXTURE);
	if(trace_hit)
	{
		my.ambient = -120;
		BMAP* shadows = ent_getskin(you,2);  //<<shadowmap skin number
		fmt = bmap_lock(shadows,0);
		pxl = pixel_for_bmap(shadows,hit.u1,hit.v1);
		bmap_unlock(shadows);
		pixel_to_vec(tmpC, NULL, fmt, pxl);
		my.ambient = my.ambient + ((tmpC.red + tmpC.green + tmpC.blue) / 3) * 0.784;
	}
	
}


Posted By: EvilSOB

Re: reading BMAP's - 07/11/09 18:58

Aha, so its working well. Tis good.
Catch ya round...
Posted By: Nowherebrain

Re: reading BMAP's - 07/11/09 20:34

Yes thank you.
© 2024 lite-C Forums