Gamestudio Links
Zorro Links
Newest Posts
Change chart colours
by 7th_zorro. 05/11/24 09:25
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (AndrewAMD), 1,187 guests, and 3 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Hanky27, firatv, wandaluciaia, Mega_Rod, EternallyCurious
19051 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
[solved] save hmp problem #450080
04/06/15 12:44
04/06/15 12:44
Joined: Mar 2012
Posts: 927
cyberspace
W
Wjbender Offline OP
User
Wjbender  Offline OP
User
W

Joined: Mar 2012
Posts: 927
cyberspace
hi , i have some problem that i am not able to figure out .
i have a plugin that i wrote with a little function i am working on
to safe a terrain entity out to a .hmp file ,i am using the hmp sdk

i followed the example , as i understood it ,to write this function.

so , my problem is this :
whenever i write out a terrain , the saved .hmp file once opened up
seem to have a complete column of vertices down the left side of the model
which have no height influance at all.

i thought the problem could be the xVerticesNum amount ,but whatever i seem
to do does not fix this,so i am not sure anymore what the problem is.

please help me find where i am messing this up ?


in my dll i have this for my hmp save function

Code:
DLLFUNC int save_hmp(char* filename,ENTITY* terrain)
{
	if(terrain)
	{
		hmpdata hmp;
		int num_skin=_INT(ent_status(terrain,_VAR(8)));
		cSkin *skins=(cSkin*)malloc(sizeof(cSkin)*num_skin);

		hmp.iNumSkins=num_skin;
		hmp.skinlist=skins;

		int total_vertices=_INT(ent_status(terrain,_VAR(0)));
		hmpvertex *verts;

		verts=(hmpvertex*)malloc(sizeof(hmpvertex)*total_vertices);
		for(int i=0;i<total_vertices;i++)
		{
			CONTACT *c=ent_getvertex(terrain,NULL,_VAR(i));
			verts[i].nx=_FLOAT(c->nx);
			verts[i].ny=_FLOAT(c->ny);
			verts[i].nz=_FLOAT(c->nz);
			verts[i].x=_FLOAT(c->x);
			verts[i].y=_FLOAT(c->y);
			verts[i].z=_FLOAT(c->z);
		}

		float x_size=_FLOAT(terrain->max_x-terrain->min_x);
		float y_size=_FLOAT(terrain->max_y-terrain->min_y);
		
		int x_tiles=_INT(ent_status(terrain,_VAR(2)));
		int y_tiles=_INT(ent_status(terrain,_VAR(3)));

		hmp.vlist=verts;
		hmp.vlistsize=total_vertices;
		
		hmp.xVerticesNum = x_tiles+1;
		hmp.bFloor=true;
	
		hmp.fFaceWidth=x_size/x_tiles;
		hmp.fFaceHeight=y_size/y_tiles;

		hmp.v_min.set(0,0,0);
		hmp.v_max.set(0,0,0);
		
		if(hmp.allVertices())
		{
			float x,y,z;
			float nx,ny,nz;
			hmp.vertex (0,x,y,z, nx,ny,nz);

			hmp.v_min.set(x,y,z);
			hmp.v_max.set(x,y,z);

			for ( int i=1;  i < hmp.allVertices(); i++)
			{
				hmp.vertex ( i,x,y,z, nx,ny,nz);
				
				if ( x < hmp.v_min.x) hmp.v_min.x = x;
				if ( y < hmp.v_min.y) hmp.v_min.y = y;
				if ( z < hmp.v_min.z) hmp.v_min.z = z;

				if ( x > hmp.v_max.x) hmp.v_max.x = x;
				if ( y > hmp.v_max.y) hmp.v_max.y = y;
				if ( z > hmp.v_max.z) hmp.v_max.z = z;
			}
		}

		hmp.iNumFrames = 1;
		strcpy(hmp.cFrameName,"Frame0");

		if(save_hmp7(filename,hmp)) return 1;
		else return 0;
	}
	return 0;
}



then in my code to test it i have this

Code:
///////////////////////////////
#include <acknex.h>
#include <default.c>
#include <level.c>
///////////////////////////////

BMAP* height_map="heightmap.bmp";
BMAP* color_map="colormap.bmp";
BMAP* detail="detail.bmp";

////////////////////////////////////////////
/// save_hmp("example.hmp",source_terrain);
int save_hmp(char* filename,ENTITY* terrain);

function main()
{
	vec_set(screen_size,vector(800,600,0));
	level_load("");
	vec_set(camera.x,vector(0,0,500));
	
	///////////////////////
	//test create a terrain 
	ENTITY* terrain=ent_createterrain(height_map,nullvector,32,32,32);
	c_setminmax(terrain);
	wait(1);
	
	int i;
	var height_factor=1;
	for(i=0;i<ent_status(terrain,0);i++)
	{
		CONTACT *pos=ent_getvertex(terrain,NULL,i);
		COLOR * tp=terrain_getpixel(terrain,pos.x,pos.y,height_map);
		var n=tp.blue+tp.red+tp.green/(3*255);
		//pos.z=0.1+(n*height_factor);
		pos.v.y= 0.1+(n*height_factor);
		//pos.v=NULL;
		ent_setvertex(terrain,pos,i);
	}
	c_updatehull(terrain,0);
	wait(1);	
	
	ent_setskin(terrain,color_map,1);
	ent_setskin(terrain,detail,2);
	
	///////////////////
	//save the hmp file
	save_hmp("test.hmp",terrain);
}



when the test code is ran , the terrain vertices are all completely affected.

but the saved hmp file ,model has one complete column to the left ,of unaffected
vertices like ,xVerticeNum needed 1 more for its value ,BUT that isnt it...

edit : correction , they are affected but they seem to be less offset from zero than the rest , I checked my input values again but I cannot find the problem

jb

Last edited by Wjbender; 04/07/15 09:25.

Compulsive compiler
Re: save hmp problem [Re: Wjbender] #450086
04/06/15 14:33
04/06/15 14:33
Joined: Mar 2012
Posts: 927
cyberspace
W
Wjbender Offline OP
User
Wjbender  Offline OP
User
W

Joined: Mar 2012
Posts: 927
cyberspace
I have tried multiple height map images , the problem persists ..

I am not sure if this is a bug , although I fear saying bug because it might be my code somewhere , I do not know I cannot find documentation for the hmp sdk..

this is the result when I run my test code , it looks correct , all vertices at expected positions .



this is the saved hmp file in med , the problem is highlighted in red .



both are viewed approximately the same for comparison.

thanks


Compulsive compiler
Re: save hmp problem [Re: Wjbender] #450135
04/07/15 09:26
04/07/15 09:26
Joined: Mar 2012
Posts: 927
cyberspace
W
Wjbender Offline OP
User
Wjbender  Offline OP
User
W

Joined: Mar 2012
Posts: 927
cyberspace
found the stupid little problem ..


Compulsive compiler

Moderated by  old_bill, Tobias 

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