Gamestudio Links
Zorro Links
Newest Posts
Data from CSV not parsed correctly
by EternallyCurious. 04/18/24 10:45
StartWeek not working as it should
by Zheka. 04/18/24 10:11
folder management functions
by VoroneTZ. 04/17/24 06:52
lookback setting performance issue
by 7th_zorro. 04/16/24 03:08
zorro 64bit command line support
by 7th_zorro. 04/15/24 09:36
Zorro FIX plugin - Experimental
by flink. 04/14/24 07:48
Zorro FIX plugin - Experimental
by flink. 04/14/24 07:46
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (AndrewAMD), 552 guests, and 1 spider.
Key: Admin, Global Mod, Mod
Newest Members
EternallyCurious, 11honza11, ccorrea, sakolin, rajesh7827
19046 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Make engine change collision box, sprites! #445866
09/28/14 00:19
09/28/14 00:19

M
Malice
Unregistered
Malice
Unregistered
M



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

Last edited by Malice; 09/28/14 00:21.
Re: Make engine change collision box, sprites! [Re: ] #445870
09/28/14 06:49
09/28/14 06:49
Joined: Mar 2012
Posts: 927
cyberspace
W
Wjbender Offline
User
Wjbender  Offline
User
W

Joined: Mar 2012
Posts: 927
cyberspace
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.


Compulsive compiler
Re: Make engine change collision box, sprites! [Re: Wjbender] #445920
09/30/14 04:05
09/30/14 04:05

M
Malice
Unregistered
Malice
Unregistered
M



Ok Thank you. The research will be fun.

Re: Make engine change collision box, sprites! [Re: ] #446411
10/14/14 11:47
10/14/14 11:47
Joined: Mar 2012
Posts: 927
cyberspace
W
Wjbender Offline
User
Wjbender  Offline
User
W

Joined: Mar 2012
Posts: 927
cyberspace

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 ?


Compulsive compiler
Re: Make engine change collision box, sprites! [Re: ] #446420
10/15/14 06:45
10/15/14 06:45
Joined: Oct 2004
Posts: 900
Lgh
rojart Offline
User
rojart  Offline
User

Joined: Oct 2004
Posts: 900
Lgh
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


Regards, Robert

Quote
Everything should be made as simple as possible, but not one bit simpler.
by Albert Einstein

PhysX Preview of Cloth, Fluid and Soft Body

A8.47.1P
Re: Make engine change collision box, sprites! [Re: ] #446432
10/15/14 11:07
10/15/14 11:07
Joined: Mar 2012
Posts: 927
cyberspace
W
Wjbender Offline
User
Wjbender  Offline
User
W

Joined: Mar 2012
Posts: 927
cyberspace
..

Last edited by Wjbender; 10/16/14 15:17.

Compulsive compiler
Re: Make engine change collision box, sprites! [Re: Wjbender] #446446
10/15/14 18:32
10/15/14 18:32

M
Malice
Unregistered
Malice
Unregistered
M



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.

Re: Make engine change collision box, sprites! [Re: ] #446509
10/18/14 18:09
10/18/14 18:09
Joined: Mar 2011
Posts: 3,150
Budapest
sivan Offline
Expert
sivan  Offline
Expert

Joined: Mar 2011
Posts: 3,150
Budapest


Free world editor for 3D Gamestudio: MapBuilder Editor

Moderated by  HeelX, Spirit 

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