BigB Posted January 30, 2010 Share Posted January 30, 2010 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 Quote Link to comment Share on other sites More sharing options...
AggrorJorn Posted January 30, 2010 Share Posted January 30, 2010 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 Quote Link to comment Share on other sites More sharing options...
BigB Posted January 30, 2010 Author Share Posted January 30, 2010 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 Quote Link to comment Share on other sites More sharing options...
ZeroByte Posted January 30, 2010 Share Posted January 30, 2010 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. Quote Win 7 64, LE 2.31, Liquid Cooled I7-960 @ 4.00GHz, 6GB DDR3 Ram @ 1600mhz, BFG GTX295, Sound Blaster X-FI. Link to comment Share on other sites More sharing options...
Canardia Posted January 30, 2010 Share Posted January 30, 2010 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. Quote ■ Ryzen 9 ■ RX 6800M ■ 16GB ■ XF8 ■ Windows 11 ■ ■ Ultra ■ LE 2.5 ■ 3DWS 5.6 ■ Reaper ■ C/C++ ■ C# ■ Fortran 2008 ■ Story ■ ■ Homepage: https://canardia.com ■ Link to comment Share on other sites More sharing options...
ZeroByte Posted January 30, 2010 Share Posted January 30, 2010 Thank's for that info Lumooja, i'll try to alter the header to return TTire then. Quote Win 7 64, LE 2.31, Liquid Cooled I7-960 @ 4.00GHz, 6GB DDR3 Ram @ 1600mhz, BFG GTX295, Sound Blaster X-FI. Link to comment Share on other sites More sharing options...
Canardia Posted January 30, 2010 Share Posted January 30, 2010 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. Quote ■ Ryzen 9 ■ RX 6800M ■ 16GB ■ XF8 ■ Windows 11 ■ ■ Ultra ■ LE 2.5 ■ 3DWS 5.6 ■ Reaper ■ C/C++ ■ C# ■ Fortran 2008 ■ Story ■ ■ Homepage: https://canardia.com ■ Link to comment Share on other sites More sharing options...
ZeroByte Posted January 30, 2010 Share Posted January 30, 2010 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. Quote Win 7 64, LE 2.31, Liquid Cooled I7-960 @ 4.00GHz, 6GB DDR3 Ram @ 1600mhz, BFG GTX295, Sound Blaster X-FI. Link to comment Share on other sites More sharing options...
Canardia Posted January 30, 2010 Share Posted January 30, 2010 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 Quote ■ Ryzen 9 ■ RX 6800M ■ 16GB ■ XF8 ■ Windows 11 ■ ■ Ultra ■ LE 2.5 ■ 3DWS 5.6 ■ Reaper ■ C/C++ ■ C# ■ Fortran 2008 ■ Story ■ ■ Homepage: https://canardia.com ■ Link to comment Share on other sites More sharing options...
ZeroByte Posted January 30, 2010 Share Posted January 30, 2010 Awesome, thank's for posting bug report. Lol, yea a bug fix day. Quote Win 7 64, LE 2.31, Liquid Cooled I7-960 @ 4.00GHz, 6GB DDR3 Ram @ 1600mhz, BFG GTX295, Sound Blaster X-FI. Link to comment Share on other sites More sharing options...
Josh Posted January 30, 2010 Share Posted January 30, 2010 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. Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
Canardia Posted January 30, 2010 Share Posted January 30, 2010 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. Quote ■ Ryzen 9 ■ RX 6800M ■ 16GB ■ XF8 ■ Windows 11 ■ ■ Ultra ■ LE 2.5 ■ 3DWS 5.6 ■ Reaper ■ C/C++ ■ C# ■ Fortran 2008 ■ Story ■ ■ Homepage: https://canardia.com ■ Link to comment Share on other sites More sharing options...
macklebee Posted January 30, 2010 Share Posted January 30, 2010 TVehicle veh=CreateVehicle(veh); youre parenting the item you are creating to itself? shouldn't that be: TVehicle veh=CreateVehicle(car) Quote Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590 LE / 3DWS / BMX / Hexagon macklebee's channel Link to comment Share on other sites More sharing options...
Canardia Posted January 30, 2010 Share Posted January 30, 2010 Yes, typo. Quote ■ Ryzen 9 ■ RX 6800M ■ 16GB ■ XF8 ■ Windows 11 ■ ■ Ultra ■ LE 2.5 ■ 3DWS 5.6 ■ Reaper ■ C/C++ ■ C# ■ Fortran 2008 ■ Story ■ ■ Homepage: https://canardia.com ■ Link to comment Share on other sites More sharing options...
Josh Posted January 30, 2010 Share Posted January 30, 2010 Until someone posts a working example we can't be sure there isn't a problem. Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
Canardia Posted January 30, 2010 Share Posted January 30, 2010 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(); } Quote ■ Ryzen 9 ■ RX 6800M ■ 16GB ■ XF8 ■ Windows 11 ■ ■ Ultra ■ LE 2.5 ■ 3DWS 5.6 ■ Reaper ■ C/C++ ■ C# ■ Fortran 2008 ■ Story ■ ■ Homepage: https://canardia.com ■ Link to comment Share on other sites More sharing options...
Josh Posted January 30, 2010 Share Posted January 30, 2010 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 Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
Canardia Posted January 30, 2010 Share Posted January 30, 2010 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 Quote ■ Ryzen 9 ■ RX 6800M ■ 16GB ■ XF8 ■ Windows 11 ■ ■ Ultra ■ LE 2.5 ■ 3DWS 5.6 ■ Reaper ■ C/C++ ■ C# ■ Fortran 2008 ■ Story ■ ■ Homepage: https://canardia.com ■ Link to comment Share on other sites More sharing options...
Josh Posted January 30, 2010 Share Posted January 30, 2010 They're basically the same data type. Vehicle tires are not visualized by the physics debugger, since they are just raycasts. Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
Canardia Posted January 30, 2010 Share Posted January 30, 2010 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. Quote ■ Ryzen 9 ■ RX 6800M ■ 16GB ■ XF8 ■ Windows 11 ■ ■ Ultra ■ LE 2.5 ■ 3DWS 5.6 ■ Reaper ■ C/C++ ■ C# ■ Fortran 2008 ■ Story ■ ■ Homepage: https://canardia.com ■ Link to comment Share on other sites More sharing options...
ZeroByte Posted January 30, 2010 Share Posted January 30, 2010 Wow, thank's for recompiled DLL Josh, that was fast. And, thank's for the help Lumooja, i'm gonna go try this. Quote Win 7 64, LE 2.31, Liquid Cooled I7-960 @ 4.00GHz, 6GB DDR3 Ram @ 1600mhz, BFG GTX295, Sound Blaster X-FI. Link to comment Share on other sites More sharing options...
ZeroByte Posted January 30, 2010 Share Posted January 30, 2010 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); Quote Win 7 64, LE 2.31, Liquid Cooled I7-960 @ 4.00GHz, 6GB DDR3 Ram @ 1600mhz, BFG GTX295, Sound Blaster X-FI. Link to comment Share on other sites More sharing options...
Josh Posted January 30, 2010 Share Posted January 30, 2010 #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(); } Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
Canardia Posted January 30, 2010 Share Posted January 30, 2010 Cool, I wonder why the default parameters are so useless... I think they should be fixed to make a working default result. Quote ■ Ryzen 9 ■ RX 6800M ■ 16GB ■ XF8 ■ Windows 11 ■ ■ Ultra ■ LE 2.5 ■ 3DWS 5.6 ■ Reaper ■ C/C++ ■ C# ■ Fortran 2008 ■ Story ■ ■ Homepage: https://canardia.com ■ Link to comment Share on other sites More sharing options...
Josh Posted January 30, 2010 Share Posted January 30, 2010 It depends on the mass of your chassis and the position of the wheels. Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
Recommended Posts
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.