Jump to content

Recommended Posts

Posted

Hi all,

 

I'm newcommer to this forum, few months ago i bought Leadwerks 2.28 SDK, and i want to know if there is anyway to make a vehicle from the scratch (without using any gmf model) in C/C++, i've tried everything (i think) and i only have compiling errors. I will be very greatfull if someone can post a simple c/c++ code for vehicles ( only a cube with 4 cylinders working ).

 

Thanks in advance.

 

BigB

Posted

I don't have an entire example but instead of

chassis = LoadModel(abstract::chassis.gmf) 

you could use the CreateCube and CreateCylinder commands:

http://www.leadwerks.com/wiki/index.php?title=Meshes

 

i've wrote this code:

 

TBody chasis=CreateBodyBox(1.2,0.5,4);

EntityType(chasis,2);

PositionEntity(chasis,Vec3(0.0,8.5,0.0));

SetBodyMass(chasis,800);

 

TVehicle car=CreateVehicle(chasis);

AddVehicleTire(car,Vec3(-0.75,8.0,0),0.3,0.25,70.0,150.0);

 

This is theoricly how it must work no?

 

If i put this code it crashes...

 

 

Then i tried that (change "car" by "chasis" on AddVehicleTire command:

 

TBody chasis=CreateBodyBox(1.2,0.5,4);

EntityType(chasis,2);

PositionEntity(chasis,Vec3(0.0,8.5,0.0));

SetBodyMass(chasis,800);

 

TVehicle car=CreateVehicle(chasis);

AddVehicleTire(chasis,Vec3(-0.75,8.0,0),0.3,0.25,70.0,150.0);

 

It doesn't crash at startup, but when i apply force by adding torque it crashes. I'm blocked, pls help.

 

Thanks in advance.

 

BigB

Posted

Hi BigB,

 

i can't get the vehicle to work in c/c++ either, look's like you are running into the same problems as me.

 

Try changing

 

EntityType(chasis,2);

 

to

 

EntityType(chasis,1);

 

The last working vehicle example in C, was in LE 2.24 it can be found here:

 

http://forum.leadwerks.com/viewtopic.php?f=2&t=3761&p=33322&hilit=vehicle#p33322

 

It was ported to C API by pushedx, maybe it will help you.

Win 7 64, LE 2.31, Liquid Cooled I7-960 @ 4.00GHz, 6GB DDR3 Ram @ 1600mhz, BFG GTX295, Sound Blaster X-FI.

Posted

There's a bug in the engine.dll, because AddVehicleTire returns an Int, although it should return TTire. So the engine crashes when trying to call AddVehicleTire.

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 ■

Posted

Thank's for that info Lumooja, i'll try to alter the header to return TTire then. :)

Win 7 64, LE 2.31, Liquid Cooled I7-960 @ 4.00GHz, 6GB DDR3 Ram @ 1600mhz, BFG GTX295, Sound Blaster X-FI.

Posted

It doesn't help to change the header, since the bug is in the engine.dll. It returns more bytes from the core engine to the dll, so it overwrites unallocated memory and crashes.

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 ■

Posted

Oh ok, do you know if Josh is going to fix this ?

 

I've been trying to get vehicles going for awhile now,

 

and i'd prefer to use c/c++ for vehicles.

 

Thank's.

Win 7 64, LE 2.31, Liquid Cooled I7-960 @ 4.00GHz, 6GB DDR3 Ram @ 1600mhz, BFG GTX295, Sound Blaster X-FI.

Posted

Sure he will fix it, and I posted a bug report in the tracker also.

I think Josh needs to dedicate a few days per month for bug fixing only.

It would be nice to know beforehand when bugs are going to be fixed, for example every 8th day of the month :)

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 ■

Posted

Awesome, thank's for posting bug report.

 

Lol, yea a bug fix day. :)

Win 7 64, LE 2.31, Liquid Cooled I7-960 @ 4.00GHz, 6GB DDR3 Ram @ 1600mhz, BFG GTX295, Sound Blaster X-FI.

Posted

That's incorrect:

Method AddTire:Int(position:TVec3,radius:Float,suspensionlength:Float,springconstant:Float=70.0,springdamping:Float=150.0)

 

AddTire() returns an integer.

 

I'll see about making a C++ vehicle example, although it is going to use a model. I won't do an example out of mesh primitives, because then everyone will ask how to make one with a model.

My job is to make tools you love, with the features you want, and performance you can't live without.

Posted

Why do we need an example?

Just a simple:

TBody car=CreateBodyBox();
SetBodyMass(car,1);
TVehicle veh=CreateVehicle(car);
AddVehicleTire(veh);

Should not crash the engine, especially when veh is a valid pointer.

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 ■

Posted

Here's a fully working example:

#include "engine.h"
int main(){
Initialize();
RegisterAbstractPath("c:/program files/leadwerks engine sdk");
Graphics(800,600);
TFramework fw=CreateFramework();
TBody fuselage=CreateBodyBox();
SetBodyMass(fuselage,1);
TVehicle veh=CreateVehicle(fuselage);
AddVehicleTire(veh); // crash here
while(!KeyHit()){
	UpdateFramework();
	RenderFramework();
	Flip();
}
return Terminate();
}

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 ■

Posted

The cause is the position parameter is declared as a vec3, and it should be a byte ptr. Here is the corrected function:

Function AddVehicleTire_:Int(vehicle:TVehicle,position:Byte Ptr,radius:Float,suspensionlength:Float,springconstant:Float=70.0,springdamping:Float=150.0) "win32"
GCEnter()
Local t:TVec3=New TVec3
MemCopy(t,position,12)
Return vehicle.addtire(t,radius,suspensionlength,springconstant,springdamping)
EndFunction

 

And here is a recompiled DLL:

engine.zip

My job is to make tools you love, with the features you want, and performance you can't live without.

Posted

Crashing stopped, but I can't see any wheels on my car:

#include "engine.h"
int main(){
Initialize();
RegisterAbstractPath("c:/program files/leadwerks engine sdk");
Graphics(800,600);
TFramework fw=CreateFramework();
TBody fuselage=CreateBodyBox();
EntityType(fuselage,1);
SetBodyMass(fuselage,1);
TVehicle veh=CreateVehicle(fuselage);
AddVehicleTire(veh,Vec3(-1,-1,0));
DebugPhysics();
MoveEntity(GetLayerCamera(GetFrameworkLayer(0)),Vec3(0,0,-10));
TBody ground=CreateBodyBox(1000,1,1000);
MoveEntity(ground,Vec3(0,-5,0));
EntityType(ground,1);
Collisions();
while(!KeyHit()){
	UpdateFramework();
	RenderFramework();
	Flip();
}
return Terminate();
}

 

In MoveEntity, the Vec3 is declared as Float Ptr, why not in AddVehicleTire also?

Function MoveEntity_(entity:TEntity,p:Float Ptr,glob:Int=0) "win32"
GCEnter()
?debug
If Not EntityExists(entity) RuntimeError "Invalid object."
?
entity.move(p,glob)
EndFunction

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 ■

Posted

They're basically the same data type.

 

Vehicle tires are not visualized by the physics debugger, since they are just raycasts.

My job is to make tools you love, with the features you want, and performance you can't live without.

Posted

But shouldn't tires have somekind of effect on my cubic car? It just falls flat on the floor, although the wheel should be 1 meter to the left and 1 meter under the box, so the box should at least lay a bit tilted on the floor.

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 ■

Posted

Wow, thank's for recompiled DLL Josh, that was fast. :)

 

And, thank's for the help Lumooja, i'm gonna go try this.

Win 7 64, LE 2.31, Liquid Cooled I7-960 @ 4.00GHz, 6GB DDR3 Ram @ 1600mhz, BFG GTX295, Sound Blaster X-FI.

Posted

Lumooja your code work's, just change:

 

AddVehicleTire(veh,Vec3(-1,-1,0));

 

to

 

AddVehicleTire(veh,Vec3(-1,-1,0), 0.5, 0.3, 45.0, 100.0);

Win 7 64, LE 2.31, Liquid Cooled I7-960 @ 4.00GHz, 6GB DDR3 Ram @ 1600mhz, BFG GTX295, Sound Blaster X-FI.

Posted
#include "engine.h"
int main(){

       Initialize();
       RegisterAbstractPath("C:/Leadwerks Engine SDK");
       Graphics(800,600);

	TFramework fw=CreateFramework();
	DebugPhysics(1);
	Collisions(1,1,1);
	MoveEntity(GetLayerCamera(GetFrameworkLayer(0)),Vec3(0,0,-10));

	TBody fuselage=CreateBodyBox();
       EntityType(fuselage,1);
       SetBodyMass(fuselage,10);

	TLight light=CreateDirectionalLight();
	RotateEntity(light,Vec3(45,45,45));

	TMesh tire[4];

	tire[0]=CreateCylinder();
	tire[1]=CreateCylinder();
	tire[2]=CreateCylinder();
	tire[3]=CreateCylinder();

	RotateMesh(tire[0],Vec3(0,0,90));
	RotateMesh(tire[1],Vec3(0,0,90));
	RotateMesh(tire[2],Vec3(0,0,90));
	RotateMesh(tire[3],Vec3(0,0,90));


	TVehicle veh=CreateVehicle(fuselage);
       AddVehicleTire(veh,Vec3(-1,0,1),0.5,1.0,70,150);
       AddVehicleTire(veh,Vec3(1,0,1),0.5,1.0,70,150);
       AddVehicleTire(veh,Vec3(-1,0,-1),0.5,1.0,70,150);
       AddVehicleTire(veh,Vec3(1,0,-1),0.5,1.0,70,150);

	TBody ground=CreateBodyBox(100,1,100);
       MoveEntity(ground,Vec3(0,-3,0));
       EntityType(ground,1);
	RotateEntity(ground,Vec3(-5,0,0));

	while(!KeyHit()){
               UpdateFramework();

			SetEntityMatrix(tire[0],GetTireMatrix(veh,0));
			SetEntityMatrix(tire[1],GetTireMatrix(veh,1));
			SetEntityMatrix(tire[2],GetTireMatrix(veh,2));
			SetEntityMatrix(tire[3],GetTireMatrix(veh,3));

               RenderFramework();
               Flip();
       }
       return Terminate();
}

My job is to make tools you love, with the features you want, and performance you can't live without.

Posted

Cool, I wonder why the default parameters are so useless...

I think they should be fixed to make a working default result.

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 ■

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.

×
×
  • Create New...