Sammy6200 Posted October 17, 2010 Share Posted October 17, 2010 How would it be possible to make gravity attract towords the center of a giant sphere to simulate a planet with LE? And also, would it be possible to create some sort of event horizon around the sphere that makes the gravity attract when close enough, so it would be possible to create multiple "planets" who all have gravity? Quote c++, 3Ds Max, LE. Link to comment Share on other sites More sharing options...
Canardia Posted October 17, 2010 Share Posted October 17, 2010 It's quite easy, you just need to loop through all physics bodies and add a force to them in direction of the nearest/biggest gravity center. 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...
Sammy6200 Posted October 17, 2010 Author Share Posted October 17, 2010 What functions will allow me to do so? Quote c++, 3Ds Max, LE. Link to comment Share on other sites More sharing options...
Canardia Posted October 17, 2010 Share Posted October 17, 2010 ForEachEntityDo(), TFormVec() and AddBodyForce(). 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...
Sammy6200 Posted October 17, 2010 Author Share Posted October 17, 2010 i dont really understand how to use TFormVector(). TVec3 TFormVector(TVec3 &vector, TEntity src, TEntity dst) What does it return? And what is the Source Entity and the Destination Entity? Quote c++, 3Ds Max, LE. Link to comment Share on other sites More sharing options...
Sammy6200 Posted October 17, 2010 Author Share Posted October 17, 2010 I did this: #include "engine.h" #include <iostream> int main( int argn, char* argv[] ) { Initialize() ; RegisterAbstractPath("C:/Users/Sammy/Desktop/Leadwerks SDK"); SetAppTitle( "New" ) ; Graphics( 800, 500 ) ; AFilter() ; TFilter() ; TWorld world; TBuffer gbuffer; TCamera camera; TMesh mesh; TBody body; TMesh mesh2; TBody body2; TLight light; TMaterial material; world = CreateWorld() ; if (!world) { MessageBoxA(0,"Error","Failed to create world.",0); return Terminate(); } gbuffer=CreateBuffer(GraphicsWidth(),GraphicsHeight(),BUFFER_COLOR|BUFFER_DEPTH|BUFFER_NORMAL); camera=CreateCamera(); PositionEntity(camera,Vec3(0,0,-2)); material=LoadMaterial("abstract::cobblestones.mat"); mesh=CreateSphere(16); body=CreateBodySphere(); EntityParent(mesh,body); PaintEntity(mesh,material); SetBodyMass(body,1); EntityType(body,1); PositionEntity(body,Vec3(0.7,0.5,0.3)); mesh2=CreateSphere(16); body2=CreateBodySphere(); EntityParent(mesh2,body2); PaintEntity(mesh2,material); EntityType(body2,1); PositionEntity(body2,Vec3(-0.7,0,0)); DebugPhysics(1); light=CreateDirectionalLight(); RotateEntity(light,Vec3(45,45,45)); Collisions(1,1,1); SetWorldGravity(Vec3(0,0,0)); TVec3 vector = Vec3(0,0,0); std::string vinfo; // Game loop while( !KeyHit() && !AppTerminate() ) { vector = TFormVector(Vec3(-2,0,0),body,body2); // Update timing and world UpdateAppTime(); UpdateWorld(AppSpeed()) ; // Render SetBuffer(gbuffer); RenderWorld(); SetBuffer(BackBuffer()); RenderLights(gbuffer); AddBodyForce(body,vector,1); // Send to screen Flip(0) ; } // Done return Terminate() ; } It kinda seems to create an gravitation towords the one sphere. Quote c++, 3Ds Max, LE. Link to comment Share on other sites More sharing options...
Canardia Posted October 17, 2010 Share Posted October 17, 2010 The only use I know for TFormVector is to rotate a vector so that it has the same rotation as some entity. So to use it for gravity force, you point a pivot from an object to the gravity center, and then use TFormVector to get that rotation, so you can use it as force vector: PointEntity( pivot, gravitycenter ); // pivot is parented to the object TFormVector( &force, pivot, NULL); AddBodyForce( object, force ); 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...
Ending Credits Posted October 18, 2010 Share Posted October 18, 2010 Remember to divide the Force by the square of the distance from the centre of gravity if you want to make it realistic. Fortunately the distance squared is simply the the sum of the squares of the difference in x, y and z. i.e (x1 - x2)2 + (y1 - y2)2 + (z1 - z2)2 Quote AMD Phenom 9850 (X4 2.5GHz) | 1066MHz CL5 GEIL Black Dragon (800MHz) | Powercolor ATI 4870 1GB | DFI 790FXB-M2RSH | 24" 1920x1200 | Windows Vista 64-bit Ultimate Link to comment Share on other sites More sharing options...
Sammy6200 Posted October 19, 2010 Author Share Posted October 19, 2010 I still can't figure out how to do it Quote c++, 3Ds Max, LE. Link to comment Share on other sites More sharing options...
Sammy6200 Posted October 20, 2010 Author Share Posted October 20, 2010 I got an idea. Can anyone tell me how to get the position of an object? Is there any "GetPosition()" function, that can return the position of a body? Quote c++, 3Ds Max, LE. Link to comment Share on other sites More sharing options...
Gilmer Posted October 20, 2010 Share Posted October 20, 2010 Yes, the EntityPosition(). You can also do this: TVec3 planetpos = EntityPosition(planet); TVec3 objpos = EntityPostion(obj); //x while(objpos.x<planetpos.x){ MoveEntity(obj,Vec3(-1,0,0); } while(objpos.x>planetpos.x){ MoveEntity(obj,Vec3(1,0,0); } //y while(objpos.y<planetpos.y){ MoveEntity(obj,Vec3(0,-1,0); } while(objpos.y>planetpos.y){ MoveEntity(obj,Vec3(0,1,0); } //z while(objpos.z<planetpos.z){ MoveEntity(obj,Vec3(0,0,-1); } while(objpos.z>planetpos.z){ MoveEntity(obj,Vec3(0,0,1); } not a good solution, but it can work. Quote Link to comment Share on other sites More sharing options...
Sammy6200 Posted October 20, 2010 Author Share Posted October 20, 2010 Thanks! Quote c++, 3Ds Max, LE. Link to comment Share on other sites More sharing options...
Sammy6200 Posted October 20, 2010 Author Share Posted October 20, 2010 My solution was this: #include "engine.h" #include <iostream> #include <cmath> int main( int argn, char* argv[] ) { Initialize() ; RegisterAbstractPath("C:/Users/Sammy/Desktop/Leadwerks SDK"); SetAppTitle( "New" ) ; Graphics( 800, 500 ) ; AFilter() ; TFilter() ; TWorld world; TBuffer gbuffer; TCamera camera; TMesh mesh; TBody body; TMesh mesh2; TBody body2; TLight light; TMaterial material; world = CreateWorld() ; if (!world) { MessageBoxA(0,"Error","Failed to create world.",0); return Terminate(); } gbuffer=CreateBuffer(GraphicsWidth(),GraphicsHeight(),BUFFER_COLOR|BUFFER_DEPTH|BUFFER_NORMAL); camera=CreateCamera(); PositionEntity(camera,Vec3(0,0,-2)); mesh=CreateSphere(16); body=CreateBodySphere(); EntityParent(mesh,body); SetBodyMass(body,1); EntityType(body,1); PositionEntity(body,Vec3(-0.8,0,0)); mesh2=CreateSphere(16); body2=CreateBodySphere(); EntityParent(mesh2,body2); SetBodyMass(body2,1); EntityType(body2,1); PositionEntity(body2,Vec3(0.2,0,0)); DebugPhysics(1); light=CreateDirectionalLight(); RotateEntity(light,Vec3(45,45,45)); Collisions(1,1,1); SetWorldGravity(Vec3(0,0,0)); TVec3 b1Vec = Vec3(0,0,0); TVec3 b2Vec = Vec3(0,0,0); TVec3 fVec = Vec3(0,0,0); // Game loop while( !KeyHit() && !AppTerminate() ) { b1Vec = EntityPosition(body); b2Vec = EntityPosition(body2); fVec = Vec3((b1Vec.X - b2Vec.X)*(-1), (b1Vec.Y - b2Vec.Y)*(-1), (b1Vec.Z - b2Vec.Z)*(-1)); AddBodyForce(body,fVec); if(KeyDown(KEY_UP)) { AddBodyForce(body,Vec3(0,10,0)); } if(KeyDown(KEY_DOWN)) { AddBodyForce(body,Vec3(0,-10,0)); } // Update timing and world UpdateAppTime(); UpdateWorld(AppSpeed()) ; // Render SetBuffer(gbuffer); RenderWorld(); SetBuffer(BackBuffer()); RenderLights(gbuffer); // Send to screen Flip(0) ; } // Done return Terminate() ; } And it works perfectly! Quote c++, 3Ds Max, LE. 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.