[Newton] Breakable Objects / Bruchstücke

Posted By: MasterQ32

[Newton] Breakable Objects / Bruchstücke - 10/28/09 14:06

Hallo,
gibt es die Möglichkeit, in Lite-C dieses Feature von Newton zu verwenden??

Hello guys,
is it possible to use this feature of newton in Lite-C??
Video

Richi007
Posted By: Blackchuck

Re: [Newton] Breakable Objects / Bruchstücke - 11/12/09 15:28

Hy I have the same questins like you! laugh
I will try to find it in the newton forum.
When I know it I will tell it to you.
Posted By: VeT

Re: [Newton] Breakable Objects / Bruchstücke - 11/13/09 13:55

Yep, its possible, but now i'm working on wrapping Character and Cars controllers.
Any help would be great. wink
Posted By: darkinferno

Re: [Newton] Breakable Objects / Bruchstücke - 11/13/09 14:13

ahh, sounds good Vet, maybe sign in to ICQ? i'd like to talk on a few systems of newton, sadly i cant really help with the technicalities too much grin
Posted By: Blackchuck

Re: [Newton] Breakable Objects / Bruchstücke - 11/13/09 14:57

So that meens that (when we use newton) we must wright everithing in a totaly other way.
Posted By: darkinferno

Re: [Newton] Breakable Objects / Bruchstücke - 11/13/09 20:14

ya.. which is what scared me away in the first place grin not that i couldnt learn, but its kinda hard to be learning multiple systems, you'll really never get your game done if you take time to learn all the available systems
Posted By: VeT

Re: [Newton] Breakable Objects / Bruchstücke - 11/14/09 10:50

Yep, but you must know, which system is good for what laugh
For example, i learn physic systems (Newton, Bullet, PhysX), worked a lot with different AI systems (Perfect, A-star), but i NEVER would start to learn shaders grin
Posted By: Blackchuck

Re: [Newton] Breakable Objects / Bruchstücke - 11/14/09 12:40

But maby we don`t musst to lern everithing.
We could make somthing like vocabularies, I meen it like this;
Lets take vocabularies from german in english:

german
Auto
in englisch
car

And know from lite-c to newton;

lite-c:

action ball()
{
phent_settype(my,PH_RIGID,PH_SPHERE);
phent_setfriction(my,90);
phent_setmass(my,5,PH_SPHERE);
phent_setelasticity(my,75,100);
phent_setdamping(my,30,5);
ph_setgravity(vector(0,0,-500));
}

to newton:

float QUANTTOMETER = 0.03125;
float METERTOQUANT = 32;

#include "NewtonMain2.18.c"
#include "NewtonAPI2.18.c"

NewtonWorld* nworld;

#include "matrix.c"
#include "newton_materials.c"
#include "newton_main.c"
#include "newton_debug.c"

void quit()
{
newton_stop();
}
void newton_start()
{
wait(2);
newton_start();
on_exit = quit;
while(1)
{
newton_update();
wait(1);
}
}

action ball_newt()
{
wait(3);
newton_addentity(me, 5, NEWTON_SPHERE, onforceandtorque);
}

That would be a idea.
Posted By: FBL

Re: [Newton] Breakable Objects / Bruchstücke - 11/14/09 12:44

Integrating Newton is not too difficult.
The ugly part is getting the matrices right and converting the mesh data (imho), but ventilator and vet have already done this for us laugh

I've extended the mesh converter so it only reads certain mesh subsets. This allows me to use simpler geometry for collision and complex geometry for display - without the need to have to use two models and reference each other.
Posted By: FBL

Re: [Newton] Breakable Objects / Bruchstücke - 11/14/09 12:45

void newton_start()
{
wait(2);
newton_start();
...

now that's an endless loop wink
Posted By: Blackchuck

Re: [Newton] Breakable Objects / Bruchstücke - 11/14/09 12:50

Hmmm.
How made that "breakeble objeckt" projeckt?
Maby he could help us alittlebit out.
Posted By: VeT

Re: [Newton] Breakable Objects / Bruchstücke - 11/14/09 13:00

2 Firoball:
//I've extended the mesh converter so it only reads certain mesh subsets.
Can you share this? laugh

2 Blackchuck:
Breakable objects are almost ready in Newton's code, that is written in c++.. somebody just may convert it from c++ to lite-c and work is done laugh
i'm working on character controller and car controller, in addition i dont have enough time for that... maybe, after controllers i'll go to brekeable objects.
Posted By: VeT

Re: [Newton] Breakable Objects / Bruchstücke - 11/14/09 13:04

PS:
2 Firoball:
did you worked with NewtonSetWorldSize in newton_addstaticcollisiongeometry()?
ventilator wanted to make world size depends on size of treecollision... i'm going to add this in the next version of wrapper with the help of NewtonCollisionCalculateAABB()

2 Blackchuck:
adding Newton to project is not too hard, look at main.c.. well, also i wrote lesson in english, how to add Newton to project, but lesson is lost on the filefront(i uploaded files there before), so this evening i'l look for it on my comp.
Posted By: FBL

Re: [Newton] Breakable Objects / Bruchstücke - 11/14/09 13:14

The change is very project spedific so I don't know how much sense it makes to take this over to the wrapper.
But I will share anyway.

The rules:
- If there is only one subset, everything behaves as usual.
- If there are more than one subsets, the first one is used for collision, the remaining ones are used for display.
- The collision subset (first subset in mesh) must have at least some sort of skin (best is a skin without texture - it is never seen anyway).
- The subset order can be derived from the mesh group number in MED. It is important to make sure the collision mesh is the first group in MED
- This needs A7.8 due to the vmask instruction.

Code:
void newton_treecollisionaddentity(NewtonCollision* treecollision, ENTITY* entity)
{
	if(!entity) return;
	
	LPD3DXMESH pmesh = (LPD3DXMESH)ent_getmesh(entity, 0, 0);
	int numvertices = pmesh->GetNumVertices();
	int numfaces = pmesh->GetNumFaces();
	int meshes = ent_status(entity, 9);
	if (meshes > 1)
	{
		entity->vmask |= 0x1; //hide first mesh group, it is used for collision	
	}	
	_VERTEX_ *pvertices; pmesh->LockVertexBuffer(0, (void**)&pvertices);
	short *pindices; pmesh->LockIndexBuffer(0, (void**)&pindices);
	int *pattributes; pmesh->LockAttributeBuffer(0, &pattributes);
	
	// transform vertices to world space
	D3DXVECTOR4 *ptransformedvertices = (D3DXVECTOR4*)malloc(sizeof(D3DXVECTOR4) * numvertices);
	D3DXMATRIX m; ent_getmatrix(entity, &m);
	D3DXVECTOR3 tempvector;
	int i;
	for(i = 0; i < numvertices; i++)
	{
		tempvector.x = pvertices[i].x;
		tempvector.y = pvertices[i].z; // direct3d -> 3dgs coordinate system
		tempvector.z = pvertices[i].y; // direct3d -> 3dgs coordinate system 
		D3DXVec3Transform(&ptransformedvertices[i], &tempvector, &m);	
	}
	
	// add triangles to collision tree
	for(i = 0; i < numfaces; i++)
	{	
		float v[9];
		// use first mesh if only one mesh is available, otherwise use all meshes except first
		if ((meshes > 1 && pattributes[i] == 0) || meshes == 1)
		{
			v[0] = ptransformedvertices[pindices[(i*3)+2]].x * QUANTTOMETER;
			v[1] = ptransformedvertices[pindices[(i*3)+2]].y * QUANTTOMETER;
			v[2] = ptransformedvertices[pindices[(i*3)+2]].z * QUANTTOMETER;
			v[3] = ptransformedvertices[pindices[(i*3)+1]].x * QUANTTOMETER;
			v[4] = ptransformedvertices[pindices[(i*3)+1]].y * QUANTTOMETER;
			v[5] = ptransformedvertices[pindices[(i*3)+1]].z * QUANTTOMETER;
			v[6] = ptransformedvertices[pindices[(i*3)+0]].x * QUANTTOMETER;
			v[7] = ptransformedvertices[pindices[(i*3)+0]].y * QUANTTOMETER;
			v[8] = ptransformedvertices[pindices[(i*3)+0]].z * QUANTTOMETER;
			NewtonTreeCollisionAddFace(treecollision, 3, v, 12, pattributes[i]);
		}
	}
	
	free(ptransformedvertices);
	
	pmesh->UnlockVertexBuffer();
	pmesh->UnlockIndexBuffer();
	pmesh->UnlockAttributeBuffer();
}


Posted By: VeT

Re: [Newton] Breakable Objects / Bruchstücke - 11/15/09 23:10

Thanks, i'll look into it... Also, i finished with NewtonSetWorldSize(), you may find it at the next update.
Posted By: Blackchuck

Re: [Newton] Breakable Objects / Bruchstücke - 11/17/09 19:27

VeT the newton Character controlles hears very interesting to.
Is it writen like helf lite-c and half newton or did you just use newton?
when yes, can it be that you animated with boens?
Posted By: VeT

Re: [Newton] Breakable Objects / Bruchstücke - 11/18/09 01:10

Half lite-c anf half Newton... Its interesting, but its also hard enough: i re-write code of controller in the 5-th time from the very begining, spend a lot of weeks of work, and still no results frown
Controller is exist, capsule dont fall down, but i cant correctly move it.
Posted By: Blackchuck

Re: [Newton] Breakable Objects / Bruchstücke - 11/18/09 12:40

OK, now I knopw what you meen I tested it by myself like this;

var ISOMETRIC;

action free_camera()
{
c_setminmax(my);
VECTOR camera_force;
set(my,INVISIBLE|POLYGON);
camera_force.z = 0;
vec_set(camera.x,my.x);
vec_set(camera.pan,my.pan);
while(1)
{
camera_force.x = (key_w - key_s)*10*time_step;
camera_force.y = (key_a - key_d)*10*time_step; vec_add(my.pan,vector(mouse_force.x(-7)*time_step,mouse_force.y*7*time_step,0));
c_move(my,camera_force,nullvector,GLIDE+IGNORE_PASSABLE+IGNORE_PASSENTS+IGNORE_PUSH);
vec_set(camera.x,vector(my.x,my.y,my.z+15));
vec_set(camera.pan,my.pan);
wait(1);
}
}

That has no reaktion to the newton objeckts.
So I tryed like this;

var ISOMETRIC;

action free_camera()
{
c_setminmax(my);
VECTOR camera_force;
set(my,INVISIBLE|POLYGON);
camera_force.z = 0;
vec_set(camera.x,my.x);
vec_set(camera.pan,my.pan);
wait(3);
newton_addentity(me, (float)5, NEWTON_BOX, onforceandtorque);
while(1)
{
camera_force.x = (key_w - key_s)*10*time_step;
camera_force.y = (key_a - key_d)*10*time_step;
vec_add(my.pan,vector(mouse_force.x*(-7)*time_step,mouse_force.y*7*time_step,0));
c_move(my,camera_force,nullvector,GLIDE+IGNORE_PASSABLE+IGNORE_PASSENTS+IGNORE_PUSH);
vec_set(camera.x,vector(my.x,my.y,my.z+15));
vec_set(camera.pan,my.pan);

wait(1);
}
}

But that falles just throw everithing.
But it lookes cool becuse of tha camera laugh
Posted By: VeT

Re: [Newton] Breakable Objects / Bruchstücke - 11/18/09 18:35

First, you mix Newton and standard c_ functions... If you create Newton body with newton_addentity(), then c_move wouldnt work at all.
Second, you may apply all forces to bofu incide onforceandtorque function.
© 2024 lite-C Forums