Jump to content

[Reopened] Find All Physics Bodies on a Map


Shard
 Share

Recommended Posts

Is it possible to find all physics bodies on the map? (Even the ones that are Lua loaded/loaded with a model)

simpleSigPNG.png

 

Programmer/Engineer/Student

www.reikumar.com

 

2.6 GHz Intel Core Duo - nVidia GeForce 8600 GT - Windows 7 64-bit - 4 Gigs RAM

C++ - Visual Studio Express - Dark GDK - Leadwerks SDK

Link to comment
Share on other sites

Don't know if it's the correct way, but have you tried to pass ENTITY_BODY to ForEachEntityDo() as last parameter?

 

 

That doesn't seem to have worked.

I'm creating several physics bodies (as in the bodies tutorial) and out of the hundred, only one is affected.

 

Sine ENTITY_BODY is an enum that is 8 I tried some other values (1-7) and none of those worked and every odd number caused an exception.

 

Any other ideas?

simpleSigPNG.png

 

Programmer/Engineer/Student

www.reikumar.com

 

2.6 GHz Intel Core Duo - nVidia GeForce 8600 GT - Windows 7 64-bit - 4 Gigs RAM

C++ - Visual Studio Express - Dark GDK - Leadwerks SDK

Link to comment
Share on other sites

That doesn't seem to have worked.

I'm creating several physics bodies (as in the bodies tutorial) and out of the hundred, only one is affected.

 

I tried against the code of the tutorial "Introduction to Models" and have 101 entities count using "ENTITY_MODEL | ENTITY_BODY":

 

#include "engine.h"
#include <cstdio>
#include <sstream>

int entities = 0;

void _stdcall myfunc( TEntity entity, BP extra )
{
entities++;
}

inline float rnd( float min=0.0, float max=1.0 ) {
return min + ((float)rand()/RAND_MAX)*(max-min);
}

int WINAPI WinMain( HINSTANCE hInstance,
				HINSTANCE hPrevInstance,
				LPSTR lpCmdLine,
				int nShowCmd )
{
Initialize() ;
RegisterAbstractPath("D:/LE/2.32");
SetAppTitle( "ConsoleCPP" ) ;
Graphics( 800, 600 ) ;

TWorld world = CreateWorld() ;
if (!world) {
	MessageBoxA(0,"Error","Failed to create world.",0);
	return Terminate();
}

TBuffer gbuffer=CreateBuffer(GraphicsWidth(),GraphicsHeight(),BUFFER_COLOR|BUFFER_DEPTH|BUFFER_NORMAL);

	//Create a camera
TCamera cam=CreateCamera();
CameraClearColor(cam,Vec4(0,0,1,1));
PositionEntity(cam,Vec3(0,2,-10));

//Create a light
TLight light=CreateDirectionalLight();
RotateEntity(light,Vec3(45,45,0));

//Create a render buffer
TBuffer buffer=CreateBuffer(800,600,BUFFER_COLOR|BUFFER_DEPTH|BUFFER_NORMAL);

TModel model=LoadModel("abstract::oildrum.gmf");
if (!model) {
	MessageBoxA(0,"Error","Failed to load mesh.",0);
	goto exitapp;
}
SetBodyMass(model, 1);

for ( int n=1; n<=100; n++ ) {
	model=CopyEntity(model);
	PositionEntity(model,Vec3(rnd(-5,5),rnd(5,15),rnd(-5,5)));
	RotateEntity(model,Vec3(rnd(0,360),rnd(0,360),rnd(0,360)));
	SetBodyMass(model, 1);
}

//Main loop
while(!KeyHit(KEY_ESCAPE))
{
	//Update the world
	UpdateWorld();
	//Render the scene
	SetBuffer(buffer);
	RenderWorld();
	//Render lighting
	SetBuffer(BackBuffer());
	RenderLights(buffer);

	entities = 0;
	ForEachEntityDo(reinterpret_cast<byte*>(myfunc), 0, ENTITY_MODEL | ENTITY_BODY);

	//std::string s;
	std::stringstream out;
	out << entities;
	//s = out.str();
	DrawText(0, 30, out.str().c_str());

	//Swap the front and back buffer
	Flip();
}
exitapp:
return Terminate();
}

?? FRANCESCO CROCETTI ??

http://skaredcreations.com

Link to comment
Share on other sites

Similar code but that doesn't seem to work. (Press the Tab Key to activate the effect)

 

[removed]

simpleSigPNG.png

 

Programmer/Engineer/Student

www.reikumar.com

 

2.6 GHz Intel Core Duo - nVidia GeForce 8600 GT - Windows 7 64-bit - 4 Gigs RAM

C++ - Visual Studio Express - Dark GDK - Leadwerks SDK

Link to comment
Share on other sites

Your callback is returning 0 which tells the engine to stop looping the callback. To continue to the next iteration, return 1.

http://www.leadwerks.com/wiki/index.php?title=Entities#ForEachEntityDo

Ryzen 9 RX 6800M ■ 16GB XF8 Windows 11 ■
Ultra ■ LE 2.53DWS 5.6  Reaper ■ C/C++ C# ■ Fortran 2008 ■ Story ■
■ Homepage: https://canardia.com ■

Link to comment
Share on other sites

Your callback is returning 0 which tells the engine to stop looping the callback. To continue to the next iteration, return 1.

http://www.leadwerks.com/wiki/index.php?title=Entities#ForEachEntityDo

 

Aaaand that worked.

Thanks a lot!

simpleSigPNG.png

 

Programmer/Engineer/Student

www.reikumar.com

 

2.6 GHz Intel Core Duo - nVidia GeForce 8600 GT - Windows 7 64-bit - 4 Gigs RAM

C++ - Visual Studio Express - Dark GDK - Leadwerks SDK

Link to comment
Share on other sites

Aaaand that worked.

Thanks a lot!

 

 

Nup, actually it didn't.

It works fine for things created in code, but not for things loaded by LoadScene.

Any ideas on that?

simpleSigPNG.png

 

Programmer/Engineer/Student

www.reikumar.com

 

2.6 GHz Intel Core Duo - nVidia GeForce 8600 GT - Windows 7 64-bit - 4 Gigs RAM

C++ - Visual Studio Express - Dark GDK - Leadwerks SDK

Link to comment
Share on other sites

When you load sth with Load scene, all the entities are parented to the scene.

You have to unparent them from the scene, to get it working. A least that is

what i think will solve your problem.

(Win7 64bit) && (i7 3770K @ 3,5ghz) && (16gb DDR3 @ 1600mhz) && (Geforce660TI)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...