Make engine change collision box, sprites!

Posted By: Anonymous

Make engine change collision box, sprites! - 09/28/14 00:19

Hi,
I would like to make the engine read a sprite as a model. I want it to bound the object in a box.I would like the engine then to modify the Bbox to exclude full transparent areas, alpha 0.

Correct me if need be, the engine current wraps sprites in a box.
I simply want it to wrap it a in poly mode and to assume no polys at full transparent areas.

Key to image
yellow and black spirit image
white - world space and view through alpha 0 location
red - annotating to show sprite edge
Blue - an attempt to show the bbox
Posted By: Wjbender

Re: Make engine change collision box, sprites! - 09/28/14 06:49

well I don't know if it actually uses a bounding volume
to speed up checks etc for images ,but if it did you
wouldn't have access to it in lite-c and I think
it would be nothing else except width and height of
the image itself anyway ,which is what i believe the
only bound on an image /panel is .

If I understood correct you want to turn the image
in to a mesh ?

if that's the case and you aim at doing it in code ,you can look at "marching squares" algorithm ,wich will
enable you to trace the outline of the shape ,after tracing it you could triangulate the outline and then
convert to a mesh of an entity ,there is however more
than one algorithm to achieve tracing ,you have got
"snakes" and a bunch of stuff that may apply to the
same functionality but I think "the marching squares"
is closest. .

if you are able you could use only the outline shape
and extrusion but this however is way to much work
I think.
Posted By: Anonymous

Re: Make engine change collision box, sprites! - 09/30/14 04:05

Ok Thank you. The research will be fun.
Posted By: Wjbender

Re: Make engine change collision box, sprites! - 10/14/14 11:47


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

//IF YOU ARE USING ONLY RECTANGULAR SHAPES IN THE IMAGE
//THIS SHOULD BE ENOUGH FOR A SIMPLE ALGORITHM

//PS.. i have removed line : ent_clone in dmdl_create_instance of dynamicmodels.c when i coded this example
//so i mention this if something odd happens on your pc wich is'nt happening on mine

//path to tust
#define PRAGMA_PATH "..\\tust"
#include "tust.h"

//just a texture
BMAP* myskin="skin.tga";

//your source bmap
BMAP* source="source.bmp";

void create_quadface(VECTOR* pos,VECTOR* size,DynamicModel* model)
{
	
	/*
		uv mapping coordinates
		----------------------
			   <-U->
		(0,0).........
			  .	    .
			V .       .
			  .       .
			  .........(1,1)
	
	*/
	
	//vertices
	VECTOR v[4];
	
	//upper left
	vec_set(v[0],vector(pos.x+size.x,pos.y+size.x,pos.z));
	
	//upper right
	vec_set(v[1],vector(pos.x+size.x,pos.y-size.x,pos.z));

	//lower left
	vec_set(v[2],vector(pos.x-size.x,pos.y+size.x,pos.z));

	//lower right
	vec_set(v[3],vector(pos.x-size.x,pos.y-size.x,pos.z));

	//left face of quad
	DYNAMIC_FACE face;
	//right face of quad
	DYNAMIC_FACE face1;
	memset(face,0,sizeof(DYNAMIC_FACE));
	memset(face1,0,sizeof(DYNAMIC_FACE));
	//left face
	int i;
	for(i=0;i<3;i++)
	{
		face.v[i].x=v[i].x;
		face.v[i].z=v[i].y;
		face.v[i].y=v[i].z;
	}
	
	//uv coordinates
	//upper left
		face.v[0].u1=0.0;
		face.v[0].v1=0.0;
	//upper right
		face.v[1].u1=1.0;
		face.v[1].v1=0.0;
	//lower left
		face.v[2].u1=0.0;
		face.v[2].v1=1.0;
	
	
	//right face
	int ii=1;
	for(i=0;i<3;i++)
	{
		if(i==0)ii=1;
		if(i==1)ii=3;
		if(i==2)ii=2;
		face1.v[i].x=v[ii].x;
		face1.v[i].z=v[ii].y;
		face1.v[i].y=v[ii].z;
	}

	//uv coordinates
	//upper right
		face1.v[0].u1=1.0;
		face1.v[0].v1=0.0;
	//lower right
		face1.v[1].u1=1.0;
		face1.v[1].v1=1.0;
	//lower left
		face1.v[2].u1=0.0;
		face1.v[2].v1=1.0;
		
	dmdl_add_face(model,&face);
	dmdl_add_face(model,&face1);
	//sys_free(face);
	//sys_free(face1);
	
}

ENTITY* from_bmp()
{
	DynamicModel *model =dmdl_create();
	int tile_size=16;

	int x=0;
	int y=0;
	int area=bmap_width(source)*bmap_height(source);

	var format = bmap_lock(source,0);

	for( ;x<area;x++)
	{
		if(x==bmap_width(source))
		{
			x=0;
			y+=1;
		}
		if(y==bmap_height(source))break;
		
		COLOR pix_color;
		var pix_alpha;
		var pixel=pixel_for_bmap(source,x,y);
		
		pixel_to_vec(pix_color,pix_alpha,format,pixel);
		
		//if you are using alpha channels to determine empty space
		//skip these pixels
		//if(pix_alpha<1) continue;
		
		//or if you are using colors to determine empty space
		//this bmap i used ,used white color as an empty space
		//skip these pixels
		if(pix_color.red==255 && pix_color.green==255 && pix_color.blue=255) continue;
		
		//add a quad in place of pixel
		//you would have to map the x and y to a position + an offset (not done),or transform vertices when done to center around a position
		
		//you have to check first if there is enough vertices/triangles space left before adding a new quad
		//since a quad has two triangles and 4 vertices before welding or whatever ,you may determine that easy
		//the total amount of SOLID pixels WILL effect how many quads there are ,since i am mapping every single pixel to a quad here
		create_quadface(vector(x*tile_size*2,y*tile_size*2,0),vector(tile_size,tile_size,0),model);
	}

	bmap_unlock(source);
	
	DMDLSettings.flags|=DMDL_FIXNORMALS;
	DMDLSettings.flags|=DMDL_OPTIMIZE;
	ENTITY* ent=dmdl_create_instance(model,nullvector,NULL);
	
 	sys_free(model);
 	
 	return ent;
}

function main()
{
	vec_set(screen_size,vector(800,600,0));
	vec_set(screen_color,vector(1,1,1));
	vec_set(sky_color,vector(1,1,1));
	video_window(NULL,NULL,0,"experimental test, map a pixel to a quad face");
	d3d_antialias = 1;
	
	level_load("");
	def_debug();def_debug();def_move();
  	wait(1);
  	
  	ENTITY* ent=from_bmp();
	ent_setskin(ent,myskin,1);
	
	while(1)
	{
		draw_point3d(nullvector,COLOR_RED,100,1);
		wait(1);
	}
	
}



are you not after per pixel collision ?
Posted By: rojart

Re: Make engine change collision box, sprites! - 10/15/14 06:45

Originally Posted By: Malice
...I would like the engine then to modify the Bbox to exclude full transparent areas, alpha 0....

More simple and effective method is to use the physics like pXent_addshape
Posted By: Wjbender

Re: Make engine change collision box, sprites! - 10/15/14 11:07

..
Posted By: Anonymous

Re: Make engine change collision box, sprites! - 10/15/14 18:32

Thank you for the reply. But no need for future replies, I am not working with this engine anymore.
Thank you
Mal


rant - With the state of the engine's dev, I think I am going for good this time. The only reason to stay was the easy scripting and now I am having to learn so much beyond that, it actual is the only feature that had to continual be maintained for me as a user. If 3dgs doesn't want to keep me and my next round of hobby cash(Money Spent on my game dev hobby),I'll go shopping for an engine that is well maintained.
Posted By: sivan

Re: Make engine change collision box, sprites! - 10/18/14 18:09

to rant: tat-tadadada:
https://www.youtube.com/watch?v=A8MO7fkZc5o
© 2024 lite-C Forums