Jump to content

Physics rare behavior


DarthRaff
 Share

Recommended Posts

Hello,

 

Can someone, please, copy that code (i assume you have the SDK oildrum model)and do:

First execute it and try collide with some object.

Then delete oildrum2 from code,execute and try collide with some object.

Any difference? please, tell me. THankyou

 

the code:

#include "engine.h"
#include <math.h>
#include <string>
#include <vector>
#include "monsterfuncs.h"

using namespace std;
string nametext;

#pragma warning(disable:4996)

int state;
float fb;
float fe;

TController player;

class Monster
{
public:
TController monstercont;
TMesh monsterent;
TVec3 monsterpos;
TVec3 monsterrot;
int monsterstate;
float mstartframe;
float mendframe;
};
vector<Monster> monsterarray;
vector<Monster>::iterator monsteriter;
void UpdateMonsters()
{
for(monsteriter=monsterarray.begin();monsteriter!=monsterarray.end();monsteriter++)
{
	SlowPointEnt((*monsteriter).monstercont,player,.5);
	(*monsteriter).monsterrot=EntityRotation((*monsteriter).monstercont);
	UpdateController((*monsteriter).monstercont,(*monsteriter).monsterrot.Y,0.0f,0.0f,0.0f,10000);
	RotateEntity((*monsteriter).monsterent,(*monsteriter).monsterrot);
	//PositionEntity((*monsteriter).monsterent,EntityPosition((*monsteriter).monstercont));
PositionEntity((*monsteriter).monsterent,Vec3((*monsteriter).monsterpos.X,(*monsteriter).monsterpos.Y-1.5,(*monsteriter).monsterpos.Z));
	if(KeyHit(KEY_UP))
	{
		if((*monsteriter).monsterstate <3)
		{
			monsteriter->monsterstate++;
		}
		else
		{
			monsteriter->monsterstate=0;
		}
	}
	if(KeyHit(KEY_DOWN))
	{
		if((*monsteriter).monsterstate >0)
		{
			monsteriter->monsterstate--;
		}
		else
		{
			monsteriter->monsterstate=3;
		}
	}
	switch ((*monsteriter).monsterstate)
	{
		case 1:
			monsteriter->mstartframe=41.0f;
			monsteriter->mendframe=85.0f;
			break;
		case 2:
			monsteriter->mstartframe=90.0f;
			monsteriter->mendframe=117.0f;
			break;
		case 3:
			monsteriter->mstartframe=149.0f;
			monsteriter->mendframe=184.0f;
			break;
		default:
			monsteriter->mstartframe=1.0f;
			monsteriter->mendframe=40.0f;
			break;
	}
	AnimeEntitySeq((*monsteriter).monsterent,(*monsteriter).mstartframe,(*monsteriter).mendframe,3.0f,100.0f);
}
}

int main( int argn, char* argv[] )
{
int screenx=1024, screeny=768, camx=screenx/2, camy=screeny/2;

Initialize() ;
//RegisterAbstractPath("C:/Archivos de programa/Leadwerks Engine SDK 2 28");

//Create a graphics context
Graphics(screenx,screeny);

//Create a world
if (!CreateWorld()) {
	MessageBoxA(0,"Error","Failed to create world.",0);
	goto exitapp;
}
//Create a camera
TCamera cam=CreateCamera();
CameraClearColor(cam,Vec4(0,0,1,1));
PositionEntity(cam,Vec3(0,2,-10));

Collisions(1,1,1);
Collisions(1,2,1);
Collisions(2,2,1);

//Load a model
TModel scene=LoadModel("scene/scene.gmf");
if (scene==0) {
	MessageBoxA(0,"Error","Failed to load model.",0);
	goto exitapp;
}
EntityType(scene,2);

//Create lightent
TMesh lightent=CreateSphere();
ScaleEntity(lightent,Vec3(.5,.5,.5));
PositionEntity(lightent,Vec3(0,5,0));
//Create a light
TLight light=CreatePointLight();
PositionEntity(light,Vec3(3,5,-3));
EntityColor(light,Vec4(2,2,2,1));
SetShadowmapSize(light,1024);
AmbientLight(Vec3(0.2));
EntityParent(light,lightent);
//Create a render buffer

TBuffer buffer=CreateBuffer(screenx,screeny,BUFFER_COLOR|BUFFER_DEPTH|BUFFER_NORMAL);

//Monster m;
	//m.monstercont=CreateController(2.7f,0.9f,0.25f,45);
	//m.monsterent=LoadMesh("objs/monsters/DK1/dk1.gmf");
	//m.monsterrot=Vec3(0.0f,0.0f,0.0f);
	//m.monsterpos=Vec3(0.0f,1.5f,0.0f);
	//m.monsterstate=0;
	//RotateEntity(m.monstercont,m.monsterrot);
	//RotateEntity(m.monsterent,m.monsterrot);
	//PositionEntity(m.monstercont,m.monsterpos);
	//PositionEntity(m.monsterent,m.monsterpos);

	//EntityType(m.monstercont,2);
	//SetBodyMass(m.monstercont,1.0f);

	//monsterarray.push_back(m);

int sequence=1;
float framebegin;
float frameend;
float frame;

//Create a physics body
TBody body=CreateBodyBox();
SetBodyMass(body,1.0f);
TMesh mesh=CreateCube();
EntityParent(mesh,body);
PositionEntity(body,Vec3(-3,5,0));
EntityType(body,2);

//Create another physics body
TModel oildrum=LoadModel("scene/oildrum.gmf");
PositionEntity(oildrum,Vec3(3,5,0));
EntityType(oildrum,2);
SetBodyMass(oildrum,1.0f);

TModel oildrum2=LoadModel("scene/oildrum.gmf");
PositionEntity(oildrum2,Vec3(0,5,0));
EntityType(oildrum2,2);
SetBodyMass(oildrum2,1.0f);

player=CreateController(1.84f,0.50f,0.25f,45);
EntityType(player,1);
//SetBodyDamping(player,.5f,.5f);
SetBodyMass(player,1.0f);
//SetWorldGravity(Vec3(0,-9.8f,0));
float move=0.0;
float strafe=0.0;
TVec3 camrotation=Vec3(0);
TVec3 playerpos;
float mx=0;
float my=0;
HideMouse();
MoveMouse(GraphicsWidth()/2,GraphicsHeight()/2);

PositionEntity(player,Vec3(0,0,-3));

SetWorldGravity(Vec3(0,-9.8f,0));

SetPhysicsQuality(1);

int debphy=0;

//Main loop
// Game loop
while( !KeyHit() && !AppTerminate() )
{
	if( !AppSuspended() ) // We are not in focus!
	{

		// Update timing and world
		UpdateAppTime();
		UpdateWorld(AppSpeed()) ;
		//UpdateAppTime();

		if(KeyHit(KEY_P)){debphy=1-debphy;DebugPhysics(debphy);}
		//DebugPhysics(KeyHit(KEY_P));

		TurnEntity(lightent,Vec3(0,.5f,0));

		//Player movement
		move=2*(KeyDown(KEY_W)-KeyDown(KEY_S));
		strafe=2*(KeyDown(KEY_D)-KeyDown(KEY_A));
		//Jumping
		float jump=0.0;
		if (KeyHit(KEY_SPACE)) {
			if (!ControllerAirborne(player)) {
				jump=4.0;
			}
		}
		//Run
		if (KeyDown(KEY_LSHIFT)||KeyDown(KEY_RSHIFT)) {
			if (!ControllerAirborne(player)) {
				move*=2.0;
				strafe*=2.0;
			}
		}

		playerpos=EntityPosition(player);
		//Camera looking
		mx=Curve(MouseX()-GraphicsWidth()/2,mx,6);
		my=Curve(MouseY()-GraphicsHeight()/2,my,6);
		MoveMouse(GraphicsWidth()/2,GraphicsHeight()/2);
		camrotation.X=camrotation.X+my/5.0;
		if (camrotation.X < -90){ camrotation.X = -90;}
		if (camrotation.X > 90){ camrotation.X = 90;}
		camrotation.Y=camrotation.Y-mx/5.0;
		RotateEntity(cam,camrotation);

		////Set controller input

		PositionEntity(cam,Vec3(playerpos.X,playerpos.Y+.84,playerpos.Z));
		TVec3 camerapos=EntityPosition(cam);
		TVec3 poscont=EntityPosition(player);
		PositionEntity(cam,camerapos);

		//UpdateController(player,camrotation.Y,move,strafe,jump,15000.0);
		UpdateController(player,camrotation.Y,move,strafe,jump,10000);

		//Render the scene

		//UpdateAppTime();
		//UpdateWorld();

		if(KeyHit(KEY_NUM8))
		{
			if(state < 3)
			{
				state++;
			}
			else
			{
				state=0;
			}
		}
		if(KeyHit(KEY_NUM2))
		{
			if(state > 0)
			{
				state--;
			}
			else
			{
				state=3;
			}
		}
		switch(state)
		{
		case 1:
			fb=41.0;
			fe=85.0;
			break;
		case 2:
			fb=90.0;
			fe=116.0;
			break;
		case 3:
			fb=149.0;
			fe=184.0;
			break;
		default:
			fb=0;
			fe=40;
			break;
		}

		UpdateMonsters();

		// Render
		SetBuffer(buffer);
		RenderWorld();
		SetBuffer(BackBuffer());
		RenderLights(buffer);

		DrawText(10,10,"%.3f",UPS());
		DrawText(10,30,"%d",TrisRendered());
		// Send to screen
		Flip(0) ;
	}
}

// Done
exitapp:
return Terminate() ;
}

Link to comment
Share on other sites

Please,

 

I have problems with collisions and don't know how to solve it. Can someone try and tell me, please. Thankyou.

 

 

What problem?

AMD Bulldozer FX-4 Quad Core 4100 Black Edition

2 x 4GB DDR3 1333Mhz Memory

Gigabyte GeForce GTX 550 Ti OC 1024MB GDDR5

Windows 7 Home 64 bit

 

BlitzMax 1.50 • Lua 5.1 MaxGUI 1.41 • UU3D Pro • MessiahStudio Pro • Silo Pro

3D Coat • ShaderMap Pro • Hexagon 2 • Photoshop, Gimp & Paint.NET

 

LE 2.5/3.4 • Skyline UE4 • CE3 SDK • Unity 5 • Esenthel Engine 2.0

 

Marleys Ghost's YouTube Channel Marleys Ghost's Blog

 

"I used to be alive like you .... then I took an arrow to the head"

Link to comment
Share on other sites

hi,

 

The problem is that if i put a cube with collision created by code or two or three, the collisions goes perfect, but if i try to put more than one oildrums or another gmf file the collisions fails because if you collide with an object it goes away too fast or keeps rotating around the character controller, or another malfunction. If there is just one oildrum or just one monster created by me the collisions goes perfect but if i try to put two or more of the gmf objects in the same scene the collisions fails i don't know way. all updated and copied to the right place because the collisions of objects created by code works perfect just fails more than one gmf in the same scene.

 

The code above is for best understanding of the problem. If you coul'd try it you will see.

the first fails and then if you delete oildrum2 from the code then goes perfect with one cube create by code and one oildrum.gmf.

Link to comment
Share on other sites

Well first of all try changing:

 

UpdateController(player,camrotation.Y,move,strafe,jump,10000);

 

To something like:

 

UpdateController(player,camrotation.Y,move*3,strafe*3,jump,500);

 

See if there is an improvement.

AMD Bulldozer FX-4 Quad Core 4100 Black Edition

2 x 4GB DDR3 1333Mhz Memory

Gigabyte GeForce GTX 550 Ti OC 1024MB GDDR5

Windows 7 Home 64 bit

 

BlitzMax 1.50 • Lua 5.1 MaxGUI 1.41 • UU3D Pro • MessiahStudio Pro • Silo Pro

3D Coat • ShaderMap Pro • Hexagon 2 • Photoshop, Gimp & Paint.NET

 

LE 2.5/3.4 • Skyline UE4 • CE3 SDK • Unity 5 • Esenthel Engine 2.0

 

Marleys Ghost's YouTube Channel Marleys Ghost's Blog

 

"I used to be alive like you .... then I took an arrow to the head"

Link to comment
Share on other sites

If you want others to run your code you would also need to post the monsterfuncs.h

AMD Bulldozer FX-4 Quad Core 4100 Black Edition

2 x 4GB DDR3 1333Mhz Memory

Gigabyte GeForce GTX 550 Ti OC 1024MB GDDR5

Windows 7 Home 64 bit

 

BlitzMax 1.50 • Lua 5.1 MaxGUI 1.41 • UU3D Pro • MessiahStudio Pro • Silo Pro

3D Coat • ShaderMap Pro • Hexagon 2 • Photoshop, Gimp & Paint.NET

 

LE 2.5/3.4 • Skyline UE4 • CE3 SDK • Unity 5 • Esenthel Engine 2.0

 

Marleys Ghost's YouTube Channel Marleys Ghost's Blog

 

"I used to be alive like you .... then I took an arrow to the head"

Link to comment
Share on other sites

Simply post monsterfuncs.h as code the same as you did for the main prog.

AMD Bulldozer FX-4 Quad Core 4100 Black Edition

2 x 4GB DDR3 1333Mhz Memory

Gigabyte GeForce GTX 550 Ti OC 1024MB GDDR5

Windows 7 Home 64 bit

 

BlitzMax 1.50 • Lua 5.1 MaxGUI 1.41 • UU3D Pro • MessiahStudio Pro • Silo Pro

3D Coat • ShaderMap Pro • Hexagon 2 • Photoshop, Gimp & Paint.NET

 

LE 2.5/3.4 • Skyline UE4 • CE3 SDK • Unity 5 • Esenthel Engine 2.0

 

Marleys Ghost's YouTube Channel Marleys Ghost's Blog

 

"I used to be alive like you .... then I took an arrow to the head"

Link to comment
Share on other sites

Also what scene.gmf? is it the one for the controller tutorial?

AMD Bulldozer FX-4 Quad Core 4100 Black Edition

2 x 4GB DDR3 1333Mhz Memory

Gigabyte GeForce GTX 550 Ti OC 1024MB GDDR5

Windows 7 Home 64 bit

 

BlitzMax 1.50 • Lua 5.1 MaxGUI 1.41 • UU3D Pro • MessiahStudio Pro • Silo Pro

3D Coat • ShaderMap Pro • Hexagon 2 • Photoshop, Gimp & Paint.NET

 

LE 2.5/3.4 • Skyline UE4 • CE3 SDK • Unity 5 • Esenthel Engine 2.0

 

Marleys Ghost's YouTube Channel Marleys Ghost's Blog

 

"I used to be alive like you .... then I took an arrow to the head"

Link to comment
Share on other sites

Yes is the same of the character controller. And here is monsterfuncs.h:

void SlowPointEnt(TEntity ent1,TEntity ent2,float speed)
{
TVec3 ent1pos=EntityPosition(ent1);
TVec3 ent1rot=EntityRotation(ent1,0);
TVec3 ent2pos=EntityPosition(ent2);
float dx=0.0;
float dy=0.0;
float dz=0.0;
float rz=0.0;
//float speed=1.0;
dx=ent1pos.X-ent2pos.X; 
dy=ent1pos.Y-ent2pos.Y; 
dz=ent1pos.Z-ent2pos.Z;
rz=ent1rot.Z;
return AlignToVector(ent1,Vec3(dx,rz,dz),3,speed);
}

void AnimeEntitySeq(TEntity ent,float startframe=0.0f, float finalframe=1.0f, float vel=1.0f, float partitiontime=100.0f)
{
float frame;
//framebegin=startframe;
//frameend=finalframe;
//Animate(ent,frame,1,0,1);
frame=(AppTime()*vel)/partitiontime;
//frame=fmodf(frame,frameend-framebegin)+framebegin;
frame=fmodf(frame,finalframe-startframe)+startframe;
Animate(ent,frame,1,0,1);
}

Link to comment
Share on other sites

change to 500 or 100 don't solve the problem, thankyou.

 

 

did you just change the acceleration value or did you change the whole line?

 

UpdateController(player,camrotation.Y,move*3,strafe*3,jump,500);

AMD Bulldozer FX-4 Quad Core 4100 Black Edition

2 x 4GB DDR3 1333Mhz Memory

Gigabyte GeForce GTX 550 Ti OC 1024MB GDDR5

Windows 7 Home 64 bit

 

BlitzMax 1.50 • Lua 5.1 MaxGUI 1.41 • UU3D Pro • MessiahStudio Pro • Silo Pro

3D Coat • ShaderMap Pro • Hexagon 2 • Photoshop, Gimp & Paint.NET

 

LE 2.5/3.4 • Skyline UE4 • CE3 SDK • Unity 5 • Esenthel Engine 2.0

 

Marleys Ghost's YouTube Channel Marleys Ghost's Blog

 

"I used to be alive like you .... then I took an arrow to the head"

Link to comment
Share on other sites

but why multiply move and strafe per 3?

 

 

First number I hit :P

 

oddly multiplying by 1 works as well ...

AMD Bulldozer FX-4 Quad Core 4100 Black Edition

2 x 4GB DDR3 1333Mhz Memory

Gigabyte GeForce GTX 550 Ti OC 1024MB GDDR5

Windows 7 Home 64 bit

 

BlitzMax 1.50 • Lua 5.1 MaxGUI 1.41 • UU3D Pro • MessiahStudio Pro • Silo Pro

3D Coat • ShaderMap Pro • Hexagon 2 • Photoshop, Gimp & Paint.NET

 

LE 2.5/3.4 • Skyline UE4 • CE3 SDK • Unity 5 • Esenthel Engine 2.0

 

Marleys Ghost's YouTube Channel Marleys Ghost's Blog

 

"I used to be alive like you .... then I took an arrow to the head"

Link to comment
Share on other sites

:P:lol: Thankyou very much :D

 

 

No Problems .. glad it helped.

AMD Bulldozer FX-4 Quad Core 4100 Black Edition

2 x 4GB DDR3 1333Mhz Memory

Gigabyte GeForce GTX 550 Ti OC 1024MB GDDR5

Windows 7 Home 64 bit

 

BlitzMax 1.50 • Lua 5.1 MaxGUI 1.41 • UU3D Pro • MessiahStudio Pro • Silo Pro

3D Coat • ShaderMap Pro • Hexagon 2 • Photoshop, Gimp & Paint.NET

 

LE 2.5/3.4 • Skyline UE4 • CE3 SDK • Unity 5 • Esenthel Engine 2.0

 

Marleys Ghost's YouTube Channel Marleys Ghost's Blog

 

"I used to be alive like you .... then I took an arrow to the head"

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...