Gamestudio Links
Zorro Links
Newest Posts
Trading Journey
by howardR. 04/28/24 09:55
Zorro Trader GPT
by TipmyPip. 04/27/24 13:50
Help with plotting multiple ZigZag
by M_D. 04/26/24 20:03
Data from CSV not parsed correctly
by jcl. 04/26/24 11:18
M1 Oversampling
by jcl. 04/26/24 11:12
Why Zorro supports up to 72 cores?
by jcl. 04/26/24 11:09
Eigenwerbung
by jcl. 04/26/24 11:08
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (1 invisible), 735 guests, and 2 spiders.
Key: Admin, Global Mod, Mod
Newest Members
wandaluciaia, Mega_Rod, EternallyCurious, howardR, 11honza11
19049 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
The big PhysX gimmick user collection Thread #354982
01/23/11 20:12
01/23/11 20:12
Joined: Sep 2003
Posts: 303
Germany
Clemens Offline OP
Senior Member
Clemens  Offline OP
Senior Member

Joined: Sep 2003
Posts: 303
Germany
Hi everybody!

I wanna start a project with you together. It's about the nice physics engine, 3d GameStudio has, and about the fact of a deficit in examples and tutorials in this category.

So let's make and collect some nice gimmicks.

Code:
/*
A project started by Clemens Möckel (23.1.2011)

with the aim of a nice, big collection of 3dGS PhysX gimmicks...

Start now and create/add yours. Here's the How-to:

1) Program a function which creates your physics gimmick (simulation)... like the function create_chain_ball()
	-try to keep it as simple as possible
	-document and comment your source code and insert "[help]" at each places, you have trouble with
2) Implement a hotkey to your function in the main function.
3) You need to have a while loop
	-which includes the user control (if there is one) (I)
	-a draw_text command giving a short description of your gimmick (II)
	-and very important: a "if (key_delete)" block, which removes your gimmick (III)
4) Add a "gimmick_is_running=1;" before the while loop and a "gimmick_is_running=0;" after that loop
5) Share it in the 3dGs forum at: [url]
   -don't forget a download with the models/prefabs
   -post a screenshot of your gimmick
*/

///////////////////////////////
#include <acknex.h>
#include <default.c>
#include <ackphysx.h>
///////////////////////////////

BOOL gimmick_is_running;

////////////////////////
// chain_ball v0.3 by Clemens

function create_chain_ball() {
	// Create the chains, and the ball at the bottom
	ENTITY* Ring1 = ent_create("chain_ring.mdl", vector(0,0,0), NULL);
	ENTITY* Ring2 = ent_create("chain_ring.mdl", vector(0,0,-10), NULL);
	Ring2.pan=90;
	ENTITY* Ring3 = ent_create("chain_ring.mdl", vector(0,0,-20), NULL);
	ENTITY* Ring4 = ent_create("chain_ring.mdl", vector(0,0,-30), NULL);
	Ring4.pan=90;
	ENTITY* Ring5 = ent_create("chain_ring.mdl", vector(0,0,-40), NULL);
	ENTITY* Ring6 = ent_create("chain_ring.mdl", vector(0,0,-50), NULL);
	Ring6.pan=90;
	ENTITY* Ball = ent_create("sphere.mdl", vector(0,0,-64), NULL);
	
	// Just for the look
	// material
	set(Ring1,LIGHT|CAST);set(Ring2,LIGHT|CAST);set(Ring3,LIGHT|CAST);set(Ring4,LIGHT|CAST);set(Ring5,LIGHT|CAST);set(Ring6,LIGHT|CAST);set(Ball,LIGHT|CAST);
	Ring1.material=mat_metal;Ring2.material=mat_metal;Ring3.material=mat_metal;Ring4.material=mat_metal;Ring5.material=mat_metal;Ring6.material=mat_metal;Ball.material=mat_metal;
	// colors
	//[variante1] vec_set(Ring1.blue,vector(200,0,0));vec_set(Ring2.blue,vector(0,100,0));vec_set(Ring3.blue,vector(200,0,0));vec_set(Ring4.blue,vector(0,200,0));vec_set(Ring5.blue,vector(200,0,0));vec_set(Ring6.blue,vector(0,200,0));vec_set(Ball.blue,vector(0,0,200));
	vec_set(Ring1.blue,vector(200,0,0));vec_set(Ring2.blue,vector(160,40,0));vec_set(Ring3.blue,vector(120,80,0));vec_set(Ring4.blue,vector(80,120,0));vec_set(Ring5.blue,vector(40,160,0));vec_set(Ring6.blue,vector(0,200,0));vec_set(Ball.blue,vector(0,100,100));
	// casting shadows
	set(Ring1,SHADOW); set(Ring2,SHADOW); set(Ring3,SHADOW); set(Ring4,SHADOW); set(Ring5,SHADOW); set(Ring6,SHADOW); set(Ball,SHADOW);


	// Make them physical by define their types
	pXent_settype(Ring1,PH_RIGID,PH_CONVEX);
	pXent_settype(Ring2,PH_RIGID,PH_CONVEX);
	pXent_settype(Ring3,PH_RIGID,PH_CONVEX);
	pXent_settype(Ring4,PH_RIGID,PH_CONVEX);
	pXent_settype(Ring5,PH_RIGID,PH_CONVEX);
	pXent_settype(Ring6,PH_RIGID,PH_CONVEX);
	pXent_settype(Ball,PH_RIGID,PH_BALL);
	
	// group the rings so they dont affect each other related to their collision (getting important if they losing their constraints)
	pXent_setgroup(Ring1,3); pXent_setgroup(Ring2,3); pXent_setgroup(Ring3,3); pXent_setgroup(Ring4,3);pXent_setgroup (Ring5,3);pXent_setgroup (Ring6,3);
	 //pXent_setgroup(Ball,3);
	
	// Connect the objects!
	pXcon_add ( PH_BALL, Ring1, NULL, 0 );		// PH_BALL makes it more movable...
 	pXcon_add ( PH_HINGE, Ring2, Ring1, 0 );
 	pXcon_add ( PH_HINGE, Ring3, Ring2, 0 );
 	pXcon_add ( PH_HINGE, Ring4, Ring3, 0 );
 	pXcon_add ( PH_HINGE, Ring5, Ring4, 0 );
 	pXcon_add ( PH_HINGE, Ring6, Ring5, 0 );
 	pXcon_add ( PH_HINGE, Ball, Ring6, 0 );
	
	pXcon_setparams1(Ring1, vector(0,0,5), NULL, NULL);	// anchor point at the top, like attached on the ceiling
	// change the axis - otherwise the chains wouldn't keep their 90° pan relation ... (1,0,0), (0,1,0), (1,1,0) seems to make no difference (?)
	pXcon_setparams1(Ring2, NULL, vector(0,1,0), NULL);
	pXcon_setparams1(Ring3, NULL, vector(0,1,0), NULL);
	pXcon_setparams1(Ring4, NULL, vector(0,1,0), NULL);
	pXcon_setparams1(Ring5, NULL, vector(0,1,0), NULL);
	pXcon_setparams1(Ring6, NULL, vector(0,1,0), NULL);

	pXent_setmass(Ball, 0.01);		// if the ball is to heavy it results in physical chaos
			// reducing pXent_setmaxspeed can help to protect chaos, too - but then the sixth ring becomes stiff... why? [help]
			//pXent_setmaxspeed(Ball, 0.1);
			// second way would probably be to change parameter3 --> let it break before
	pXent_setdamping (Ball, 50, 50 ); // the ball gets forced, so it as well has to be damped - otherwise doesn't stop moving

	gimmick_is_running=1;
	while(1) {
		// (I) user control
		if (key_cul) pXent_addforcecentral(Ball, vector(-0.01, 0, 0));
		if (key_cur) pXent_addforcecentral(Ball, vector(0.01, 0, 0));
		if (key_cuu) pXent_addforcecentral(Ball, vector(0, 0.01, 0));
		if (key_cud)pXent_addforcecentral(Ball, vector(0, -0.01, 0));
		// (II) info text
		draw_text("chain_ball v0.3 by Clemens \n arrow keys: give the ball a force in that direction \n del key: destroy it", 10,10,vector(255,255,255));			
		// (III) remove gimmick... (only a part) 
		if (key_del) {
			pXcon_remove(Ball);	// backwards order important
			pXcon_remove(Ring6);
			pXcon_remove(Ring5);
			pXcon_remove(Ring4);
			pXcon_remove(Ring3);
			pXcon_remove(Ring2);
			pXcon_remove(Ring1);			
			break;
		}
		pX_pick();
		wait(1);	
	}
	gimmick_is_running=0;
	wait(-5);
	// placed the real remove routine here, because it's a nice effect, having it destroyed and lying on the door for five seconds
	ent_remove(Ball);
	/* "Error E1513: Script crash in physX_ent_remove: SYS" when deleting the rings -> don't know why [help]
	ent_remove(Ring6);
	ent_remove(Ring5);
	ent_remove(Ring4);
	ent_remove(Ring3);
	ent_remove(Ring2);
	ent_remove(Ring1);
	*/
}


////////////////
// main function

function main() {
	sun_angle.pan -= 80;
	sun_angle.tilt = 50;
	shadow_stencil = 3;
	d3d_antialias = 4;
	
	physX_open();
	level_load(""); // load empty level
	vec_set(camera.x,vector(0,-180,-50));
	camera.pan=90;

	// create ground plate (copied from physXtest.c by jcl)
	ENTITY* ground = ent_create(CUBE_MDL,vector(0,0,-100),NULL);
	vec_set(ground.scale_x,vector(20,20,1));
	pXent_settype(ground,PH_STATIC,PH_BOX); 
	pXent_setfriction(ground,10);

	
	while (1) {
		if (gimmick_is_running==0) {
			if (key_a) {
				create_chain_ball();
				wait(-1);
			}
			// Here you have to insert your function-hotkey
			// ...
		}
		wait(1);
	}
}



Don't forget to upload the needed models/prefabs etc.

Here's the whole "starter" package: Download

Including my first gimmick chain_ball v0.3:


Feel free to correct spelling mistakes and to edit any script (but document it!) for making new better versions!

Interested to join work, but no ideas? What about one of these...
-rope
-seesaw
-weighing machine
-trampoline
-carousel
-Newton's cradle
-piece of furniture
-elevator
-skid
-snake
-breakable glass
-crane
-chart house
-"jenga" tower
-gearwheel
-trap (for mouse/bear/saw^^)

Best regards,
Clemens

Last edited by Clemens; 02/01/11 20:01.
Re: The big PhysX gimmick user collection Thread [Re: Clemens] #354983
01/23/11 20:17
01/23/11 20:17
Joined: Sep 2003
Posts: 303
Germany
Clemens Offline OP
Senior Member
Clemens  Offline OP
Senior Member

Joined: Sep 2003
Posts: 303
Germany
Oh, and in my imagination every next gimmick is callable with the next higher letter.
So after pressing "a" for chain_ball - there should come "b" for the next public made gimmick.

Re: The big PhysX gimmick user collection Thread [Re: Clemens] #354984
01/23/11 20:17
01/23/11 20:17
Joined: Jul 2001
Posts: 6,904
H
HeelX Offline
Senior Expert
HeelX  Offline
Senior Expert
H

Joined: Jul 2001
Posts: 6,904
Hi Clemens, this is a really nice idea. I also planned to get my hands wet on this because after using ODE in one of my earlier projects in which I had to use it, I developed a physics engine phobia... grin , I will download your package and will post here again.

Re: The big PhysX gimmick user collection Thread [Re: HeelX] #356407
02/01/11 20:00
02/01/11 20:00
Joined: Sep 2003
Posts: 303
Germany
Clemens Offline OP
Senior Member
Clemens  Offline OP
Senior Member

Joined: Sep 2003
Posts: 303
Germany
Hi guys,
I made an update with a new gimmick:

Code:
////////////////////////
// [B] seesaw v0.3 by Clemens (31.1.2011)
// Problems [help]: often the board just freezes (doesn't go back in the horizontal position) -> depends maybe on the pXent_setskinwidth value !??

function Pause_force_arrow(ENTITY* Arrow) {
	set(Arrow, TRANSLUCENT);
	wait(-0.4);
	reset(Arrow, TRANSLUCENT);
}
function create_seesaw() {
	pX_setautodisable (0, 0); // hoped that this would solve my freeze-problem -> does not! :(

	ENTITY* Seesaw_pillar = ent_create("seesaw_pillar.mdl", vector(0,-0.2,-93), NULL);	// Create the pillar of the seesaw 
	ENTITY* Seesaw_board = ent_create("seesaw_board.mdl", vector(0,0,-80), NULL);			// Create the board of the seesaw
	ENTITY* Force_arrow = ent_create("arrow3d.mdl", vector(0,0,-50), NULL);					// Create the force arrow, which shows where to give the force on the board
	// Just for the look
	color_me(Force_arrow, vector(0,0,255));
	color_me(Seesaw_pillar, vector(0,100,100));
	color_me(Seesaw_board, vector(200,0,0));

	pXent_settype(Seesaw_pillar,PH_STATIC,PH_CONVEX);
	//pXent_setmass(Seesaw_pillar, 1);		// this can be tried, when not making it static
	
	pXent_settype(Seesaw_board,PH_RIGID,PH_BOX);
 	pXcon_add (PH_HINGE, Seesaw_board, Seesaw_pillar, 0);
	pXcon_setparams1 (Seesaw_board, nullvector, vector(0,0,1), NULL);

	var Cylinder_handles[99];	// just don't create more than 99 rolling cylinders ;)
	var CylinderNo=0;	// [0] => at begin there are zero rolling cylinders
	gimmick_is_running=1;
	while(1) {
		//// (I) user control -> keyboard or(/plus) mouse supported
		Force_arrow.x += ( 5*(key_cur-key_cul) + 15*mouse_force.x )*time_step;	// moving the arrow
		// setting the arrow force
		Force_arrow.scale_z += ( 0.03*(key_cuu-key_cud) + mickey.z/70 )*time_step;
		if (Force_arrow.scale_z<0.5) Force_arrow.scale_z=0.5;	// minimum of size/force
		if (Force_arrow.scale_z>3) Force_arrow.scale_z=3;		// maximum of size/force
		// push the board with the force that has been set at the horizontal position of the arrow
		if (is(Force_arrow,TRANSLUCENT)==0) {
			if (key_space || mouse_left) {
				pXent_addforceglobal(Seesaw_board, vector(0, 0, -0.5*Force_arrow.scale_z), vector(Force_arrow.x, 0, 0));
				Pause_force_arrow(Force_arrow);
			}
			if (key_bksp || mouse_right) {
				pXent_addforceglobal(Seesaw_board, vector(0, 0, 0.5*Force_arrow.scale_z), vector(Force_arrow.x, 0, 0));
				Pause_force_arrow(Force_arrow);
			}			
		}		
		// create a rolling cylinder, which can be balanced on the seesaw
		if (key_shift || mouse_middle) {
			ENTITY* Rolling_cylinder = ent_create("wide_cylinder.mdl", vector(0,0,-50), NULL);
			color_me(Rolling_cylinder, vector(120,0,255));
			pXent_settype(Rolling_cylinder,PH_RIGID,PH_CONVEX);
			pXent_setmass(Rolling_cylinder,0.005);
			CylinderNo+=1;
			Cylinder_handles[CylinderNo] = handle(Rolling_cylinder);
			wait(-0.3);			// no nice elegant solution -> to [update]: externalize
		}
		//// (II) remove gimmick (without the cylinders)
		if (key_del) {
			ent_remove(Seesaw_board);
			ent_remove(Seesaw_pillar);	
			ent_remove(Force_arrow);
			break;
		}
		//pX_pick();	// to dangerous that it's used accidentally
		wait(1);
	}
	gimmick_is_running=0;
	(Info_text.pstring)[0]=Help_str;
	pX_setautodisable (2, 2);
	wait(-5);	// want the cylinders to stay some seconds...
	while (CylinderNo>0) {	// remove every created cylinders (step for step)
		ptr_remove(ptr_for_handle(Cylinder_handles[CylinderNo]));
		CylinderNo-=1;
		wait(-0.1);
	}
}





Collection a-b (whole package) Download

HeelX, happy to hear your interest. Looking forward for some gimmicks from you wink

And hopelly there will be some more persone here in the forum who like to play a little bit around with the physics engine and share the result here with us...



Edit on 8.9.2012: eaglelab asked me to reupload the package. Done!

Last edited by Clemens; 09/07/12 23:40.
Re: The big PhysX gimmick user collection Thread [Re: Clemens] #356408
02/01/11 20:07
02/01/11 20:07
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Superku Offline
Senior Expert
Superku  Offline
Senior Expert

Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
My contribution is more a hint than a regular contribution:
Open ackphysx.c and have a look at its content. You will discover many useful things, such as a nice way for 2D physics, for example:

pXent_setbodyflag(my,NX_BF_FROZEN_POS_Y,1);

Now you will have a nice 2D-physics-engine. You can lock the pan and roll angles so objects remain 2D (that is they always face the camera), even if they are 3D:

pXent_setbodyflag(my,NX_BF_FROZEN_POS_Y | NX_BF_FROZEN_PAN | NX_BF_FROZEN_ROLL,1);


"Falls das Resultat nicht einfach nur dermassen gut aussieht, sollten Sie nochmal von vorn anfangen..." - Manual

Check out my new game: Pogostuck: Rage With Your Friends

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