cassius Posted August 30, 2012 Posted August 30, 2012 I tried to translate this code from Bmax into codeblocks. It loads the scene but nothing moves can anyone see why? It complains about setstats which I commented out. // ==================================================================== // This file was generated by LEBuilder // http://leadwerks.com/werkspace // ==================================================================== #include "engine.h" #include <iostream> #include <string> const int ScreenWidth = 1200; const int ScreenHeight = 900; const char* MediaDir = "C:/mygame"; const char* AppTitle = "game"; TEntity scene; TController player; //Setup the player movement variables. float move = 0.0 ; float strafe = 0.0 ; TVec3 camrotation = Vec3(0); float mx = 0.0 ; float my = 0.0; float jump = 0.0; float camy = 0.0; float camz = 0.0; void ErrOut( const std::string& message ) { std::cerr << message << std::endl; } // ------------------------------- int main( int argn, char* argv[] ) { if( !Initialize() ) return 1; // Set graphics mode SetAppTitle( AppTitle ) ; if( !Graphics(ScreenWidth,ScreenHeight) ) { ErrOut( "Failed to set graphics mode." ); return 1; } RegisterAbstractPath( MediaDir ); // Create framework object and set it to a global object so other scripts can access it TFramework fw = CreateFramework(); if( fw == NULL ) { ErrOut( "Failed to initialize engine." ); return 1; } AFilter(4); TFilter(1); // Set Lua framework object SetGlobalObject( "fw", fw ); // Set Lua framework variable BP lua = GetLuaState(); lua_pushobject( lua, fw ); lua_setglobal( lua, "fw" ); lua_pop( lua, 1 ); // Get framework main camera TCamera camera = GetLayerCamera( GetFrameworkLayer(0) ); PositionEntity( camera, Vec3(3.18,0.2,41.86) ); scene = LoadScene("abstract::game03map.sbx"); //fw.SetStats(1) ; //Create the controller player=CreateController(2.0); PositionEntity(player,EntityPosition(camera)); EntityType(player, 1); SetBodyMass(player, 60.0); Collisions(1, 1, 1); // Skybox SetSkybox(LoadMaterial("abstract::NiceSky.mat")); SetBackgroundColor(Vec4(1 ,1, 1, 1)); HideMouse(); while( !KeyHit() && !AppTerminate() ) { if( !AppSuspended() ) { UpdateAppTime(); UpdateWorld(AppSpeed()); PositionEntity(player,EntityPosition(camera)); mx = Curve(MouseX() - GraphicsWidth() / 2, mx, 6) ; my = Curve(MouseY() - GraphicsHeight() / 2, my, 6); MoveMouse(GraphicsWidth() / 2, GraphicsHeight() / 2) ; camrotation.X = camrotation.X + my / 10.0; camrotation.Y = camrotation.Y - mx / 10.0 ; RotateEntity(fw.Main.camera, camrotation); move = KeyDown(KEY_W) - KeyDown(KEY_S) ; strafe = KeyDown(KEY_D) - KeyDown(KEY_A) ; jump = 0.0; // If (KeyHit(KEY_SPACE) & ! ControllerAirborne(player) ) //jump = 4.0; If (KeyDown(KEY_LSHIFT) ) { move = move * 3.0 ; strafe = strafe * 3.0 ; } PositionEntity(fw.Main.camera, Vec3(player.position.x, player.position.y + 0.8, player.position.z)) ; camy = 0.5 ; If (MouseZ()>0) FlushMouse(); } If (MouseZ()=0) { camy = 0.0 ; camz = Curve(MouseZ(), camz, 10) ; } MoveEntity(fw.Main.camera, Vec3(0,camy,camz)) ; UpdateController(player, camrotation.Y, move * 3, strafe * 3, jump, 500) ; UpdateFramework(); RenderFramework(); Flip( 0 ); } } return Terminate(); Quote amd quad core 4 ghz / geforce 660 ti 2gb / win 10 Blender,gimp,silo2,ac3d,,audacity,Hexagon / using c++
Canardia Posted August 30, 2012 Posted August 30, 2012 C is not OOP, so you can't use fw.something. 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 ■
Roland Posted August 30, 2012 Posted August 30, 2012 while( !KeyHit() && !AppTerminate() ) { if( !AppSuspended() ) { UpdateAppTime(); UpdateWorld(AppSpeed()); PositionEntity(player,EntityPosition(camera)); mx = Curve(MouseX() - GraphicsWidth() / 2, mx, 6) ; my = Curve(MouseY() - GraphicsHeight() / 2, my, 6); MoveMouse(GraphicsWidth() / 2, GraphicsHeight() / 2) ; camrotation.X = camrotation.X + my / 10.0; camrotation.Y = camrotation.Y - mx / 10.0 ; TCamera mainCam = GetLayerCamera( GetFrameworkLayer(0) ); RotateEntity(mainCam, camrotation); move = KeyDown(KEY_W) - KeyDown(KEY_S) ; strafe = KeyDown(KEY_D) - KeyDown(KEY_A) ; jump = 0.0; // If (KeyHit(KEY_SPACE) & ! ControllerAirborne(player) ) //jump = 4.0; if (KeyDown(KEY_LSHIFT) ) { move = move * 3.0 ; strafe = strafe * 3.0 ; } TVec3 playerPos = EntityPosition(player); PositionEntity(mainCam, Vec3(playerPos.X, playerPos.Y + 0.8, playerPos.Z )) ; camy = 0.5 ; if (MouseZ()>0) FlushMouse(); if (MouseZ()==0) { camy = 0.0 ; camz = Curve(MouseZ(), camz, 10) ; } MoveEntity(mainCam, Vec3(0,camy,camz)) ; UpdateController(player, camrotation.Y, move * 3, strafe * 3, jump, 500) ; UpdateFramework(); RenderFramework(); Flip( 0 ); } } Quote Roland Strålberg Website: https://rstralberg.com
flachdrache Posted August 30, 2012 Posted August 30, 2012 What ? ... Iam pretty sure we agreed in some topic that "UpdateFramework()", just like "UpdateFramewerk()", does call an update on world and AppTime already - and that a second use of update calls does nothing but to make the ups displayed wrong. void Framewerk::Update() { UpdateAppTime(); SetWorld( background.GetWorld() ); UpdateWorld( AppSpeed() ); SetWorld( transparency.GetWorld() ); UpdateWorld( AppSpeed() ); SetWorld( main.GetWorld() ); UpdateWorld( AppSpeed() ); } Dont get me wrong - i talk about framework here but i had the intention it should look quit similar ... the version differences are getting on my nerves. ... "UpdateWorld()" is in charge for updating the physics as well afaik - calling it two times should/would/could fobaring quit a lot. Can this be clarified for real this time ?! Quote AMD 64 X2 Dual 5k - 4GB - XFX GForce9800GT - nv196.21 - WinXP Sp3 zBrush4R2 - Silo2Pro - Unwrap3DPro - Gile - MaPZone2.5 Xxploration FPS in progress ...
cassius Posted August 30, 2012 Author Posted August 30, 2012 Thanks Roland I will try that code tonight. I am trying c++ so I can use any examples that come with leadwerks 3d.I havn't used the language since I used c++builder 3 some years ago. I am having the usual noob problems with curly brackets and sem colons etc but its slowly coming back to me. 1 Quote amd quad core 4 ghz / geforce 660 ti 2gb / win 10 Blender,gimp,silo2,ac3d,,audacity,Hexagon / using c++
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.