Gamestudio Links
Zorro Links
Newest Posts
loading historical data 1st time
by AndrewAMD. 04/14/23 12:54
Trade at bar open
by juanex. 04/13/23 19:43
Bug in Highpass2 filter
by rki. 04/13/23 09:54
Adding Limit Orders For IB
by scatters. 04/11/23 16:16
FisherN
by rki. 04/11/23 08:38
AUM Magazine
Latest Screens
SHADOW (2014)
DEAD TASTE
Tactics of World War I
Hecknex World
Who's Online Now
2 registered members (Grant, AndrewAMD), 911 guests, and 9 spiders.
Key: Admin, Global Mod, Mod
Newest Members
rki, FranzIII, indonesiae, The_Judge, storrealba
18919 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Dicing physic code Y_Y #319430
04/14/10 20:59
04/14/10 20:59
Joined: Mar 2008
Posts: 2,247
Baden Württemberg, Germany
Espér Offline OP
Expert
Espér  Offline OP
Expert

Joined: Mar 2008
Posts: 2,247
Baden Württemberg, Germany
hi there..
I got a little problem with my dicing-based game. the proble is, the dicing code.

1. i have a box ( invisible ) where two dices are inside.
2. this two dices should start flipping around in a random direction
3. now the physic engine should do the rest.
4. When the dices stop moving ( and lieing plane on the ground), the shown scores should be added together into a variable ( the dice result )...


So.. i know how to make a dice with integer(random(X)).. but not how to do it with dice-models and physics..

Can someone help me here Y_Y ?


Selling my Acknex Engine Editions (A7 Com & A8 Pro):
>> click here if you are interested <<
Re: Dicing physic code Y_Y [Re: Espér] #319439
04/14/10 21:22
04/14/10 21:22
Joined: Mar 2006
Posts: 2,252
Hummel Offline
Expert
Hummel  Offline
Expert

Joined: Mar 2006
Posts: 2,252
Even the crappy engine physic should work for some simple dices. Just add some forces to the models using random vectors. Then you need to find out wich number the top side shows. A possible solution would be to add 6 extra vertices to the model, for each side one. After dicing simply check wich ob these vertices has the biggest z-value. The vertex number refers then to the diced one.

Re: Dicing physic code Y_Y [Re: Hummel] #319441
04/14/10 21:27
04/14/10 21:27
Joined: Mar 2008
Posts: 2,247
Baden Württemberg, Germany
Espér Offline OP
Expert
Espér  Offline OP
Expert

Joined: Mar 2008
Posts: 2,247
Baden Württemberg, Germany
the problem isn´t the "finding out wich side is the upper side"

more the "Why is the dice moving that slow.. and why is it not rotating when it hits the ground/wall".
And "How to ask if the dices stopped?"

Atm the dice just falls slowly, bounces away a bit.. but doesn´t change direction ( even if it hits the ground with one of the edges (rounded)).
And sometimes it happens, that he just jumps out of the box downwards if it falls.. then the dices get stuck outside the box, inside the ground terrain Y_Y

Last edited by Espér; 04/14/10 22:14.

Selling my Acknex Engine Editions (A7 Com & A8 Pro):
>> click here if you are interested <<
Re: Dicing physic code Y_Y [Re: Espér] #319448
04/14/10 23:06
04/14/10 23:06
Joined: Mar 2008
Posts: 2,247
Baden Württemberg, Germany
Espér Offline OP
Expert
Espér  Offline OP
Expert

Joined: Mar 2008
Posts: 2,247
Baden Württemberg, Germany
ok.. got the dicing code to work now..
Code:
function dicecontrol(ENTITY* dicepointer)
{
	VECTOR* my_pos = {x=0; y=0; z=0;}
	var vertexarray[6] = {1695, 311, 1692, 81, 1698, 312};
	var resulting = 1;
	var i;
	
	for(i=0; i!=6; i++)
	{
		vec_for_vertex(my_pos, dicepointer, vertexarray[i]);
		if(my_pos.z >= 600)
		{resulting = i+1;break;}
	}
	return(resulting);
}

function dicing()
{
	var seedget = random(333.3);
	var dice_1_result = 1;
	var dice_2_result = 1;
	
	random_seed(seedget);
	seedget = random(333.3);
	random_seed(seedget);  
	ENTITY* dicebox = ent_create ("dicebox.mdl", vector(-750, 0, 550), NULL);
	c_setminmax(dicebox);
	set(dicebox, INVISIBLE | POLYGON);
	reset(dicebox, PASSABLE);
	vec_set(dicebox.scale_x, vector(10.0, 10.0, 5.0));
	wait(1);
	ENTITY* dice1 = ent_create ("würfel.mdl", vector(200, 200, 2000), NULL);
	ENTITY* dice2 = ent_create ("würfel.mdl", vector(-200, -200, 2000), NULL);
	c_setminmax(dice1); c_setminmax(dice2);
	set(dice1, POLYGON); set(dice2, POLYGON);
	vec_set(dice1.scale_x, vector(40.0, 40.0, 40.0)); vec_set(dice2.scale_x, dice1.scale_x);
	vec_set(dice1.pan, vector(random(360)-180, random(360)-180, random(360)-180)); vec_set(dice2.pan, vector(random(360)-180, random(360)-180, random(360)-180));
	ph_setgravity (vector(random(300)-150, random(300)-150, -1000));
	phent_settype (dice1, PH_RIGID, PH_BOX); phent_settype (dice2, PH_RIGID, PH_BOX);
	phent_setmass (dice1, 2000, PH_BOX); phent_setmass (dice2, 2000, PH_BOX);
	phent_setfriction (dice1, 50); phent_setfriction (dice2, 50);
	phent_setdamping (dice1, 50, 50); phent_setdamping (dice2, 50, 50);
	phent_setelasticity (dice1, 100, 100); phent_setelasticity (dice2, 100, 100);
	ph_setgravity (vector(0, 0, -386));
	
	VECTOR* old_pos1 = {x=0; y=0; z=0;}
	VECTOR* old_pos2 = {x=0; y=0; z=0;}
	VECTOR* new_pos1 = {x=0; y=0; z=0;}
	VECTOR* new_pos2 = {x=0; y=0; z=0;}
	
	while(1)
	{
		vec_set(old_pos1.x, dice1.x); vec_set(old_pos2.x, dice2.x);
		wait(10);
		vec_set(new_pos1.x, dice1.x); vec_set(new_pos2.x, dice2.x);
		if(vec_dist(new_pos1.x, old_pos1.x) <= 0)
		{
			break;
		}
		wait(1);
	}
	
	dice_1_result = dicecontrol(dice1);
	wait_for(dicecontrol);
	dice_2_result = dicecontrol(dice2);
	wait_for(dicecontrol);
	diceresult = dice_1_result + dice_2_result;
	waitcount = 200;
	while(key_space == 0)
	{
		if(waitcount < 1){break;}
		waitcount -= 1;
		wait(1);
	}
	ent_remove(dice1);
	ent_remove(dice2);
	ent_remove(dicebox);
	dicetrigger = 0;
}



But the dices are falling toooo slowly!
How can i make them falling faster?

Last edited by Espér; 04/14/10 23:11.

Selling my Acknex Engine Editions (A7 Com & A8 Pro):
>> click here if you are interested <<
Re: Dicing physic code Y_Y [Re: Espér] #319464
04/15/10 05:52
04/15/10 05:52
Joined: Jul 2007
Posts: 959
nl
F
flits Offline
User
flits  Offline
User
F

Joined: Jul 2007
Posts: 959
nl
you can change the gravety more donwwards
less damping
ore add a extra force

and be carfull settings suchs hi friction because it can give ugly effects in gsphysics

dont know how you are rotating sovar i see by moving the gravety sideways


"empty"

Moderated by  adoado, checkbutton, mk_1, Perro 

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