Compare commits
	
		
			3 Commits
		
	
	
		
			aa1e7fa117
			...
			c9b48a2ea5
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| c9b48a2ea5 | |||
|  | a5c1667d9f | ||
|  | 362de5bee9 | 
| @ -127,8 +127,8 @@ | |||||||
|             "movementSystems" : [ |             "movementSystems" : [ | ||||||
|                 { |                 { | ||||||
|                     "type" : "GROUND", |                     "type" : "GROUND", | ||||||
|                     "acceleration" : 100.0, |                     "acceleration" : 5000.0, | ||||||
|                     "maxVelocity" : 3.5, |                     "maxVelocity" : 500.5, | ||||||
|                     "animationStartup" : { |                     "animationStartup" : { | ||||||
|                         "name" : "Jog", |                         "name" : "Jog", | ||||||
|                         "length" : 1, |                         "length" : 1, | ||||||
| @ -161,8 +161,8 @@ | |||||||
|                 }, |                 }, | ||||||
|                 { |                 { | ||||||
|                     "type" : "JUMP", |                     "type" : "JUMP", | ||||||
|                     "jumpFrames" : 30, |                     "jumpFrames" : 3, | ||||||
|                     "jumpForce" : 0.05, |                     "jumpForce" : 1000, | ||||||
|                     "animationJump" : { |                     "animationJump" : { | ||||||
|                         "name" : "Jump", |                         "name" : "Jump", | ||||||
|                         "length" : 1, |                         "length" : 1, | ||||||
| @ -274,7 +274,7 @@ | |||||||
|                 "rotZ": 0, |                 "rotZ": 0, | ||||||
|                 "rotW": 1, |                 "rotW": 1, | ||||||
|                 "offsetX" : 0, |                 "offsetX" : 0, | ||||||
|                 "offsetY" : 0.45, |                 "offsetY" : 0.4, | ||||||
|                 "offsetZ" : 0 |                 "offsetZ" : 0 | ||||||
|             }, |             }, | ||||||
|             "attackMoves" : [ |             "attackMoves" : [ | ||||||
|  | |||||||
| @ -1,3 +1,3 @@ | |||||||
| #maven.buildNumber.plugin properties file | #maven.buildNumber.plugin properties file | ||||||
| #Thu Mar 21 19:58:26 EDT 2024 | #Sat Mar 23 16:53:49 EDT 2024 | ||||||
| buildNumber=79 | buildNumber=80 | ||||||
|  | |||||||
							
								
								
									
										6
									
								
								docs/src/highlevel-design/economics/economicsindex.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										6
									
								
								docs/src/highlevel-design/economics/economicsindex.md
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,6 @@ | |||||||
|  | @page economicsindex Economics | ||||||
|  | 
 | ||||||
|  | [TOC] | ||||||
|  | - @subpage merchantguilds | ||||||
|  | - @subpage ports | ||||||
|  | 
 | ||||||
							
								
								
									
										8
									
								
								docs/src/highlevel-design/economics/merchantguilds.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								docs/src/highlevel-design/economics/merchantguilds.md
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,8 @@ | |||||||
|  | @page merchantguilds Merchant Guilds | ||||||
|  | 
 | ||||||
|  | What function do they provide? | ||||||
|  | 
 | ||||||
|  | How are they physically represented? | ||||||
|  | 
 | ||||||
|  | Where do you go to start one? | ||||||
|  | 
 | ||||||
							
								
								
									
										10
									
								
								docs/src/highlevel-design/economics/ports.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										10
									
								
								docs/src/highlevel-design/economics/ports.md
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,10 @@ | |||||||
|  | @page ports Ports | ||||||
|  | 
 | ||||||
|  | Buying boats | ||||||
|  | 
 | ||||||
|  | Selling boats | ||||||
|  | 
 | ||||||
|  | Queueing shipping voyages | ||||||
|  | 
 | ||||||
|  | Portmaster's Building | ||||||
|  | 
 | ||||||
| @ -15,3 +15,5 @@ Discussion of, at a high game-design level, how everything should work and conne | |||||||
| - @subpage puzzleindex | - @subpage puzzleindex | ||||||
| - @subpage fluidindex | - @subpage fluidindex | ||||||
| - @subpage locomotion | - @subpage locomotion | ||||||
|  | - @subpage economicsindex | ||||||
|  | - @subpage structuresandbuildings | ||||||
| @ -21,6 +21,7 @@ | |||||||
|  - Overgrown (dense) |  - Overgrown (dense) | ||||||
|  - Mushroom |  - Mushroom | ||||||
|  - Jungle |  - Jungle | ||||||
|  |  - Giant Frozen Taiga (supermassive snow covered pine trees, snow permanently on ground) | ||||||
| 
 | 
 | ||||||
| ## Rolling Hills | ## Rolling Hills | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -4,3 +4,4 @@ | |||||||
|  - @subpage biomeideas |  - @subpage biomeideas | ||||||
|  - @subpage largelocationideas |  - @subpage largelocationideas | ||||||
|  - @subpage macrolocationideas |  - @subpage macrolocationideas | ||||||
|  |  - @subpage smalllocations | ||||||
							
								
								
									
										42
									
								
								docs/src/highlevel-design/locations/smalllocations.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										42
									
								
								docs/src/highlevel-design/locations/smalllocations.md
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,42 @@ | |||||||
|  | @page smalllocations Small Locations | ||||||
|  | 
 | ||||||
|  | Little locations to provide immediate points of interest for the player to spring between | ||||||
|  | 
 | ||||||
|  | ## Puzzle teleporters | ||||||
|  | 
 | ||||||
|  | ## Shrines, torii, etc | ||||||
|  |  - Churches, monestaries, etc that provide resting places for traveleers | ||||||
|  |  - Taverns | ||||||
|  | 
 | ||||||
|  | ## Outposts, Observation Posts | ||||||
|  | 
 | ||||||
|  | ## Bandit Camps | ||||||
|  | 
 | ||||||
|  | ## Small cave networks | ||||||
|  | 
 | ||||||
|  | ## Grottos | ||||||
|  | 
 | ||||||
|  | ## Plant bundles/collection points | ||||||
|  | Berry bushes | ||||||
|  | Clusters of ferns | ||||||
|  | Fruit trees | ||||||
|  | 
 | ||||||
|  | ## Wild animal packs | ||||||
|  | Herds like cows, deer, horses | ||||||
|  | Communal hunters like wolves | ||||||
|  | Solitary animals like bears | ||||||
|  | 
 | ||||||
|  | ## Ore veins | ||||||
|  | 
 | ||||||
|  | ## Mazes full of minotaur | ||||||
|  | 
 | ||||||
|  | ## Crypts | ||||||
|  | 
 | ||||||
|  | ## Ruins | ||||||
|  | 
 | ||||||
|  | ## Obelisks | ||||||
|  | 
 | ||||||
|  | ## Magical Anomalies | ||||||
|  | 
 | ||||||
|  | ## Natural crafting stations | ||||||
|  | 
 | ||||||
| @ -1,8 +1,10 @@ | |||||||
| @page macrosimtimeline Macro Simulation Timeline | @page macrosimtimeline Macro Simulation Timeline | ||||||
| 
 | 
 | ||||||
|  | ## Origins | ||||||
|  | 
 | ||||||
| ## Age of Gods | ## Age of Gods | ||||||
| 
 | 
 | ||||||
| ## First Interregnum | ## Interregnum | ||||||
| 
 | 
 | ||||||
| ## Age of Exploration | ## Age of Exploration | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -9,3 +9,8 @@ Use spring to launch object into target | |||||||
| Correctly ordering blocks to press a button | Correctly ordering blocks to press a button | ||||||
| 
 | 
 | ||||||
| Maze that uses teleportation spell to confuse in three dimensions | Maze that uses teleportation spell to confuse in three dimensions | ||||||
|  | 
 | ||||||
|  | Maze on the ceiling to navigate invisible platforms | ||||||
|  | 
 | ||||||
|  | Pendulums to carry ball to switch that it opens a door with | ||||||
|  | 
 | ||||||
|  | |||||||
| @ -6,3 +6,5 @@ For this, I think we're going to try for 0.25 meter cube voxels in a separate me | |||||||
| 
 | 
 | ||||||
| Problems to be solved: | Problems to be solved: | ||||||
| LOD alongside terrain marching cubes | LOD alongside terrain marching cubes | ||||||
|  | 
 | ||||||
|  | When in building mode, have the ability to place 'parts', ie a section of wall, a section of roof, a beam, etc | ||||||
| @ -179,6 +179,9 @@ Fix Frustum Culling for skybox | |||||||
| 
 | 
 | ||||||
| Fix Character creation preview not working | Fix Character creation preview not working | ||||||
| 
 | 
 | ||||||
|  | (03/23/2024) | ||||||
|  | Physics-controlled objects system | ||||||
|  | 
 | ||||||
| 
 | 
 | ||||||
| # TODO | # TODO | ||||||
| 
 | 
 | ||||||
| @ -190,8 +193,6 @@ Level loading/saving + Basic Editor | |||||||
|    - Menu of types of entities to spawn |    - Menu of types of entities to spawn | ||||||
|    - Button to spawn them at cursor |    - Button to spawn them at cursor | ||||||
| 
 | 
 | ||||||
| Physics-controlled objects system |  | ||||||
| 
 |  | ||||||
| Shader library system | Shader library system | ||||||
|  - Abiltiy to include the shader library in individual files (ie implement #include) |  - Abiltiy to include the shader library in individual files (ie implement #include) | ||||||
|     |     | ||||||
|  | |||||||
| @ -52,7 +52,7 @@ public class FluidCellManager { | |||||||
|     int drawStepdownInterval = 3; |     int drawStepdownInterval = 3; | ||||||
|     int drawStepdownValue = 25; |     int drawStepdownValue = 25; | ||||||
| 
 | 
 | ||||||
|     double drawRadius = 200; |     double drawRadius = 50; | ||||||
|      |      | ||||||
|     int physicsRadius = 3; |     int physicsRadius = 3; | ||||||
|      |      | ||||||
|  | |||||||
| @ -64,6 +64,15 @@ public class ClientSceneWrapper { | |||||||
|         return serverToClientIdMap.get(serverId); |         return serverToClientIdMap.get(serverId); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |     /** | ||||||
|  |      * Checks if the scene wrapper contains the provided server id | ||||||
|  |      * @param serverId The server id | ||||||
|  |      * @return true if the map contains that id, false otherwise | ||||||
|  |      */ | ||||||
|  |     public boolean containsServerId(int serverId){ | ||||||
|  |         return serverToClientIdMap.containsKey(serverId); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
|      * Returns true if the server->client map contains a given id |      * Returns true if the server->client map contains a given id | ||||||
|  | |||||||
| @ -1,6 +1,8 @@ | |||||||
| package electrosphere.client.sim; | package electrosphere.client.sim; | ||||||
| 
 | 
 | ||||||
| import electrosphere.client.targeting.crosshair.Crosshair; | import electrosphere.client.targeting.crosshair.Crosshair; | ||||||
|  | import electrosphere.collision.PhysicsEntityUtils; | ||||||
|  | import electrosphere.collision.PhysicsUtils; | ||||||
| import electrosphere.engine.Globals; | import electrosphere.engine.Globals; | ||||||
| import electrosphere.engine.Main; | import electrosphere.engine.Main; | ||||||
| import electrosphere.entity.Entity; | import electrosphere.entity.Entity; | ||||||
| @ -25,6 +27,7 @@ public class ClientSimulation { | |||||||
|     public void simulate(){ |     public void simulate(){ | ||||||
|         //simulate bullet physics engine step |         //simulate bullet physics engine step | ||||||
|         Globals.clientSceneWrapper.getCollisionEngine().simulatePhysics((float)Globals.timekeeper.getSimFrameTime()); |         Globals.clientSceneWrapper.getCollisionEngine().simulatePhysics((float)Globals.timekeeper.getSimFrameTime()); | ||||||
|  |         Globals.clientSceneWrapper.getCollisionEngine().updateDynamicObjectTransforms(); | ||||||
|         //update actor animations |         //update actor animations | ||||||
|         for(Entity currentEntity : Globals.clientSceneWrapper.getScene().getEntitiesWithTag(EntityTags.DRAWABLE)){ |         for(Entity currentEntity : Globals.clientSceneWrapper.getScene().getEntitiesWithTag(EntityTags.DRAWABLE)){ | ||||||
|             Actor currentActor = EntityUtils.getActor(currentEntity); |             Actor currentActor = EntityUtils.getActor(currentEntity); | ||||||
|  | |||||||
| @ -14,6 +14,7 @@ import org.ode4j.ode.DBox; | |||||||
| import org.ode4j.ode.DCylinder; | import org.ode4j.ode.DCylinder; | ||||||
| import org.ode4j.ode.DSphere; | import org.ode4j.ode.DSphere; | ||||||
| import org.ode4j.ode.DTriMesh; | import org.ode4j.ode.DTriMesh; | ||||||
|  | import org.ode4j.ode.OdeHelper; | ||||||
| 
 | 
 | ||||||
| import electrosphere.entity.types.terrain.TerrainChunkData; | import electrosphere.entity.types.terrain.TerrainChunkData; | ||||||
| 
 | 
 | ||||||
| @ -80,6 +81,29 @@ public class CollisionBodyCreation { | |||||||
|         return collisionEngine.createDBody(geom); |         return collisionEngine.createDBody(geom); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |     /** | ||||||
|  |      * Sets the provided body to be a kinematic body (no gravity applied) | ||||||
|  |      * @param collisionEngine The collision engine | ||||||
|  |      * @param body The body | ||||||
|  |      */ | ||||||
|  |     public static void setKinematic(CollisionEngine collisionEngine, DBody body){ | ||||||
|  |         collisionEngine.setKinematic(body); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |      * Sets the gravity mode of the body | ||||||
|  |      * @param collisionEngine the collision engine | ||||||
|  |      * @param body the body | ||||||
|  |      * @param gravityMode the gravity mode value | ||||||
|  |      */ | ||||||
|  |     public static void setGravityMode(CollisionEngine collisionEngine, DBody body, boolean gravityMode){ | ||||||
|  |         collisionEngine.setGravityMode(body, gravityMode); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     public static void addMass(CollisionEngine collisionEngine, DBody body){ | ||||||
|  |          | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|      |      | ||||||
|     /** |     /** | ||||||
|      * Creates an ode DBody from a terrain chunk data object |      * Creates an ode DBody from a terrain chunk data object | ||||||
|  | |||||||
| @ -43,10 +43,12 @@ import org.ode4j.ode.DSphere; | |||||||
| import org.ode4j.ode.DTriMesh; | import org.ode4j.ode.DTriMesh; | ||||||
| import org.ode4j.ode.DTriMeshData; | import org.ode4j.ode.DTriMeshData; | ||||||
| import org.ode4j.ode.DWorld; | import org.ode4j.ode.DWorld; | ||||||
|  | import org.ode4j.ode.OdeConstants; | ||||||
| import org.ode4j.ode.OdeHelper; | import org.ode4j.ode.OdeHelper; | ||||||
| 
 | 
 | ||||||
| import electrosphere.collision.RayCastCallback.RayCastCallbackData; | import electrosphere.collision.RayCastCallback.RayCastCallbackData; | ||||||
| import electrosphere.collision.collidable.Collidable; | import electrosphere.collision.collidable.Collidable; | ||||||
|  | import electrosphere.engine.Globals; | ||||||
| import electrosphere.entity.Entity; | import electrosphere.entity.Entity; | ||||||
| import electrosphere.entity.EntityDataStrings; | import electrosphere.entity.EntityDataStrings; | ||||||
| import electrosphere.entity.EntityUtils; | import electrosphere.entity.EntityUtils; | ||||||
| @ -71,7 +73,7 @@ public class CollisionEngine { | |||||||
|     private static Semaphore spaceLock = new Semaphore(1); |     private static Semaphore spaceLock = new Semaphore(1); | ||||||
|     private DJointGroup contactgroup; |     private DJointGroup contactgroup; | ||||||
| 
 | 
 | ||||||
|     private static final int MAX_CONTACTS = 1;		// maximum number of contact points per body |     private static final int MAX_CONTACTS = 10;		// maximum number of contact points per body | ||||||
| 
 | 
 | ||||||
|     //The list of dbodies ode should be tracking |     //The list of dbodies ode should be tracking | ||||||
|     List<DBody> bodies = new ArrayList<DBody>(); |     List<DBody> bodies = new ArrayList<DBody>(); | ||||||
| @ -91,6 +93,7 @@ public class CollisionEngine { | |||||||
|     public CollisionEngine(){ |     public CollisionEngine(){ | ||||||
|         world = OdeHelper.createWorld(); |         world = OdeHelper.createWorld(); | ||||||
|         space = OdeHelper.createBHVSpace(Collidable.TYPE_STATIC_BIT); |         space = OdeHelper.createBHVSpace(Collidable.TYPE_STATIC_BIT); | ||||||
|  |         world.setGravity(0,-3,0); | ||||||
|         contactgroup = OdeHelper.createJointGroup(); |         contactgroup = OdeHelper.createJointGroup(); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
| @ -210,9 +213,11 @@ public class CollisionEngine { | |||||||
|      */ |      */ | ||||||
|     public void simulatePhysics(float time){ |     public void simulatePhysics(float time){ | ||||||
|         spaceLock.acquireUninterruptibly(); |         spaceLock.acquireUninterruptibly(); | ||||||
| 		space.collide(0,nearCallback); |         OdeHelper.spaceCollide(space, 0, nearCallback); | ||||||
|         // space.collide2(space, collisionWorldData, nearCallback); |         // space.collide2(space, collisionWorldData, nearCallback); | ||||||
| 		// world.quickStep(ENGINE_STEP_SIZE); | 
 | ||||||
|  |         //simulate physics | ||||||
|  | 		world.quickStep(ENGINE_STEP_SIZE); | ||||||
| 
 | 
 | ||||||
| 		// remove all contact joints | 		// remove all contact joints | ||||||
| 		contactgroup.empty(); | 		contactgroup.empty(); | ||||||
| @ -247,12 +252,13 @@ public class CollisionEngine { | |||||||
| 		DContactBuffer contacts = new DContactBuffer(MAX_CONTACTS);   // up to MAX_CONTACTS contacts per box-box | 		DContactBuffer contacts = new DContactBuffer(MAX_CONTACTS);   // up to MAX_CONTACTS contacts per box-box | ||||||
| 		for (int i=0; i<MAX_CONTACTS; i++) { | 		for (int i=0; i<MAX_CONTACTS; i++) { | ||||||
| 			DContact contact = contacts.get(i); | 			DContact contact = contacts.get(i); | ||||||
| 			contact.surface.mode = dContactBounce | dContactSoftCFM; | 			contact.surface.mode = OdeConstants.dContactApprox1 & OdeConstants.dContactRolling;//dContactBounce | dContactSoftCFM; | ||||||
| 			contact.surface.mu = dInfinity; | 			contact.surface.mu = 10; | ||||||
| 			contact.surface.mu2 = 0; |             // contact.surface.mu = dInfinity; | ||||||
| 			contact.surface.bounce = 0.1; | 			// contact.surface.mu2 = 0; | ||||||
| 			contact.surface.bounce_vel = 0.1; | 			// contact.surface.bounce = 0.1; | ||||||
| 			contact.surface.soft_cfm = 0.01; | 			// contact.surface.bounce_vel = 0.1; | ||||||
|  | 			// contact.surface.soft_cfm = 0.01; | ||||||
| 		} | 		} | ||||||
|         if( |         if( | ||||||
|             bodyPointerMap.get(b1) != null && |             bodyPointerMap.get(b1) != null && | ||||||
| @ -367,12 +373,12 @@ public class CollisionEngine { | |||||||
|      * Main function to resynchronize entity positions with physics object positions after impulses are applied. |      * Main function to resynchronize entity positions with physics object positions after impulses are applied. | ||||||
|      */ |      */ | ||||||
|     public void updateDynamicObjectTransforms(){ |     public void updateDynamicObjectTransforms(){ | ||||||
|  |         spaceLock.acquireUninterruptibly(); | ||||||
|         for(Collidable collidable : collidableList){ |         for(Collidable collidable : collidableList){ | ||||||
|             if(collidable.getParentTracksCollidable()){ |             if(collidable.getParentTracksCollidable()){ | ||||||
|                 Entity physicsEntity = collidable.getParent(); |                 Entity physicsEntity = collidable.getParent(); | ||||||
|                 DBody rigidBody = (DBody)physicsEntity.getData(EntityDataStrings.PHYSICS_COLLISION_BODY); |                 DBody rigidBody = (DBody)physicsEntity.getData(EntityDataStrings.PHYSICS_COLLISION_BODY); | ||||||
|                 Matrix4d transform = PhysicsEntityUtils.getEntityCollidableTransform(physicsEntity); |                 Matrix4d inverseTransform = new Matrix4d(); | ||||||
|                 Matrix4d inverseTransform = transform.invert(); |  | ||||||
|                 Vector4d rawPos = inverseTransform.transform(new Vector4d(PhysicsUtils.getRigidBodyPosition(rigidBody),1)); |                 Vector4d rawPos = inverseTransform.transform(new Vector4d(PhysicsUtils.getRigidBodyPosition(rigidBody),1)); | ||||||
|                 Vector3d newPosition = new Vector3d(rawPos.x,rawPos.y,rawPos.z); |                 Vector3d newPosition = new Vector3d(rawPos.x,rawPos.y,rawPos.z); | ||||||
|                 Quaterniond newRotation = PhysicsUtils.getRigidBodyRotation(rigidBody); |                 Quaterniond newRotation = PhysicsUtils.getRigidBodyRotation(rigidBody); | ||||||
| @ -380,6 +386,7 @@ public class CollisionEngine { | |||||||
|                 EntityUtils.getRotation(physicsEntity).set(newRotation); |                 EntityUtils.getRotation(physicsEntity).set(newRotation); | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|  |         spaceLock.release(); | ||||||
|     } |     } | ||||||
|      |      | ||||||
|     public void registerCollisionObject(DBody body, Collidable collidable){ |     public void registerCollisionObject(DBody body, Collidable collidable){ | ||||||
| @ -638,7 +645,7 @@ public class CollisionEngine { | |||||||
|     protected DMass createDMass(double massValue, DBody body){ |     protected DMass createDMass(double massValue, DBody body){ | ||||||
|         spaceLock.acquireUninterruptibly(); |         spaceLock.acquireUninterruptibly(); | ||||||
|         DMass mass = OdeHelper.createMass(); |         DMass mass = OdeHelper.createMass(); | ||||||
|         body.setMass(mass); |         mass.setMass(massValue); | ||||||
|         spaceLock.release(); |         spaceLock.release(); | ||||||
|         return mass; |         return mass; | ||||||
|     } |     } | ||||||
| @ -724,4 +731,13 @@ public class CollisionEngine { | |||||||
|         spaceLock.release(); |         spaceLock.release(); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |     /** | ||||||
|  |      * Sets the gravity mode of the body | ||||||
|  |      * @param body the body | ||||||
|  |      * @param gravityMode the gravity mode | ||||||
|  |      */ | ||||||
|  |     protected void setGravityMode(DBody body, boolean gravityMode){ | ||||||
|  |         body.setGravityMode(gravityMode); | ||||||
|  |     } | ||||||
|  |      | ||||||
| } | } | ||||||
|  | |||||||
| @ -5,6 +5,7 @@ import org.joml.Matrix4f; | |||||||
| import org.joml.Vector3d; | import org.joml.Vector3d; | ||||||
| import org.joml.Vector3f; | import org.joml.Vector3f; | ||||||
| import org.ode4j.ode.DBody; | import org.ode4j.ode.DBody; | ||||||
|  | import org.ode4j.ode.DCylinder; | ||||||
| import org.ode4j.ode.DTriMesh; | import org.ode4j.ode.DTriMesh; | ||||||
| 
 | 
 | ||||||
| import electrosphere.collision.collidable.Collidable; | import electrosphere.collision.collidable.Collidable; | ||||||
| @ -44,6 +45,8 @@ public class PhysicsEntityUtils { | |||||||
|                     physicsTemplate.getDimension2(), |                     physicsTemplate.getDimension2(), | ||||||
|                     Collidable.TYPE_CREATURE_BIT |                     Collidable.TYPE_CREATURE_BIT | ||||||
|                 ); |                 ); | ||||||
|  |                 DCylinder cylinder = (DCylinder)rigidBody.getGeomIterator().next(); | ||||||
|  |                 cylinder.setOffsetPosition(physicsTemplate.getOffsetX(), physicsTemplate.getOffsetY(), physicsTemplate.getOffsetZ()); | ||||||
|                 collidable = new Collidable(rVal, Collidable.TYPE_CREATURE); |                 collidable = new Collidable(rVal, Collidable.TYPE_CREATURE); | ||||||
|                 ClientCollidableTree tree = new ClientCollidableTree(rVal,collidable,rigidBody); |                 ClientCollidableTree tree = new ClientCollidableTree(rVal,collidable,rigidBody); | ||||||
|                 rVal.putData(EntityDataStrings.PHYSICS_COLLISION_BODY, rigidBody); |                 rVal.putData(EntityDataStrings.PHYSICS_COLLISION_BODY, rigidBody); | ||||||
| @ -51,7 +54,6 @@ public class PhysicsEntityUtils { | |||||||
|                     physicsTemplate.getOffsetX(), physicsTemplate.getOffsetY(), physicsTemplate.getOffsetZ(), //translate |                     physicsTemplate.getOffsetX(), physicsTemplate.getOffsetY(), physicsTemplate.getOffsetZ(), //translate | ||||||
|                     physicsTemplate.getRotX(), physicsTemplate.getRotY(), physicsTemplate.getRotZ(), physicsTemplate.getRotW() //rotate |                     physicsTemplate.getRotX(), physicsTemplate.getRotY(), physicsTemplate.getRotZ(), physicsTemplate.getRotW() //rotate | ||||||
|                 ); |                 ); | ||||||
|                 rVal.putData(EntityDataStrings.PHYSICS_COLLISION_BODY_OFFSET, new Vector3f(physicsTemplate.getOffsetX(),physicsTemplate.getOffsetY(),physicsTemplate.getOffsetZ())); |  | ||||||
|                 rVal.putData(EntityDataStrings.PHYSICS_COLLISION_BODY_TRANSFORM, offsetTransform); |                 rVal.putData(EntityDataStrings.PHYSICS_COLLISION_BODY_TRANSFORM, offsetTransform); | ||||||
|                 rVal.putData(EntityDataStrings.PHYSICS_MODEL_TEMPLATE, physicsTemplate); |                 rVal.putData(EntityDataStrings.PHYSICS_MODEL_TEMPLATE, physicsTemplate); | ||||||
|                 rVal.putData(EntityDataStrings.PHYSICS_COLLIDABLE, collidable); |                 rVal.putData(EntityDataStrings.PHYSICS_COLLIDABLE, collidable); | ||||||
| @ -59,13 +61,6 @@ public class PhysicsEntityUtils { | |||||||
| 
 | 
 | ||||||
|                 scale = new Vector3f(physicsTemplate.getDimension1(),physicsTemplate.getDimension2(),physicsTemplate.getDimension3()); |                 scale = new Vector3f(physicsTemplate.getDimension1(),physicsTemplate.getDimension2(),physicsTemplate.getDimension3()); | ||||||
|                 rVal.putData(EntityDataStrings.PHYSICS_MASS, mass); |                 rVal.putData(EntityDataStrings.PHYSICS_MASS, mass); | ||||||
|                 //inertia tensor |  | ||||||
|                 //https://scienceworld.wolfram.com/physics/MomentofInertiaCylinder.html |  | ||||||
|                 inertiaTensor = new Matrix4f(); |  | ||||||
|                 inertiaTensor.m00(mass * scale.y * scale.y / 12.0f + mass * scale.x * scale.x / 4.0f); |  | ||||||
|                 inertiaTensor.m11(mass * scale.y * scale.y / 12.0f + mass * scale.x * scale.x / 4.0f); |  | ||||||
|                 inertiaTensor.m22(mass * scale.x * scale.x / 2.0f); |  | ||||||
|                 rVal.putData(EntityDataStrings.PHYSICS_INVERSE_INERTIA_TENSOR, inertiaTensor.invert()); |  | ||||||
| 
 | 
 | ||||||
|                 Globals.clientSceneWrapper.getCollisionEngine().registerCollisionObject(rigidBody, collidable); |                 Globals.clientSceneWrapper.getCollisionEngine().registerCollisionObject(rigidBody, collidable); | ||||||
|                 Globals.clientScene.registerEntityToTag(rVal, EntityTags.COLLIDABLE); |                 Globals.clientScene.registerEntityToTag(rVal, EntityTags.COLLIDABLE); | ||||||
| @ -84,7 +79,6 @@ public class PhysicsEntityUtils { | |||||||
|                     physicsTemplate.getRotX(), physicsTemplate.getRotY(), physicsTemplate.getRotZ(), physicsTemplate.getRotW(), //rotate |                     physicsTemplate.getRotX(), physicsTemplate.getRotY(), physicsTemplate.getRotZ(), physicsTemplate.getRotW(), //rotate | ||||||
|                     1, 1, 1 //scale |                     1, 1, 1 //scale | ||||||
|                 ); |                 ); | ||||||
|                 rVal.putData(EntityDataStrings.PHYSICS_COLLISION_BODY_OFFSET, new Vector3f(physicsTemplate.getOffsetX(),physicsTemplate.getOffsetY(),physicsTemplate.getOffsetZ())); |  | ||||||
|                 rVal.putData(EntityDataStrings.PHYSICS_COLLISION_BODY_TRANSFORM, offsetTransform); |                 rVal.putData(EntityDataStrings.PHYSICS_COLLISION_BODY_TRANSFORM, offsetTransform); | ||||||
|                 rVal.putData(EntityDataStrings.PHYSICS_MODEL_TEMPLATE, physicsTemplate); |                 rVal.putData(EntityDataStrings.PHYSICS_MODEL_TEMPLATE, physicsTemplate); | ||||||
|                 rVal.putData(EntityDataStrings.PHYSICS_COLLIDABLE, collidable); |                 rVal.putData(EntityDataStrings.PHYSICS_COLLIDABLE, collidable); | ||||||
| @ -92,10 +86,6 @@ public class PhysicsEntityUtils { | |||||||
| 
 | 
 | ||||||
|                 scale = new Vector3f(physicsTemplate.getDimension1(),physicsTemplate.getDimension2(),physicsTemplate.getDimension3()); |                 scale = new Vector3f(physicsTemplate.getDimension1(),physicsTemplate.getDimension2(),physicsTemplate.getDimension3()); | ||||||
|                 rVal.putData(EntityDataStrings.PHYSICS_MASS, mass); |                 rVal.putData(EntityDataStrings.PHYSICS_MASS, mass); | ||||||
|                 //inertia tensor |  | ||||||
|                 //https://hepweb.ucsd.edu/ph110b/110b_notes/node26.html |  | ||||||
|                 inertiaTensor = new Matrix4f().identity().scale(mass * scale.x * scale.x / 6.0f).m33(1); |  | ||||||
|                 rVal.putData(EntityDataStrings.PHYSICS_INVERSE_INERTIA_TENSOR, inertiaTensor.invert()); |  | ||||||
| 
 | 
 | ||||||
|                 Globals.clientSceneWrapper.getCollisionEngine().registerCollisionObject(rigidBody, collidable); |                 Globals.clientSceneWrapper.getCollisionEngine().registerCollisionObject(rigidBody, collidable); | ||||||
|                 Globals.clientScene.registerEntityToTag(rVal, EntityTags.COLLIDABLE); |                 Globals.clientScene.registerEntityToTag(rVal, EntityTags.COLLIDABLE); | ||||||
| @ -111,7 +101,7 @@ public class PhysicsEntityUtils { | |||||||
|      * @param physicsTemplate The collidable template |      * @param physicsTemplate The collidable template | ||||||
|      */ |      */ | ||||||
|     public static void serverAttachCollidableTemplate(Realm realm, Entity rVal, CollidableTemplate physicsTemplate){ |     public static void serverAttachCollidableTemplate(Realm realm, Entity rVal, CollidableTemplate physicsTemplate){ | ||||||
|         DBody rigidBody; |         DBody rigidBody = null; | ||||||
|         Collidable collidable; |         Collidable collidable; | ||||||
|         float mass = 1.0f; |         float mass = 1.0f; | ||||||
|         Matrix4f inertiaTensor; |         Matrix4f inertiaTensor; | ||||||
| @ -124,23 +114,23 @@ public class PhysicsEntityUtils { | |||||||
|                     physicsTemplate.getDimension2(), |                     physicsTemplate.getDimension2(), | ||||||
|                     Collidable.TYPE_CREATURE_BIT |                     Collidable.TYPE_CREATURE_BIT | ||||||
|                 ); |                 ); | ||||||
|  |                 DCylinder cylinder = (DCylinder)rigidBody.getGeomIterator().next(); | ||||||
|  |                 cylinder.setOffsetPosition(physicsTemplate.getOffsetX(), physicsTemplate.getOffsetY(), physicsTemplate.getOffsetZ()); | ||||||
|                 collidable = new Collidable(rVal, Collidable.TYPE_CREATURE); |                 collidable = new Collidable(rVal, Collidable.TYPE_CREATURE); | ||||||
|                 ServerCollidableTree tree = new ServerCollidableTree(rVal,collidable,rigidBody); |                 ServerCollidableTree tree = new ServerCollidableTree(rVal,collidable,rigidBody); | ||||||
|                 rVal.putData(EntityDataStrings.PHYSICS_COLLISION_BODY, rigidBody); |                 rVal.putData(EntityDataStrings.PHYSICS_COLLISION_BODY, rigidBody); | ||||||
|                 rVal.putData(EntityDataStrings.PHYSICS_COLLISION_BODY_OFFSET, new Vector3f(physicsTemplate.getOffsetX(),physicsTemplate.getOffsetY(),physicsTemplate.getOffsetZ())); |                 Matrix4d offsetTransform = new Matrix4d().translationRotateScale( | ||||||
|  |                     physicsTemplate.getOffsetX(), physicsTemplate.getOffsetY(), physicsTemplate.getOffsetZ(), //translate | ||||||
|  |                     physicsTemplate.getRotX(), physicsTemplate.getRotY(), physicsTemplate.getRotZ(), physicsTemplate.getRotW(), //rotate | ||||||
|  |                     1, 1, 1 //scale | ||||||
|  |                 ); | ||||||
|  |                 rVal.putData(EntityDataStrings.PHYSICS_COLLISION_BODY_TRANSFORM, offsetTransform); | ||||||
|                 rVal.putData(EntityDataStrings.PHYSICS_MODEL_TEMPLATE, physicsTemplate); |                 rVal.putData(EntityDataStrings.PHYSICS_MODEL_TEMPLATE, physicsTemplate); | ||||||
|                 rVal.putData(EntityDataStrings.PHYSICS_COLLIDABLE, collidable); |                 rVal.putData(EntityDataStrings.PHYSICS_COLLIDABLE, collidable); | ||||||
|                 rVal.putData(EntityDataStrings.SERVER_COLLIDABLE_TREE, tree); |                 rVal.putData(EntityDataStrings.SERVER_COLLIDABLE_TREE, tree); | ||||||
| 
 | 
 | ||||||
|                 scale = new Vector3f(physicsTemplate.getDimension1(),physicsTemplate.getDimension2(),physicsTemplate.getDimension3()); |                 scale = new Vector3f(physicsTemplate.getDimension1(),physicsTemplate.getDimension2(),physicsTemplate.getDimension3()); | ||||||
|                 rVal.putData(EntityDataStrings.PHYSICS_MASS, mass); |                 rVal.putData(EntityDataStrings.PHYSICS_MASS, mass); | ||||||
|                 //inertia tensor |  | ||||||
|                 //https://scienceworld.wolfram.com/physics/MomentofInertiaCylinder.html |  | ||||||
|                 inertiaTensor = new Matrix4f(); |  | ||||||
|                 inertiaTensor.m00(mass * scale.y * scale.y / 12.0f + mass * scale.x * scale.x / 4.0f); |  | ||||||
|                 inertiaTensor.m11(mass * scale.y * scale.y / 12.0f + mass * scale.x * scale.x / 4.0f); |  | ||||||
|                 inertiaTensor.m22(mass * scale.x * scale.x / 2.0f); |  | ||||||
|                 rVal.putData(EntityDataStrings.PHYSICS_INVERSE_INERTIA_TENSOR, inertiaTensor.invert()); |  | ||||||
| 
 | 
 | ||||||
|                 realm.getCollisionEngine().registerCollisionObject(rigidBody, collidable); |                 realm.getCollisionEngine().registerCollisionObject(rigidBody, collidable); | ||||||
|                 ServerEntityTagUtils.attachTagToEntity(rVal, EntityTags.COLLIDABLE); |                 ServerEntityTagUtils.attachTagToEntity(rVal, EntityTags.COLLIDABLE); | ||||||
| @ -150,17 +140,18 @@ public class PhysicsEntityUtils { | |||||||
|                 collidable = new Collidable(rVal, Collidable.TYPE_CREATURE); |                 collidable = new Collidable(rVal, Collidable.TYPE_CREATURE); | ||||||
|                 ServerCollidableTree tree = new ServerCollidableTree(rVal,collidable,rigidBody); |                 ServerCollidableTree tree = new ServerCollidableTree(rVal,collidable,rigidBody); | ||||||
|                 rVal.putData(EntityDataStrings.PHYSICS_COLLISION_BODY, rigidBody); |                 rVal.putData(EntityDataStrings.PHYSICS_COLLISION_BODY, rigidBody); | ||||||
|                 rVal.putData(EntityDataStrings.PHYSICS_COLLISION_BODY_OFFSET, new Vector3f(physicsTemplate.getOffsetX(),physicsTemplate.getOffsetY(),physicsTemplate.getOffsetZ())); |                 Matrix4d offsetTransform = new Matrix4d().translationRotateScale( | ||||||
|  |                     physicsTemplate.getOffsetX(), physicsTemplate.getOffsetY(), physicsTemplate.getOffsetZ(), //translate | ||||||
|  |                     physicsTemplate.getRotX(), physicsTemplate.getRotY(), physicsTemplate.getRotZ(), physicsTemplate.getRotW(), //rotate | ||||||
|  |                     1, 1, 1 //scale | ||||||
|  |                 ); | ||||||
|  |                 rVal.putData(EntityDataStrings.PHYSICS_COLLISION_BODY_TRANSFORM, offsetTransform); | ||||||
|                 rVal.putData(EntityDataStrings.PHYSICS_MODEL_TEMPLATE, physicsTemplate); |                 rVal.putData(EntityDataStrings.PHYSICS_MODEL_TEMPLATE, physicsTemplate); | ||||||
|                 rVal.putData(EntityDataStrings.PHYSICS_COLLIDABLE, collidable); |                 rVal.putData(EntityDataStrings.PHYSICS_COLLIDABLE, collidable); | ||||||
|                 rVal.putData(EntityDataStrings.SERVER_COLLIDABLE_TREE, tree); |                 rVal.putData(EntityDataStrings.SERVER_COLLIDABLE_TREE, tree); | ||||||
| 
 | 
 | ||||||
|                 scale = new Vector3f(physicsTemplate.getDimension1(),physicsTemplate.getDimension2(),physicsTemplate.getDimension3()); |                 scale = new Vector3f(physicsTemplate.getDimension1(),physicsTemplate.getDimension2(),physicsTemplate.getDimension3()); | ||||||
|                 rVal.putData(EntityDataStrings.PHYSICS_MASS, mass); |                 rVal.putData(EntityDataStrings.PHYSICS_MASS, mass); | ||||||
|                 //inertia tensor |  | ||||||
|                 //https://hepweb.ucsd.edu/ph110b/110b_notes/node26.html |  | ||||||
|                 inertiaTensor = new Matrix4f().identity().scale(mass * scale.x * scale.x / 6.0f).m33(1); |  | ||||||
|                 rVal.putData(EntityDataStrings.PHYSICS_INVERSE_INERTIA_TENSOR, inertiaTensor.invert()); |  | ||||||
| 
 | 
 | ||||||
|                 realm.getCollisionEngine().registerCollisionObject(rigidBody, collidable); |                 realm.getCollisionEngine().registerCollisionObject(rigidBody, collidable); | ||||||
|                 ServerEntityTagUtils.attachTagToEntity(rVal, EntityTags.COLLIDABLE); |                 ServerEntityTagUtils.attachTagToEntity(rVal, EntityTags.COLLIDABLE); | ||||||
| @ -175,6 +166,7 @@ public class PhysicsEntityUtils { | |||||||
|      * [CLIENT ONLY] Attaches a heightmap dbody to an entity |      * [CLIENT ONLY] Attaches a heightmap dbody to an entity | ||||||
|      * @param terrain The terrain entity |      * @param terrain The terrain entity | ||||||
|      * @param heightfield The heightfield values |      * @param heightfield The heightfield values | ||||||
|  |      *  | ||||||
|      * @return The DBody created |      * @return The DBody created | ||||||
|      */ |      */ | ||||||
|     public static DBody clientAttachTerrainRigidBody(Entity terrain, CollisionEngine collisionEngine, float[][] heightfield){ |     public static DBody clientAttachTerrainRigidBody(Entity terrain, CollisionEngine collisionEngine, float[][] heightfield){ | ||||||
| @ -256,6 +248,8 @@ public class PhysicsEntityUtils { | |||||||
|     public static DBody clientAttachTerrainChunkRigidBody(Entity terrain, TerrainChunkData data){ |     public static DBody clientAttachTerrainChunkRigidBody(Entity terrain, TerrainChunkData data){ | ||||||
|         Vector3d position = EntityUtils.getPosition(terrain); |         Vector3d position = EntityUtils.getPosition(terrain); | ||||||
|         DBody terrainBody = CollisionBodyCreation.generateBodyFromTerrainData(Globals.clientSceneWrapper.getCollisionEngine(), data,Collidable.TYPE_STATIC_BIT); |         DBody terrainBody = CollisionBodyCreation.generateBodyFromTerrainData(Globals.clientSceneWrapper.getCollisionEngine(), data,Collidable.TYPE_STATIC_BIT); | ||||||
|  |         CollisionBodyCreation.setKinematic(Globals.clientSceneWrapper.getCollisionEngine(), terrainBody); | ||||||
|  |         CollisionBodyCreation.setGravityMode(Globals.clientSceneWrapper.getCollisionEngine(), terrainBody, false); | ||||||
|          |          | ||||||
|          |          | ||||||
|         Globals.clientSceneWrapper.getCollisionEngine().registerCollisionObject(terrainBody, new Collidable(terrain,Collidable.TYPE_TERRAIN)); |         Globals.clientSceneWrapper.getCollisionEngine().registerCollisionObject(terrainBody, new Collidable(terrain,Collidable.TYPE_TERRAIN)); | ||||||
| @ -275,6 +269,8 @@ public class PhysicsEntityUtils { | |||||||
|         Vector3d position = EntityUtils.getPosition(terrain); |         Vector3d position = EntityUtils.getPosition(terrain); | ||||||
|         Realm terrainRealm = Globals.realmManager.getEntityRealm(terrain); |         Realm terrainRealm = Globals.realmManager.getEntityRealm(terrain); | ||||||
|         DBody terrainBody = CollisionBodyCreation.generateBodyFromTerrainData(terrainRealm.getCollisionEngine(),data,Collidable.TYPE_STATIC_BIT); |         DBody terrainBody = CollisionBodyCreation.generateBodyFromTerrainData(terrainRealm.getCollisionEngine(),data,Collidable.TYPE_STATIC_BIT); | ||||||
|  |         CollisionBodyCreation.setKinematic(terrainRealm.getCollisionEngine(), terrainBody); | ||||||
|  |         CollisionBodyCreation.setGravityMode(terrainRealm.getCollisionEngine(), terrainBody, false); | ||||||
|          |          | ||||||
|         terrainRealm.getCollisionEngine().registerCollisionObject(terrainBody, new Collidable(terrain,Collidable.TYPE_TERRAIN)); |         terrainRealm.getCollisionEngine().registerCollisionObject(terrainBody, new Collidable(terrain,Collidable.TYPE_TERRAIN)); | ||||||
|         terrain.putData(EntityDataStrings.PHYSICS_COLLISION_BODY, terrainBody); |         terrain.putData(EntityDataStrings.PHYSICS_COLLISION_BODY, terrainBody); | ||||||
| @ -291,4 +287,13 @@ public class PhysicsEntityUtils { | |||||||
|         return (Matrix4d) entity.getData(EntityDataStrings.PHYSICS_COLLISION_BODY_TRANSFORM); |         return (Matrix4d) entity.getData(EntityDataStrings.PHYSICS_COLLISION_BODY_TRANSFORM); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |     /** | ||||||
|  |      * Gets the DBody attached to an entity | ||||||
|  |      * @param entity the entity | ||||||
|  |      * @return The dbody if it exists, null otherwise | ||||||
|  |      */ | ||||||
|  |     public static DBody getDBody(Entity entity){ | ||||||
|  |         return (DBody)entity.getData(EntityDataStrings.PHYSICS_COLLISION_BODY); | ||||||
|  |     } | ||||||
|  |      | ||||||
| } | } | ||||||
|  | |||||||
| @ -81,7 +81,7 @@ import electrosphere.controls.Control.ControlType; | |||||||
| import electrosphere.engine.Globals; | import electrosphere.engine.Globals; | ||||||
| import electrosphere.engine.Main; | import electrosphere.engine.Main; | ||||||
| import electrosphere.entity.Entity; | import electrosphere.entity.Entity; | ||||||
| import electrosphere.entity.state.BehaviorTree; | import electrosphere.entity.btree.BehaviorTree; | ||||||
| import electrosphere.entity.state.attack.AttackTree; | import electrosphere.entity.state.attack.AttackTree; | ||||||
| import electrosphere.entity.state.attack.ShooterTree; | import electrosphere.entity.state.attack.ShooterTree; | ||||||
| import electrosphere.entity.state.equip.EquipState; | import electrosphere.entity.state.equip.EquipState; | ||||||
|  | |||||||
| @ -7,11 +7,13 @@ import org.joml.Vector3d; | |||||||
| 
 | 
 | ||||||
| import electrosphere.engine.Globals; | import electrosphere.engine.Globals; | ||||||
| import electrosphere.engine.assetmanager.AssetDataStrings; | import electrosphere.engine.assetmanager.AssetDataStrings; | ||||||
|  | import electrosphere.entity.ClientEntityUtils; | ||||||
| import electrosphere.entity.Entity; | import electrosphere.entity.Entity; | ||||||
| import electrosphere.entity.EntityCreationUtils; | import electrosphere.entity.EntityCreationUtils; | ||||||
| import electrosphere.entity.EntityDataStrings; | import electrosphere.entity.EntityDataStrings; | ||||||
| import electrosphere.entity.EntityUtils; | import electrosphere.entity.EntityUtils; | ||||||
| import electrosphere.entity.ServerEntityUtils; | import electrosphere.entity.ServerEntityUtils; | ||||||
|  | import electrosphere.entity.types.object.ObjectUtils; | ||||||
| import electrosphere.game.server.world.ServerWorldData; | import electrosphere.game.server.world.ServerWorldData; | ||||||
| import electrosphere.logger.LoggerInterface; | import electrosphere.logger.LoggerInterface; | ||||||
| import electrosphere.server.content.ServerContentManager; | import electrosphere.server.content.ServerContentManager; | ||||||
| @ -225,6 +227,9 @@ public class ArenaLoading { | |||||||
|                 //         } |                 //         } | ||||||
|                 // }}); |                 // }}); | ||||||
|          |          | ||||||
|  |                 // Entity crateEntity = ObjectUtils.clientSpawnBasicObject("crateWooden"); | ||||||
|  |                 // ClientEntityUtils.initiallyPositionEntity(crateEntity, new Vector3d(5,5,5)); | ||||||
|  |                 // ObjectUtils.serverSpawnBasicObject(Globals.realmManager.getRealms().iterator().next(),new Vector3d(5,5,5),"crateWooden"); | ||||||
|                  |                  | ||||||
|          |          | ||||||
|                 // DebugVisualizerUtils.spawnVectorVisualizer(new Vector3d(0,0,0), new Vector3d(-1,-1,-1)); |                 // DebugVisualizerUtils.spawnVectorVisualizer(new Vector3d(0,0,0), new Vector3d(-1,-1,-1)); | ||||||
|  | |||||||
| @ -25,7 +25,7 @@ import electrosphere.entity.Entity; | |||||||
| import electrosphere.entity.EntityCreationUtils; | import electrosphere.entity.EntityCreationUtils; | ||||||
| import electrosphere.entity.EntityDataStrings; | import electrosphere.entity.EntityDataStrings; | ||||||
| import electrosphere.entity.EntityUtils; | import electrosphere.entity.EntityUtils; | ||||||
| import electrosphere.entity.state.BehaviorTree; | import electrosphere.entity.btree.BehaviorTree; | ||||||
| import electrosphere.entity.state.movement.ApplyRotationTree; | import electrosphere.entity.state.movement.ApplyRotationTree; | ||||||
| import electrosphere.entity.types.camera.CameraEntityUtils; | import electrosphere.entity.types.camera.CameraEntityUtils; | ||||||
| import electrosphere.entity.types.tree.ProceduralTree; | import electrosphere.entity.types.tree.ProceduralTree; | ||||||
|  | |||||||
| @ -118,12 +118,10 @@ public class EntityDataStrings { | |||||||
|     Physics Entity |     Physics Entity | ||||||
|     */ |     */ | ||||||
|     public static final String PHYSICS_COLLISION_BODY = "physicsRigidBody"; |     public static final String PHYSICS_COLLISION_BODY = "physicsRigidBody"; | ||||||
|     public static final String PHYSICS_COLLISION_BODY_OFFSET = "physicsRigidBodyOffset"; |  | ||||||
|     public static final String PHYSICS_COLLISION_BODY_TRANSFORM = "physicsRigidBodyTransform"; // the transform matrix from origin of entity to origin of physics body |     public static final String PHYSICS_COLLISION_BODY_TRANSFORM = "physicsRigidBodyTransform"; // the transform matrix from origin of entity to origin of physics body | ||||||
|     public static final String PHYSICS_COLLIDABLE = "physicsCollidable"; |     public static final String PHYSICS_COLLIDABLE = "physicsCollidable"; | ||||||
|     public static final String PHYSICS_MODEL_TEMPLATE = "physicsModelTemplate"; |     public static final String PHYSICS_MODEL_TEMPLATE = "physicsModelTemplate"; | ||||||
|     public static final String PHYSICS_MASS = "physicsMass"; |     public static final String PHYSICS_MASS = "physicsMass"; | ||||||
|     public static final String PHYSICS_INVERSE_INERTIA_TENSOR = "physicsInverseInertiaTensor"; |  | ||||||
|     public static final String PHYSICS_ENGINE_AUTHORITATIVE_TRANSFORM = "physicsEngineAuthoritativeTransform"; // The physics engine is authoritative abound transforms of object (eg position, rotation) |     public static final String PHYSICS_ENGINE_AUTHORITATIVE_TRANSFORM = "physicsEngineAuthoritativeTransform"; // The physics engine is authoritative abound transforms of object (eg position, rotation) | ||||||
|      |      | ||||||
|     /* |     /* | ||||||
|  | |||||||
| @ -1,7 +1,7 @@ | |||||||
| package electrosphere.entity; | package electrosphere.entity; | ||||||
| 
 | 
 | ||||||
| import electrosphere.engine.Globals; | import electrosphere.engine.Globals; | ||||||
| import electrosphere.entity.state.BehaviorTree; | import electrosphere.entity.btree.BehaviorTree; | ||||||
| import electrosphere.entity.types.attach.AttachUtils; | import electrosphere.entity.types.attach.AttachUtils; | ||||||
| import electrosphere.logger.LoggerInterface; | import electrosphere.logger.LoggerInterface; | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -68,7 +68,7 @@ public class ServerEntityUtils { | |||||||
|         //     Globals.drawCellManager.setCellY(Globals.clientPlayerData.getWorldPos().z); |         //     Globals.drawCellManager.setCellY(Globals.clientPlayerData.getWorldPos().z); | ||||||
|         // } |         // } | ||||||
|         //reposition entity |         //reposition entity | ||||||
|         CollisionObjUtils.serverPositionCharacter(entity, Globals.spawnPoint); |         CollisionObjUtils.serverPositionCharacter(entity, position); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
| } | } | ||||||
|  | |||||||
| @ -1,4 +1,4 @@ | |||||||
| package electrosphere.entity.state; | package electrosphere.entity.btree; | ||||||
| 
 | 
 | ||||||
| /** | /** | ||||||
|  * A behavior tree |  * A behavior tree | ||||||
| @ -3,6 +3,7 @@ package electrosphere.entity.state; | |||||||
| import electrosphere.engine.Globals; | import electrosphere.engine.Globals; | ||||||
| import electrosphere.entity.Entity; | import electrosphere.entity.Entity; | ||||||
| import electrosphere.entity.EntityUtils; | import electrosphere.entity.EntityUtils; | ||||||
|  | import electrosphere.entity.btree.BehaviorTree; | ||||||
| 
 | 
 | ||||||
| import org.joml.Vector3d; | import org.joml.Vector3d; | ||||||
| import org.joml.Vector3f; | import org.joml.Vector3f; | ||||||
|  | |||||||
| @ -8,7 +8,7 @@ import electrosphere.engine.Globals; | |||||||
| import electrosphere.entity.Entity; | import electrosphere.entity.Entity; | ||||||
| import electrosphere.entity.EntityDataStrings; | import electrosphere.entity.EntityDataStrings; | ||||||
| import electrosphere.entity.EntityUtils; | import electrosphere.entity.EntityUtils; | ||||||
| import electrosphere.entity.state.BehaviorTree; | import electrosphere.entity.btree.BehaviorTree; | ||||||
| import electrosphere.game.data.foliage.type.AmbientAudio; | import electrosphere.game.data.foliage.type.AmbientAudio; | ||||||
| 
 | 
 | ||||||
| /** | /** | ||||||
|  | |||||||
| @ -7,7 +7,7 @@ import electrosphere.entity.Entity; | |||||||
| import electrosphere.entity.EntityDataStrings; | import electrosphere.entity.EntityDataStrings; | ||||||
| import electrosphere.entity.EntityUtils; | import electrosphere.entity.EntityUtils; | ||||||
| import electrosphere.entity.ServerEntityUtils; | import electrosphere.entity.ServerEntityUtils; | ||||||
| import electrosphere.entity.state.BehaviorTree; | import electrosphere.entity.btree.BehaviorTree; | ||||||
| import electrosphere.entity.state.collidable.Impulse; | import electrosphere.entity.state.collidable.Impulse; | ||||||
| import electrosphere.entity.state.equip.EquipState; | import electrosphere.entity.state.equip.EquipState; | ||||||
| import electrosphere.entity.state.movement.groundmove.GroundMovementTree; | import electrosphere.entity.state.movement.groundmove.GroundMovementTree; | ||||||
|  | |||||||
| @ -7,7 +7,7 @@ import electrosphere.entity.Entity; | |||||||
| import electrosphere.entity.EntityDataStrings; | import electrosphere.entity.EntityDataStrings; | ||||||
| import electrosphere.entity.EntityUtils; | import electrosphere.entity.EntityUtils; | ||||||
| import electrosphere.entity.ServerEntityUtils; | import electrosphere.entity.ServerEntityUtils; | ||||||
| import electrosphere.entity.state.BehaviorTree; | import electrosphere.entity.btree.BehaviorTree; | ||||||
| import electrosphere.entity.state.collidable.Impulse; | import electrosphere.entity.state.collidable.Impulse; | ||||||
| import electrosphere.entity.state.equip.EquipState; | import electrosphere.entity.state.equip.EquipState; | ||||||
| import electrosphere.entity.state.movement.groundmove.GroundMovementTree; | import electrosphere.entity.state.movement.groundmove.GroundMovementTree; | ||||||
|  | |||||||
| @ -6,7 +6,7 @@ import electrosphere.engine.Globals; | |||||||
| import electrosphere.entity.Entity; | import electrosphere.entity.Entity; | ||||||
| import electrosphere.entity.EntityDataStrings; | import electrosphere.entity.EntityDataStrings; | ||||||
| import electrosphere.entity.EntityUtils; | import electrosphere.entity.EntityUtils; | ||||||
| import electrosphere.entity.state.BehaviorTree; | import electrosphere.entity.btree.BehaviorTree; | ||||||
| import electrosphere.entity.types.creature.CreatureUtils; | import electrosphere.entity.types.creature.CreatureUtils; | ||||||
| import electrosphere.entity.types.projectile.ProjectileUtils; | import electrosphere.entity.types.projectile.ProjectileUtils; | ||||||
| import electrosphere.server.datacell.Realm; | import electrosphere.server.datacell.Realm; | ||||||
|  | |||||||
| @ -15,7 +15,7 @@ import electrosphere.engine.Globals; | |||||||
| import electrosphere.entity.Entity; | import electrosphere.entity.Entity; | ||||||
| import electrosphere.entity.EntityDataStrings; | import electrosphere.entity.EntityDataStrings; | ||||||
| import electrosphere.entity.EntityUtils; | import electrosphere.entity.EntityUtils; | ||||||
| import electrosphere.entity.state.BehaviorTree; | import electrosphere.entity.btree.BehaviorTree; | ||||||
| import electrosphere.entity.state.gravity.ClientGravityTree; | import electrosphere.entity.state.gravity.ClientGravityTree; | ||||||
| import electrosphere.entity.types.collision.CollisionObjUtils; | import electrosphere.entity.types.collision.CollisionObjUtils; | ||||||
| import electrosphere.entity.types.item.ItemUtils; | import electrosphere.entity.types.item.ItemUtils; | ||||||
| @ -31,13 +31,9 @@ public class ClientCollidableTree implements BehaviorTree { | |||||||
|     //the ode body for this collidable tree |     //the ode body for this collidable tree | ||||||
|     DBody body; |     DBody body; | ||||||
|     Collidable collidable; |     Collidable collidable; | ||||||
|     Quaterniond angularVelocity = new Quaterniond(0,0,0,0); |  | ||||||
|     Vector4d cumulativeTorque = new Vector4d(0,0,0,0); |  | ||||||
| 
 | 
 | ||||||
|     boolean applyImpulses = true; |     boolean applyImpulses = true; | ||||||
|      |      | ||||||
|     static final float DELTA_T = 0.01f; |  | ||||||
| 
 |  | ||||||
|     public ClientCollidableTree(Entity e, Collidable collidable, DBody body){ |     public ClientCollidableTree(Entity e, Collidable collidable, DBody body){ | ||||||
|         parent = e; |         parent = e; | ||||||
|         this.collidable = collidable; |         this.collidable = collidable; | ||||||
| @ -56,7 +52,6 @@ public class ClientCollidableTree implements BehaviorTree { | |||||||
|     public void simulate(float deltaTime){ |     public void simulate(float deltaTime){ | ||||||
|         Vector3d position = EntityUtils.getPosition(parent); |         Vector3d position = EntityUtils.getPosition(parent); | ||||||
|         Quaterniond rotation = EntityUtils.getRotation(parent); |         Quaterniond rotation = EntityUtils.getRotation(parent); | ||||||
|         Matrix4f inverseInertiaTensor = CollisionObjUtils.getInverseInertiaTensor(parent); |  | ||||||
|         Vector3d offsetVector = new Vector3d(); |         Vector3d offsetVector = new Vector3d(); | ||||||
|         Vector3d newPosition = new Vector3d(position); |         Vector3d newPosition = new Vector3d(position); | ||||||
|         //have we hit a terrain impulse? |         //have we hit a terrain impulse? | ||||||
| @ -81,151 +76,18 @@ public class ClientCollidableTree implements BehaviorTree { | |||||||
|                     ClientGravityTree.getClientGravityTree(parent).start(); |                     ClientGravityTree.getClientGravityTree(parent).start(); | ||||||
|                 } |                 } | ||||||
|             } |             } | ||||||
|             if( |  | ||||||
|                 impulse.getCollisionPoint().length() > 0 && |  | ||||||
|                 !Double.isNaN(impulse.getCollisionPoint().x) &&  |  | ||||||
|                 !Double.isNaN(impulse.getCollisionPoint().y) &&  |  | ||||||
|                 !Double.isNaN(impulse.getCollisionPoint().z) &&  |  | ||||||
|                 !Double.isNaN(impulse.getDirection().x) && |  | ||||||
|                 !Double.isNaN(impulse.getDirection().y) && |  | ||||||
|                 !Double.isNaN(impulse.getDirection().z) && |  | ||||||
|                 ItemUtils.isItem(parent) |  | ||||||
|             ){ |  | ||||||
|                 // Vector3d collisionPoint = new Vector3d(impulse.getCollisionPoint()).normalize(); |  | ||||||
|                 Vector3d collisionPoint = new Vector3d(impulse.getWorldPoint()).sub(position); |  | ||||||
|                 Vector3d forceDir = new Vector3d(impulse.getDirection()).normalize(); |  | ||||||
|                 Vector3d torqueVec = new Vector3d(collisionPoint).cross(forceDir).normalize(); |  | ||||||
|                 // double torqueMag = Math.abs(impulse.force); |  | ||||||
|                 double torqueMag = Math.sqrt(impulse.getCollisionPoint().length()) * impulse.getForce(); |  | ||||||
|                 if(impulse.getType().equals(Collidable.TYPE_TERRAIN)){ |  | ||||||
|                     torqueMag = torqueMag * 3; |  | ||||||
|         } |         } | ||||||
|                     torqueMag = torqueMag * 10; |         //bound to world bounds | ||||||
|                 // } else { |         if(newPosition.x < Globals.clientWorldData.getWorldBoundMin().x){ | ||||||
|                 //     torqueMag = 0; |             newPosition.x = Globals.clientWorldData.getWorldBoundMin().x; | ||||||
|                 // } |  | ||||||
|                 // if(impulse.type.matches(Collidable.TYPE_ITEM) && ItemUtils.isItem(parent)){ |  | ||||||
|                 //     // System.out.println(rotation); |  | ||||||
|                 //     if(impulse.collisionPoint.x < 0){ |  | ||||||
|                 //         // System.out.println("Impulse collision point: " + impulse.getCollisionPoint() + " direction: " + impulse.getDirection() + " => " + new Vector3d(impulse.getCollisionPoint()).cross(impulse.getDirection())); |  | ||||||
|                 //         cumulativeTorque.add(new Vector3d(impulse.getCollisionPoint()).cross(impulse.getDirection())); |  | ||||||
|                 //     } |  | ||||||
|                 // } else { |  | ||||||
|                 //     // angularVelocity.add(new Vector3d(impulse.getCollisionPoint()).cross(impulse.getDirection()),1.0); |  | ||||||
|                 //     cumulativeTorque.add(new Vector3d(impulse.getCollisionPoint()).cross(impulse.getDirection())); |  | ||||||
|                 // } |  | ||||||
|                 if(impulse.type.matches(Collidable.TYPE_CREATURE)){ |  | ||||||
|                     // System.out.println("Impulse: " + impulse.getCollisionPoint() + " x " + impulse.getDirection() + " ->f " + impulse.force); |  | ||||||
|                     // incrementer++; |  | ||||||
|                     // if(incrementer > 5){ |  | ||||||
|                     //     Globals.microSimulation.freeze(); |  | ||||||
|                     // } else if(incrementer <= 5){ |  | ||||||
|                     //     // Globals.controlHandler.showMouse(); |  | ||||||
|                         // Vector3d pos = impulse.getWorldPoint(); |  | ||||||
|                     //     // pos = new Vector3d(position).add(impulse.getCollisionPoint()).mul(1,0,1); |  | ||||||
|                         // DebugVisualizerUtils.spawnVectorVisualizer(impulse.getWorldPoint(), new Vector3d(torqueVec)); |  | ||||||
|                     // } |  | ||||||
|                     // System.out.println("Impulse: " + torqueVec + " " + torqueMag); |  | ||||||
|         } |         } | ||||||
|                 // if(CreatureUtils.isCreature(parent) && forceDir.y < 0.5){ |         if(newPosition.y < Globals.clientWorldData.getWorldBoundMin().y){ | ||||||
|                 //     System.out.println(collisionPoint + " x " + forceDir + " => " + torqueVec + " " + torqueMag); |             newPosition.y = Globals.clientWorldData.getWorldBoundMin().y; | ||||||
|                 // } |  | ||||||
|                 Quaterniond impulseRotation = new Quaterniond().rotationAxis(torqueMag * DELTA_T,torqueVec.x,torqueVec.y,torqueVec.z); |  | ||||||
|                 if(angularVelocity.lengthSquared() > 0.001){ |  | ||||||
|                     angularVelocity.mul(impulseRotation); |  | ||||||
|                 } else { |  | ||||||
|                     angularVelocity.set(impulseRotation); |  | ||||||
|         } |         } | ||||||
|                 // angularVelocity.add(new Vector4d((float)torqueVec.x,(float)torqueVec.y,(float)torqueVec.z,(float)torqueMag)); |         if(newPosition.z < Globals.clientWorldData.getWorldBoundMin().z){ | ||||||
|                 // cumulativeTorque.add(new Vector4d((float)torqueVec.x,(float)torqueVec.y,(float)torqueVec.z,(float)torqueMag)); |             newPosition.z = Globals.clientWorldData.getWorldBoundMin().z; | ||||||
|         } |         } | ||||||
|             offsetVector.add(impulseForce); |         PhysicsUtils.setRigidBodyTransform(Globals.clientSceneWrapper.getCollisionEngine(), newPosition, rotation, body); | ||||||
|         } |  | ||||||
|         // if(ItemUtils.isItem(parent) && cumulativeTorque.w > 0.001){ |  | ||||||
|         //     System.out.println(cumulativeTorque); |  | ||||||
|         // } |  | ||||||
|         //friction |  | ||||||
|         // if(angularVelocity.lengthSquared() > 0.001){ |  | ||||||
|         //     angularVelocity.slerp(new Quaterniond(0,0,0,1), 0.03); |  | ||||||
|         //     // angularVelocity.scale((float)(Math.sqrt(angularVelocity.lengthSquared()) * 0.9)); |  | ||||||
|         //     // System.out.println(angularVelocity); |  | ||||||
|         // } |  | ||||||
|         // // if(cumulativeTorque.w > 0.001){ |  | ||||||
|         // //     Vector4f holder = inverseInertiaTensor.transform(new Vector4f((float)cumulativeTorque.x,(float)cumulativeTorque.y,(float)cumulativeTorque.z,(float)cumulativeTorque.w)); |  | ||||||
|         // //     cumulativeTorque = new Vector4d(holder.x,holder.y,holder.z,holder.w); |  | ||||||
|         // //     angularVelocity = angularVelocity.add(cumulativeTorque).normalize(); |  | ||||||
|         // //     cumulativeTorque.set(0,0,0,0); |  | ||||||
|         // // //     Vector3d normalizedTorqueDir = new Vector3d(cumulativeTorque.x,cumulativeTorque.y,cumulativeTorque.z).normalize(); |  | ||||||
|         // // //     double newMag = cumulativeTorque.w * 0.9; |  | ||||||
|         // // //     cumulativeTorque.set(normalizedTorqueDir.x,normalizedTorqueDir.y,normalizedTorqueDir.z,newMag); |  | ||||||
|         // // } |  | ||||||
|         // if(angularVelocity.lengthSquared() > 0.001){ |  | ||||||
|         //     // System.out.println("-" + rotation); |  | ||||||
|         //     Quaterniond newRotation = new Quaterniond(rotation).mul(angularVelocity).normalize(); |  | ||||||
|         //     // if(new Quaternionf(newRotation).add(new Quaternionf(rotation).conjugate()).lengthSquared() > 0.2){ |  | ||||||
|         //     //     newRotation.w = Math.copySign(newRotation.w, rotation.w); |  | ||||||
|         //     //     newRotation.x = Math.copySign(newRotation.x, rotation.x); |  | ||||||
|         //     //     newRotation.y = Math.copySign(newRotation.y, rotation.y); |  | ||||||
|         //     //     newRotation.z = Math.copySign(newRotation.z, rotation.z); |  | ||||||
|         //     // } |  | ||||||
|         //     rotation.set(newRotation); |  | ||||||
|         //     // System.out.println("=" + rotation); |  | ||||||
|         // } |  | ||||||
|         // if(inverseInertiaTensor != null && angularVelocity.w > 0.01){ |  | ||||||
|         //     // Vector4f angularMomentum = inverseInertiaTensor.transform(new Vector4f((float)cumulativeTorque.x,(float)cumulativeTorque.x,(float)cumulativeTorque.x,(float)cumulativeTorque.w)); |  | ||||||
|         //     // Quaternionf nextRotation = new Quaternionf(rotation).mul(new Quaternionf(angularMomentum.x,angularMomentum.y,angularMomentum.z,angularMomentum.w).scale(0.001f)).normalize(); |  | ||||||
|         //     // rotation = nextRotation; |  | ||||||
|         //     // rotation.mul(new Quaternionf((float)angularMomentum.x,(float)angularMomentum.y,(float)angularMomentum.z,(float)angularMomentum.w / 0.01f)); |  | ||||||
|         //     // if(ItemUtils.isItem(parent)){ |  | ||||||
|         //     //     System.out.println("cumulative quat: " + cumulativeTorque); |  | ||||||
|         //     // } |  | ||||||
|         //     rotation.x = rotation.x + rotation.x * (float)(angularVelocity.x * angularVelocity.w) * 0.01f; |  | ||||||
|         //     rotation.y = rotation.y + rotation.y * (float)(angularVelocity.y * angularVelocity.w) * 0.01f; |  | ||||||
|         //     rotation.z = rotation.z + rotation.z * (float)(angularVelocity.z * angularVelocity.w) * 0.01f; |  | ||||||
|         //     rotation.w = 1; |  | ||||||
|         //     // rotation.w = rotation.w + rotation.w * (float)cumulativeTorque.w * 0.001f; |  | ||||||
|         //     rotation.normalize(); |  | ||||||
|         // } |  | ||||||
|          |  | ||||||
|         //the reasoning here is that if we have something above something else and it's pushing it into the terrain, |  | ||||||
|         //we should instead just not push into terrain and push along terrain |  | ||||||
|         if(hitTerrain && offsetVector.y < 0){ |  | ||||||
|             offsetVector.y = 0; |  | ||||||
|         } |  | ||||||
|          |  | ||||||
|         //make sure we're in a valid (World bounds) position |  | ||||||
|         if(applyImpulses){ |  | ||||||
|             newPosition.add(offsetVector); |  | ||||||
|         } |  | ||||||
|         if(!Globals.clientSceneWrapper.getCollisionEngine().checkCanOccupyPosition(Globals.commonWorldData, parent, newPosition)){ |  | ||||||
|             newPosition = Globals.clientSceneWrapper.getCollisionEngine().suggestMovementPosition(Globals.commonWorldData, parent, newPosition); |  | ||||||
|         } |  | ||||||
|         position.set(newPosition); |  | ||||||
|          |  | ||||||
|         //update collision engine of this thing's position |  | ||||||
|         CollidableTemplate template = (CollidableTemplate)parent.getData(EntityDataStrings.PHYSICS_MODEL_TEMPLATE); |  | ||||||
|         Matrix4d physicsBodyTransform = PhysicsEntityUtils.getEntityCollidableTransform(parent); |  | ||||||
|         Vector3f parentScale = EntityUtils.getScale(parent); |  | ||||||
|         Matrix4d parentTransform = new Matrix4d(); |  | ||||||
|         // calculate new transform for current entity |  | ||||||
|         parentTransform.identity() |  | ||||||
|             .translate(position) |  | ||||||
|             .rotate(rotation) |  | ||||||
|             .scale(parentScale.x,parentScale.y,parentScale.z) |  | ||||||
|             .mul(physicsBodyTransform); |  | ||||||
|         //transform bone space |  | ||||||
|         Vector4d rigidBodyPositionRaw = parentTransform.transform(new Vector4d(0,0,0,1)); |  | ||||||
|         Vector3d rigidBodyPosition = new Vector3d(rigidBodyPositionRaw.x,rigidBodyPositionRaw.y,rigidBodyPositionRaw.z); |  | ||||||
|         Quaterniond rigidBodyRotation = parentTransform.getUnnormalizedRotation(new Quaterniond()).normalize(); |  | ||||||
|         Vector3d rigidBodyScale = new Vector3d(parentScale); |  | ||||||
|         PhysicsUtils.setRigidBodyTransform( |  | ||||||
|             Globals.clientSceneWrapper.getCollisionEngine(), |  | ||||||
|             template, |  | ||||||
|             rigidBodyPosition, |  | ||||||
|             rigidBodyRotation, |  | ||||||
|             rigidBodyScale, |  | ||||||
|             body |  | ||||||
|         ); |  | ||||||
|     } |     } | ||||||
|      |      | ||||||
|     /** |     /** | ||||||
| @ -238,10 +100,6 @@ public class ClientCollidableTree implements BehaviorTree { | |||||||
|         this.collidable = collidable; |         this.collidable = collidable; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     public double getAngularVelocityMagnitude(){ |  | ||||||
|         return angularVelocity.lengthSquared(); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     public static boolean hasClientCollidableTree(Entity e){ |     public static boolean hasClientCollidableTree(Entity e){ | ||||||
|         return e.containsKey(EntityDataStrings.CLIENT_COLLIDABLE_TREE); |         return e.containsKey(EntityDataStrings.CLIENT_COLLIDABLE_TREE); | ||||||
|     } |     } | ||||||
|  | |||||||
| @ -6,7 +6,7 @@ import electrosphere.engine.Globals; | |||||||
| import electrosphere.entity.Entity; | import electrosphere.entity.Entity; | ||||||
| import electrosphere.entity.EntityDataStrings; | import electrosphere.entity.EntityDataStrings; | ||||||
| import electrosphere.entity.EntityUtils; | import electrosphere.entity.EntityUtils; | ||||||
| import electrosphere.entity.state.BehaviorTree; | import electrosphere.entity.btree.BehaviorTree; | ||||||
| import electrosphere.entity.state.gravity.ServerGravityTree; | import electrosphere.entity.state.gravity.ServerGravityTree; | ||||||
| import electrosphere.entity.types.collision.CollisionObjUtils; | import electrosphere.entity.types.collision.CollisionObjUtils; | ||||||
| import electrosphere.entity.types.creature.CreatureUtils; | import electrosphere.entity.types.creature.CreatureUtils; | ||||||
| @ -14,6 +14,7 @@ import electrosphere.entity.types.debug.DebugVisualizerUtils; | |||||||
| import electrosphere.entity.types.item.ItemUtils; | import electrosphere.entity.types.item.ItemUtils; | ||||||
| import electrosphere.game.data.collidable.CollidableTemplate; | import electrosphere.game.data.collidable.CollidableTemplate; | ||||||
| import electrosphere.server.datacell.Realm; | import electrosphere.server.datacell.Realm; | ||||||
|  | import electrosphere.server.datacell.utils.DataCellSearchUtils; | ||||||
| 
 | 
 | ||||||
| import org.joml.Matrix4f; | import org.joml.Matrix4f; | ||||||
| import org.joml.Quaterniond; | import org.joml.Quaterniond; | ||||||
| @ -33,12 +34,8 @@ public class ServerCollidableTree implements BehaviorTree { | |||||||
|     Entity parent; |     Entity parent; | ||||||
|     DBody body; |     DBody body; | ||||||
|     Collidable collidable; |     Collidable collidable; | ||||||
|     Quaterniond angularVelocity = new Quaterniond(0,0,0,0); |  | ||||||
|     Vector4d cumulativeTorque = new Vector4d(0,0,0,0); |  | ||||||
| 
 |  | ||||||
|     boolean applyImpulses = true; |     boolean applyImpulses = true; | ||||||
|      |      | ||||||
|     static final float DELTA_T = 0.01f; |  | ||||||
| 
 | 
 | ||||||
|     public ServerCollidableTree(Entity e, Collidable collidable, DBody body){ |     public ServerCollidableTree(Entity e, Collidable collidable, DBody body){ | ||||||
|         parent = e; |         parent = e; | ||||||
| @ -58,7 +55,6 @@ public class ServerCollidableTree implements BehaviorTree { | |||||||
|     public void simulate(float deltaTime){ |     public void simulate(float deltaTime){ | ||||||
|         Vector3d position = EntityUtils.getPosition(parent); |         Vector3d position = EntityUtils.getPosition(parent); | ||||||
|         Quaterniond rotation = EntityUtils.getRotation(parent); |         Quaterniond rotation = EntityUtils.getRotation(parent); | ||||||
|         Matrix4f inverseInertiaTensor = CollisionObjUtils.getInverseInertiaTensor(parent); |  | ||||||
|         Vector3d offsetVector = new Vector3d(); |         Vector3d offsetVector = new Vector3d(); | ||||||
|         Vector3d newPosition = new Vector3d(position); |         Vector3d newPosition = new Vector3d(position); | ||||||
|         //have we hit a terrain impulse? |         //have we hit a terrain impulse? | ||||||
| @ -66,7 +62,6 @@ public class ServerCollidableTree implements BehaviorTree { | |||||||
|         //handle impulses |         //handle impulses | ||||||
|         for(Impulse impulse : collidable.getImpulses()){ |         for(Impulse impulse : collidable.getImpulses()){ | ||||||
| //            collidable.getImpulses().remove(impulse); | //            collidable.getImpulses().remove(impulse); | ||||||
|             Vector3d impulseForce = new Vector3d(impulse.getDirection()).mul(impulse.getForce()); |  | ||||||
|             if(impulse.type.matches(Collidable.TYPE_TERRAIN)){ |             if(impulse.type.matches(Collidable.TYPE_TERRAIN)){ | ||||||
|                 hitTerrain = true; |                 hitTerrain = true; | ||||||
|             //    System.out.println("Impulse force: " + impulseForce); |             //    System.out.println("Impulse force: " + impulseForce); | ||||||
| @ -83,136 +78,19 @@ public class ServerCollidableTree implements BehaviorTree { | |||||||
|                     ServerGravityTree.getServerGravityTree(parent).start(); |                     ServerGravityTree.getServerGravityTree(parent).start(); | ||||||
|                 } |                 } | ||||||
|             } |             } | ||||||
|             if( |  | ||||||
|                 impulse.getCollisionPoint().length() > 0 && |  | ||||||
|                 !Double.isNaN(impulse.getCollisionPoint().x) &&  |  | ||||||
|                 !Double.isNaN(impulse.getCollisionPoint().y) &&  |  | ||||||
|                 !Double.isNaN(impulse.getCollisionPoint().z) &&  |  | ||||||
|                 !Double.isNaN(impulse.getDirection().x) && |  | ||||||
|                 !Double.isNaN(impulse.getDirection().y) && |  | ||||||
|                 !Double.isNaN(impulse.getDirection().z) && |  | ||||||
|                 ItemUtils.isItem(parent) |  | ||||||
|             ){ |  | ||||||
|                 // Vector3d collisionPoint = new Vector3d(impulse.getCollisionPoint()).normalize(); |  | ||||||
|                 Vector3d collisionPoint = new Vector3d(impulse.getWorldPoint()).sub(position); |  | ||||||
|                 Vector3d forceDir = new Vector3d(impulse.getDirection()).normalize(); |  | ||||||
|                 Vector3d torqueVec = new Vector3d(collisionPoint).cross(forceDir).normalize(); |  | ||||||
|                 // double torqueMag = Math.abs(impulse.force); |  | ||||||
|                 double torqueMag = Math.sqrt(impulse.getCollisionPoint().length()) * impulse.getForce(); |  | ||||||
|                 if(impulse.getType().equals(Collidable.TYPE_TERRAIN)){ |  | ||||||
|                     torqueMag = torqueMag * 3; |  | ||||||
|         } |         } | ||||||
|                     torqueMag = torqueMag * 10; |         Realm realm = Globals.realmManager.getEntityRealm(parent); | ||||||
|                 // } else { |         //bound to world bounds | ||||||
|                 //     torqueMag = 0; |         if(newPosition.x < Globals.serverWorldData.getWorldBoundMin().x){ | ||||||
|                 // } |             newPosition.x = Globals.serverWorldData.getWorldBoundMin().x; | ||||||
|                 // if(impulse.type.matches(Collidable.TYPE_ITEM) && ItemUtils.isItem(parent)){ |  | ||||||
|                 //     // System.out.println(rotation); |  | ||||||
|                 //     if(impulse.collisionPoint.x < 0){ |  | ||||||
|                 //         // System.out.println("Impulse collision point: " + impulse.getCollisionPoint() + " direction: " + impulse.getDirection() + " => " + new Vector3d(impulse.getCollisionPoint()).cross(impulse.getDirection())); |  | ||||||
|                 //         cumulativeTorque.add(new Vector3d(impulse.getCollisionPoint()).cross(impulse.getDirection())); |  | ||||||
|                 //     } |  | ||||||
|                 // } else { |  | ||||||
|                 //     // angularVelocity.add(new Vector3d(impulse.getCollisionPoint()).cross(impulse.getDirection()),1.0); |  | ||||||
|                 //     cumulativeTorque.add(new Vector3d(impulse.getCollisionPoint()).cross(impulse.getDirection())); |  | ||||||
|                 // } |  | ||||||
|                 if(impulse.type.matches(Collidable.TYPE_CREATURE)){ |  | ||||||
|                     // System.out.println("Impulse: " + impulse.getCollisionPoint() + " x " + impulse.getDirection() + " ->f " + impulse.force); |  | ||||||
|                     // incrementer++; |  | ||||||
|                     // if(incrementer > 5){ |  | ||||||
|                     //     Globals.microSimulation.freeze(); |  | ||||||
|                     // } else if(incrementer <= 5){ |  | ||||||
|                     //     // Globals.controlHandler.showMouse(); |  | ||||||
|                         // Vector3d pos = impulse.getWorldPoint(); |  | ||||||
|                     //     // pos = new Vector3d(position).add(impulse.getCollisionPoint()).mul(1,0,1); |  | ||||||
|                         // DebugVisualizerUtils.spawnVectorVisualizer(impulse.getWorldPoint(), new Vector3d(torqueVec)); |  | ||||||
|                     // } |  | ||||||
|                     // System.out.println("Impulse: " + torqueVec + " " + torqueMag); |  | ||||||
|         } |         } | ||||||
|                 // if(CreatureUtils.isCreature(parent) && forceDir.y < 0.5){ |         if(newPosition.y < Globals.serverWorldData.getWorldBoundMin().y){ | ||||||
|                 //     System.out.println(collisionPoint + " x " + forceDir + " => " + torqueVec + " " + torqueMag); |             newPosition.y = Globals.serverWorldData.getWorldBoundMin().y; | ||||||
|                 // } |  | ||||||
|                 Quaterniond impulseRotation = new Quaterniond().rotationAxis(torqueMag * DELTA_T,torqueVec.x,torqueVec.y,torqueVec.z); |  | ||||||
|                 if(angularVelocity.lengthSquared() > 0.001){ |  | ||||||
|                     angularVelocity.mul(impulseRotation); |  | ||||||
|                 } else { |  | ||||||
|                     angularVelocity.set(impulseRotation); |  | ||||||
|         } |         } | ||||||
|                 // angularVelocity.add(new Vector4d((float)torqueVec.x,(float)torqueVec.y,(float)torqueVec.z,(float)torqueMag)); |         if(newPosition.z < Globals.serverWorldData.getWorldBoundMin().z){ | ||||||
|                 // cumulativeTorque.add(new Vector4d((float)torqueVec.x,(float)torqueVec.y,(float)torqueVec.z,(float)torqueMag)); |             newPosition.z = Globals.serverWorldData.getWorldBoundMin().z; | ||||||
|         } |         } | ||||||
|             offsetVector.add(impulseForce); |         PhysicsUtils.setRigidBodyTransform(realm.getCollisionEngine(), newPosition, rotation, body); | ||||||
|         } |  | ||||||
|         // if(ItemUtils.isItem(parent) && cumulativeTorque.w > 0.001){ |  | ||||||
|         //     System.out.println(cumulativeTorque); |  | ||||||
|         // } |  | ||||||
|         //friction |  | ||||||
|         if(angularVelocity.lengthSquared() > 0.001){ |  | ||||||
|             angularVelocity.slerp(new Quaterniond(0,0,0,1), 0.03); |  | ||||||
|             // angularVelocity.scale((float)(Math.sqrt(angularVelocity.lengthSquared()) * 0.9)); |  | ||||||
|             // System.out.println(angularVelocity); |  | ||||||
|         } |  | ||||||
|         // if(cumulativeTorque.w > 0.001){ |  | ||||||
|         //     Vector4f holder = inverseInertiaTensor.transform(new Vector4f((float)cumulativeTorque.x,(float)cumulativeTorque.y,(float)cumulativeTorque.z,(float)cumulativeTorque.w)); |  | ||||||
|         //     cumulativeTorque = new Vector4d(holder.x,holder.y,holder.z,holder.w); |  | ||||||
|         //     angularVelocity = angularVelocity.add(cumulativeTorque).normalize(); |  | ||||||
|         //     cumulativeTorque.set(0,0,0,0); |  | ||||||
|         // //     Vector3d normalizedTorqueDir = new Vector3d(cumulativeTorque.x,cumulativeTorque.y,cumulativeTorque.z).normalize(); |  | ||||||
|         // //     double newMag = cumulativeTorque.w * 0.9; |  | ||||||
|         // //     cumulativeTorque.set(normalizedTorqueDir.x,normalizedTorqueDir.y,normalizedTorqueDir.z,newMag); |  | ||||||
|         // } |  | ||||||
|         if(angularVelocity.lengthSquared() > 0.001){ |  | ||||||
|             // System.out.println("-" + rotation); |  | ||||||
|             Quaterniond newRotation = new Quaterniond(rotation).mul(angularVelocity).normalize(); |  | ||||||
|             // if(new Quaternionf(newRotation).add(new Quaternionf(rotation).conjugate()).lengthSquared() > 0.2){ |  | ||||||
|             //     newRotation.w = Math.copySign(newRotation.w, rotation.w); |  | ||||||
|             //     newRotation.x = Math.copySign(newRotation.x, rotation.x); |  | ||||||
|             //     newRotation.y = Math.copySign(newRotation.y, rotation.y); |  | ||||||
|             //     newRotation.z = Math.copySign(newRotation.z, rotation.z); |  | ||||||
|             // } |  | ||||||
|             rotation.set(newRotation); |  | ||||||
|             // System.out.println("=" + rotation); |  | ||||||
|         } |  | ||||||
|         // if(inverseInertiaTensor != null && angularVelocity.w > 0.01){ |  | ||||||
|         //     // Vector4f angularMomentum = inverseInertiaTensor.transform(new Vector4f((float)cumulativeTorque.x,(float)cumulativeTorque.x,(float)cumulativeTorque.x,(float)cumulativeTorque.w)); |  | ||||||
|         //     // Quaternionf nextRotation = new Quaternionf(rotation).mul(new Quaternionf(angularMomentum.x,angularMomentum.y,angularMomentum.z,angularMomentum.w).scale(0.001f)).normalize(); |  | ||||||
|         //     // rotation = nextRotation; |  | ||||||
|         //     // rotation.mul(new Quaternionf((float)angularMomentum.x,(float)angularMomentum.y,(float)angularMomentum.z,(float)angularMomentum.w / 0.01f)); |  | ||||||
|         //     // if(ItemUtils.isItem(parent)){ |  | ||||||
|         //     //     System.out.println("cumulative quat: " + cumulativeTorque); |  | ||||||
|         //     // } |  | ||||||
|         //     rotation.x = rotation.x + rotation.x * (float)(angularVelocity.x * angularVelocity.w) * 0.01f; |  | ||||||
|         //     rotation.y = rotation.y + rotation.y * (float)(angularVelocity.y * angularVelocity.w) * 0.01f; |  | ||||||
|         //     rotation.z = rotation.z + rotation.z * (float)(angularVelocity.z * angularVelocity.w) * 0.01f; |  | ||||||
|         //     rotation.w = 1; |  | ||||||
|         //     // rotation.w = rotation.w + rotation.w * (float)cumulativeTorque.w * 0.001f; |  | ||||||
|         //     rotation.normalize(); |  | ||||||
|         // } |  | ||||||
|          |  | ||||||
|         //the reasoning here is that if we have something above something else and it's pushing it into the terrain, |  | ||||||
|         //we should instead just not push into terrain and push along terrain |  | ||||||
|         if(hitTerrain && offsetVector.y < 0){ |  | ||||||
|             offsetVector.y = 0; |  | ||||||
|         } |  | ||||||
|          |  | ||||||
|         //make sure we're in a valid (World bounds) position |  | ||||||
|         if(applyImpulses){ |  | ||||||
|             newPosition.add(offsetVector); |  | ||||||
|         } |  | ||||||
|         Realm parentRealm = Globals.realmManager.getEntityRealm(parent); |  | ||||||
|         if(!parentRealm.getCollisionEngine().checkCanOccupyPosition(Globals.commonWorldData, parent, newPosition)){ |  | ||||||
|             newPosition = parentRealm.getCollisionEngine().suggestMovementPosition(Globals.commonWorldData, parent, newPosition); |  | ||||||
|         } |  | ||||||
|         position.set(newPosition); |  | ||||||
|          |  | ||||||
|         //update collision engine of this thing's position |  | ||||||
|         CollidableTemplate template = (CollidableTemplate)parent.getData(EntityDataStrings.PHYSICS_MODEL_TEMPLATE); |  | ||||||
|         PhysicsUtils.setRigidBodyTransform( |  | ||||||
|             parentRealm.getCollisionEngine(), |  | ||||||
|             new Vector3d(position.x + template.getOffsetX(),position.y + template.getOffsetY(),position.z + template.getOffsetZ()), |  | ||||||
|             rotation, |  | ||||||
|             body |  | ||||||
|         ); |  | ||||||
|     } |     } | ||||||
|      |      | ||||||
|      |      | ||||||
| @ -226,10 +104,6 @@ public class ServerCollidableTree implements BehaviorTree { | |||||||
|         this.collidable = collidable; |         this.collidable = collidable; | ||||||
|     } |     } | ||||||
|      |      | ||||||
|     public double getAngularVelocityMagnitude(){ |  | ||||||
|         return angularVelocity.lengthSquared(); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     public static boolean hasServerCollidableTree(Entity e){ |     public static boolean hasServerCollidableTree(Entity e){ | ||||||
|         return e.containsKey(EntityDataStrings.SERVER_COLLIDABLE_TREE); |         return e.containsKey(EntityDataStrings.SERVER_COLLIDABLE_TREE); | ||||||
|     } |     } | ||||||
|  | |||||||
| @ -7,7 +7,7 @@ import electrosphere.engine.Globals; | |||||||
| import electrosphere.entity.Entity; | import electrosphere.entity.Entity; | ||||||
| import electrosphere.entity.EntityDataStrings; | import electrosphere.entity.EntityDataStrings; | ||||||
| import electrosphere.entity.EntityUtils; | import electrosphere.entity.EntityUtils; | ||||||
| import electrosphere.entity.state.BehaviorTree; | import electrosphere.entity.btree.BehaviorTree; | ||||||
| import electrosphere.entity.types.camera.CameraEntityUtils; | import electrosphere.entity.types.camera.CameraEntityUtils; | ||||||
| 
 | 
 | ||||||
| /** | /** | ||||||
|  | |||||||
| @ -18,7 +18,7 @@ import electrosphere.engine.Globals; | |||||||
| import electrosphere.entity.Entity; | import electrosphere.entity.Entity; | ||||||
| import electrosphere.entity.EntityDataStrings; | import electrosphere.entity.EntityDataStrings; | ||||||
| import electrosphere.entity.EntityUtils; | import electrosphere.entity.EntityUtils; | ||||||
| import electrosphere.entity.state.BehaviorTree; | import electrosphere.entity.btree.BehaviorTree; | ||||||
| import electrosphere.entity.state.collidable.ClientCollidableTree; | import electrosphere.entity.state.collidable.ClientCollidableTree; | ||||||
| import electrosphere.entity.state.collidable.Impulse; | import electrosphere.entity.state.collidable.Impulse; | ||||||
| import electrosphere.entity.state.movement.FallTree; | import electrosphere.entity.state.movement.FallTree; | ||||||
| @ -48,9 +48,6 @@ public class ClientGravityTree implements BehaviorTree { | |||||||
|     int frameCurrent = 0; |     int frameCurrent = 0; | ||||||
|     int fallFrame = 1; |     int fallFrame = 1; | ||||||
|      |      | ||||||
|     float gravityVelocity = 0; |  | ||||||
|     float gravityAccel = 0.0007f; |  | ||||||
|      |  | ||||||
|     DBody body; |     DBody body; | ||||||
|     Collidable collidable; |     Collidable collidable; | ||||||
|      |      | ||||||
| @ -112,34 +109,6 @@ public class ClientGravityTree implements BehaviorTree { | |||||||
|             collidableTree = ClientCollidableTree.getClientCollidableTree(parent); |             collidableTree = ClientCollidableTree.getClientCollidableTree(parent); | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         //parse attached network messages |  | ||||||
| //        for(EntityMessage message : networkMessageQueue){ |  | ||||||
| //            networkMessageQueue.remove(message); |  | ||||||
| ////            System.out.println("MOVE to " + message.getX() + " " + message.getY() + " " + message.getZ()); |  | ||||||
| //            switch(message.getMessageSubtype()){ |  | ||||||
| //                case ATTACKUPDATE: |  | ||||||
| //                    switch(message.gettreeState()){ |  | ||||||
| //                     case 0: |  | ||||||
| //                            state = IdleTreeState.IDLE; |  | ||||||
| //                            break; |  | ||||||
| //                        case 1: |  | ||||||
| //                            state = IdleTreeState.NOT_IDLE; |  | ||||||
| //                            break; |  | ||||||
| //                    } |  | ||||||
| //                    EntityUtils.getPosition(parent).set(message.getpositionX(),message.getpositionY(),message.getpositionZ()); |  | ||||||
| //                    CreatureUtils.setMovementVector(parent, new Vector3f(message.getrotationX(),message.getrotationY(),message.getrotationZ())); |  | ||||||
| //                    break; |  | ||||||
| //            } |  | ||||||
| //        } |  | ||||||
| 
 |  | ||||||
|         //Basically if we're still spinning keep applying gravity |  | ||||||
|         boolean angularVelocityLow = true; |  | ||||||
|         if(collidableTree != null){ |  | ||||||
|             if(collidableTree.getAngularVelocityMagnitude() > 0.0001){ |  | ||||||
|                 angularVelocityLow = false; |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
| 
 |  | ||||||
|          |          | ||||||
|         //state machine |         //state machine | ||||||
|         switch(state){ |         switch(state){ | ||||||
| @ -158,7 +127,6 @@ public class ClientGravityTree implements BehaviorTree { | |||||||
|                         fallTree.land(); |                         fallTree.land(); | ||||||
|                     } |                     } | ||||||
|                     frameCurrent = 0; |                     frameCurrent = 0; | ||||||
|                     gravityVelocity = 0; |  | ||||||
|                 } else { |                 } else { | ||||||
|                     //animation nonsense |                     //animation nonsense | ||||||
|                     frameCurrent++; |                     frameCurrent++; | ||||||
| @ -169,32 +137,6 @@ public class ClientGravityTree implements BehaviorTree { | |||||||
|                         } |                         } | ||||||
|                     } |                     } | ||||||
| 
 | 
 | ||||||
|                     //actual gravity calculations |  | ||||||
|                     if(gravityVelocity < gravityConstant){ |  | ||||||
|                         gravityVelocity = gravityVelocity + gravityAccel; |  | ||||||
|                     } |  | ||||||
|                     if(gravityVelocity > gravityConstant){ |  | ||||||
|                         gravityVelocity = gravityConstant; |  | ||||||
|                     } |  | ||||||
|                     float gravityDif = gravityVelocity * (float)Math.pow(1.0f - linearDamping,deltaTime * 2); |  | ||||||
|                     // Vector3d newGravityPos = new Vector3d(position.x,position.y - gravityDif,position.z); |  | ||||||
|                     // Entity terrainHit = Globals.clientSceneWrapper.getCollisionEngine().rayCast( |  | ||||||
|                     //     position, |  | ||||||
|                     //     new Vector3d(0,-1,0), |  | ||||||
|                     //     gravityDif, |  | ||||||
|                     //     CollisionMasks.terrainMask |  | ||||||
|                     // ); |  | ||||||
|                     // float hitFraction = Globals.clientSceneWrapper.getCollisionEngine().sweepTest(body, new Vector3f((float)position.x,(float)position.y,(float)position.z), new Vector3f((float)newGravityPos.x,(float)newGravityPos.y,(float)newGravityPos.z)); |  | ||||||
| //                    if(hitFraction >= 0){ |  | ||||||
| //                        collidable.addImpulse(new Impulse(new Vector3d(0,-1,0),gravityDif * hitFraction,"gravity")); |  | ||||||
| //                        position.set(new Vector3d(position.x,position.y - gravityDif * hitFraction,position.z)); |  | ||||||
| //                    } else { |  | ||||||
| //                        position.set(new Vector3d(position.x,position.y - gravityDif,position.z)); |  | ||||||
| //                    } |  | ||||||
|                     // if(hitFraction < 0){ |  | ||||||
|                     //     hitFraction = 1; |  | ||||||
|                     // } |  | ||||||
|                     collidable.addImpulse(new Impulse(new Vector3d(0,-1,0), new Vector3d(0,0,0), new Vector3d(position), gravityDif,"gravity")); |  | ||||||
|                 } |                 } | ||||||
|                 break; |                 break; | ||||||
|             case NOT_ACTIVE: |             case NOT_ACTIVE: | ||||||
|  | |||||||
| @ -21,7 +21,7 @@ import electrosphere.collision.collidable.Collidable; | |||||||
| import electrosphere.engine.Globals; | import electrosphere.engine.Globals; | ||||||
| import electrosphere.entity.Entity; | import electrosphere.entity.Entity; | ||||||
| import electrosphere.entity.EntityUtils; | import electrosphere.entity.EntityUtils; | ||||||
| import electrosphere.entity.state.BehaviorTree; | import electrosphere.entity.btree.BehaviorTree; | ||||||
| import electrosphere.entity.state.collidable.Impulse; | import electrosphere.entity.state.collidable.Impulse; | ||||||
| import electrosphere.entity.state.collidable.ServerCollidableTree; | import electrosphere.entity.state.collidable.ServerCollidableTree; | ||||||
| import electrosphere.entity.state.gravity.ClientGravityTree.GravityTreeState; | import electrosphere.entity.state.gravity.ClientGravityTree.GravityTreeState; | ||||||
| @ -46,9 +46,6 @@ public class ServerGravityTree implements BehaviorTree { | |||||||
|     int frameCurrent = 0; |     int frameCurrent = 0; | ||||||
|     int fallFrame = 1; |     int fallFrame = 1; | ||||||
|      |      | ||||||
|     float gravityVelocity = 0; |  | ||||||
|     float gravityAccel = 0.0007f; |  | ||||||
|      |  | ||||||
|     DBody body; |     DBody body; | ||||||
|     Collidable collidable; |     Collidable collidable; | ||||||
|      |      | ||||||
| @ -130,23 +127,12 @@ public class ServerGravityTree implements BehaviorTree { | |||||||
| //            } | //            } | ||||||
| //        } | //        } | ||||||
| 
 | 
 | ||||||
|         //Basically if we're still spinning keep applying gravity |  | ||||||
|         boolean angularVelocityLow = true; |  | ||||||
|         if(collidableTree != null){ |  | ||||||
|             if(collidableTree.getAngularVelocityMagnitude() > 0.0001){ |  | ||||||
|                 angularVelocityLow = false; |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
| 
 |  | ||||||
|          |          | ||||||
|         //state machine |         //state machine | ||||||
|         switch(state){ |         switch(state){ | ||||||
|             case ACTIVE: |             case ACTIVE: | ||||||
|                 if(hadGroundCollision()){ |                 if(hadGroundCollision()){ | ||||||
|                     setState(GravityTreeState.NOT_ACTIVE); |                     setState(GravityTreeState.NOT_ACTIVE); | ||||||
|                     if(!hadStructureCollision()){ |  | ||||||
| //                        position.set(new Vector3d(position.x,Globals.commonWorldData.getElevationAtPoint(position) + 0.0001f,position.z)); |  | ||||||
|                     } |  | ||||||
|                     ServerJumpTree jumpTree; |                     ServerJumpTree jumpTree; | ||||||
|                     if((jumpTree = ServerJumpTree.getServerJumpTree(parent))!=null){ |                     if((jumpTree = ServerJumpTree.getServerJumpTree(parent))!=null){ | ||||||
|                         jumpTree.land(); |                         jumpTree.land(); | ||||||
| @ -156,7 +142,6 @@ public class ServerGravityTree implements BehaviorTree { | |||||||
|                         fallTree.land(); |                         fallTree.land(); | ||||||
|                     } |                     } | ||||||
|                     frameCurrent = 0; |                     frameCurrent = 0; | ||||||
|                     gravityVelocity = 0; |  | ||||||
|                 } else { |                 } else { | ||||||
|                     //animation nonsense |                     //animation nonsense | ||||||
|                     frameCurrent++; |                     frameCurrent++; | ||||||
| @ -166,28 +151,6 @@ public class ServerGravityTree implements BehaviorTree { | |||||||
|                             fallTree.start(); |                             fallTree.start(); | ||||||
|                         } |                         } | ||||||
|                     } |                     } | ||||||
| 
 |  | ||||||
|                     //actual gravity calculations |  | ||||||
|                     if(gravityVelocity < gravityConstant){ |  | ||||||
|                         gravityVelocity = gravityVelocity + gravityAccel; |  | ||||||
|                     } |  | ||||||
|                     if(gravityVelocity > gravityConstant){ |  | ||||||
|                         gravityVelocity = gravityConstant; |  | ||||||
|                     } |  | ||||||
|                     float gravityDif = gravityVelocity * (float)Math.pow(1.0f - linearDamping,deltaTime * 2); |  | ||||||
|                     // Vector3d newGravityPos = new Vector3d(position.x,position.y - gravityDif,position.z); |  | ||||||
|                     // Realm parentRealm = Globals.realmManager.getEntityRealm(parent); |  | ||||||
|                     // float hitFraction = parentRealm.getCollisionEngine().sweepTest(body, new Vector3f((float)position.x,(float)position.y,(float)position.z), new Vector3f((float)newGravityPos.x,(float)newGravityPos.y,(float)newGravityPos.z)); |  | ||||||
| //                    if(hitFraction >= 0){ |  | ||||||
| //                        collidable.addImpulse(new Impulse(new Vector3d(0,-1,0),gravityDif * hitFraction,"gravity")); |  | ||||||
| //                        position.set(new Vector3d(position.x,position.y - gravityDif * hitFraction,position.z)); |  | ||||||
| //                    } else { |  | ||||||
| //                        position.set(new Vector3d(position.x,position.y - gravityDif,position.z)); |  | ||||||
| //                    } |  | ||||||
|                     // if(hitFraction < 0){ |  | ||||||
|                     //     hitFraction = 1; |  | ||||||
|                     // } |  | ||||||
|                     collidable.addImpulse(new Impulse(new Vector3d(0,-1,0), new Vector3d(0,0,0), new Vector3d(position), gravityDif,"gravity")); |  | ||||||
|                 } |                 } | ||||||
|                 break; |                 break; | ||||||
|             case NOT_ACTIVE: |             case NOT_ACTIVE: | ||||||
|  | |||||||
| @ -2,16 +2,16 @@ package electrosphere.entity.state.idle; | |||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| import electrosphere.net.synchronization.BehaviorTreeIdEnums; | import electrosphere.net.synchronization.BehaviorTreeIdEnums; | ||||||
| 
 |  | ||||||
| import electrosphere.entity.state.BehaviorTree; |  | ||||||
| import electrosphere.entity.state.attack.AttackTree; | import electrosphere.entity.state.attack.AttackTree; | ||||||
| import electrosphere.entity.state.movement.AirplaneMovementTree; | import electrosphere.entity.state.movement.AirplaneMovementTree; | ||||||
| import electrosphere.entity.state.movement.groundmove.GroundMovementTree; | import electrosphere.entity.state.movement.groundmove.GroundMovementTree; | ||||||
| import electrosphere.entity.state.movement.groundmove.GroundMovementTree.MovementTreeState; | import electrosphere.entity.state.movement.groundmove.GroundMovementTree.MovementTreeState; | ||||||
|  | import electrosphere.collision.PhysicsEntityUtils; | ||||||
| import electrosphere.engine.Globals; | import electrosphere.engine.Globals; | ||||||
| import electrosphere.entity.Entity; | import electrosphere.entity.Entity; | ||||||
| import electrosphere.entity.EntityDataStrings; | import electrosphere.entity.EntityDataStrings; | ||||||
| import electrosphere.entity.EntityUtils; | import electrosphere.entity.EntityUtils; | ||||||
|  | import electrosphere.entity.btree.BehaviorTree; | ||||||
| import electrosphere.entity.types.creature.CreatureUtils; | import electrosphere.entity.types.creature.CreatureUtils; | ||||||
| import electrosphere.net.synchronization.annotation.SyncedField; | import electrosphere.net.synchronization.annotation.SyncedField; | ||||||
| import electrosphere.net.synchronization.annotation.SynchronizableEnum; | import electrosphere.net.synchronization.annotation.SynchronizableEnum; | ||||||
|  | |||||||
| @ -1,6 +1,5 @@ | |||||||
| package electrosphere.entity.state.idle; | package electrosphere.entity.state.idle; | ||||||
| 
 | 
 | ||||||
| import electrosphere.entity.state.BehaviorTree; |  | ||||||
| import electrosphere.entity.state.attack.ServerAttackTree; | import electrosphere.entity.state.attack.ServerAttackTree; | ||||||
| import electrosphere.entity.state.attack.ServerAttackTree.AttackTreeState; | import electrosphere.entity.state.attack.ServerAttackTree.AttackTreeState; | ||||||
| import electrosphere.entity.state.idle.IdleTree.IdleTreeState; | import electrosphere.entity.state.idle.IdleTree.IdleTreeState; | ||||||
| @ -11,6 +10,7 @@ import electrosphere.engine.Globals; | |||||||
| import electrosphere.entity.Entity; | import electrosphere.entity.Entity; | ||||||
| import electrosphere.entity.EntityDataStrings; | import electrosphere.entity.EntityDataStrings; | ||||||
| import electrosphere.entity.EntityUtils; | import electrosphere.entity.EntityUtils; | ||||||
|  | import electrosphere.entity.btree.BehaviorTree; | ||||||
| import electrosphere.entity.types.creature.CreatureUtils; | import electrosphere.entity.types.creature.CreatureUtils; | ||||||
| import electrosphere.net.parser.net.message.EntityMessage; | import electrosphere.net.parser.net.message.EntityMessage; | ||||||
| import electrosphere.net.parser.net.message.SynchronizationMessage; | import electrosphere.net.parser.net.message.SynchronizationMessage; | ||||||
|  | |||||||
| @ -5,7 +5,7 @@ import java.util.concurrent.CopyOnWriteArrayList; | |||||||
| import electrosphere.engine.Globals; | import electrosphere.engine.Globals; | ||||||
| import electrosphere.entity.Entity; | import electrosphere.entity.Entity; | ||||||
| import electrosphere.entity.EntityUtils; | import electrosphere.entity.EntityUtils; | ||||||
| import electrosphere.entity.state.BehaviorTree; | import electrosphere.entity.btree.BehaviorTree; | ||||||
| import electrosphere.entity.state.equip.EquipState; | import electrosphere.entity.state.equip.EquipState; | ||||||
| import electrosphere.entity.types.item.ItemUtils; | import electrosphere.entity.types.item.ItemUtils; | ||||||
| import electrosphere.game.data.creature.type.equip.EquipPoint; | import electrosphere.game.data.creature.type.equip.EquipPoint; | ||||||
|  | |||||||
| @ -5,7 +5,7 @@ import java.util.concurrent.CopyOnWriteArrayList; | |||||||
| import electrosphere.engine.Globals; | import electrosphere.engine.Globals; | ||||||
| import electrosphere.entity.Entity; | import electrosphere.entity.Entity; | ||||||
| import electrosphere.entity.EntityUtils; | import electrosphere.entity.EntityUtils; | ||||||
| import electrosphere.entity.state.BehaviorTree; | import electrosphere.entity.btree.BehaviorTree; | ||||||
| import electrosphere.entity.state.equip.EquipState; | import electrosphere.entity.state.equip.EquipState; | ||||||
| import electrosphere.entity.types.item.ItemUtils; | import electrosphere.entity.types.item.ItemUtils; | ||||||
| import electrosphere.game.data.creature.type.equip.EquipPoint; | import electrosphere.game.data.creature.type.equip.EquipPoint; | ||||||
|  | |||||||
| @ -5,7 +5,7 @@ import org.joml.Vector3f; | |||||||
| import electrosphere.engine.Globals; | import electrosphere.engine.Globals; | ||||||
| import electrosphere.entity.Entity; | import electrosphere.entity.Entity; | ||||||
| import electrosphere.entity.EntityDataStrings; | import electrosphere.entity.EntityDataStrings; | ||||||
| import electrosphere.entity.state.BehaviorTree; | import electrosphere.entity.btree.BehaviorTree; | ||||||
| import electrosphere.entity.types.camera.CameraEntityUtils; | import electrosphere.entity.types.camera.CameraEntityUtils; | ||||||
| 
 | 
 | ||||||
| public class IronSightTree implements BehaviorTree { | public class IronSightTree implements BehaviorTree { | ||||||
|  | |||||||
| @ -8,7 +8,7 @@ import electrosphere.engine.Globals; | |||||||
| import electrosphere.engine.Main; | import electrosphere.engine.Main; | ||||||
| import electrosphere.entity.Entity; | import electrosphere.entity.Entity; | ||||||
| import electrosphere.entity.EntityUtils; | import electrosphere.entity.EntityUtils; | ||||||
| import electrosphere.entity.state.BehaviorTree; | import electrosphere.entity.btree.BehaviorTree; | ||||||
| import electrosphere.entity.types.creature.CreatureUtils; | import electrosphere.entity.types.creature.CreatureUtils; | ||||||
| import electrosphere.game.data.creature.type.CreatureType; | import electrosphere.game.data.creature.type.CreatureType; | ||||||
| import electrosphere.game.data.creature.type.HealthSystem; | import electrosphere.game.data.creature.type.HealthSystem; | ||||||
|  | |||||||
| @ -12,7 +12,7 @@ import electrosphere.engine.Globals; | |||||||
| import electrosphere.engine.Main; | import electrosphere.engine.Main; | ||||||
| import electrosphere.entity.Entity; | import electrosphere.entity.Entity; | ||||||
| import electrosphere.entity.EntityUtils; | import electrosphere.entity.EntityUtils; | ||||||
| import electrosphere.entity.state.BehaviorTree; | import electrosphere.entity.btree.BehaviorTree; | ||||||
| import electrosphere.entity.state.collidable.Impulse; | import electrosphere.entity.state.collidable.Impulse; | ||||||
| import electrosphere.entity.types.camera.CameraEntityUtils; | import electrosphere.entity.types.camera.CameraEntityUtils; | ||||||
| import electrosphere.entity.types.creature.CreatureUtils; | import electrosphere.entity.types.creature.CreatureUtils; | ||||||
|  | |||||||
| @ -5,7 +5,7 @@ import org.joml.Quaternionf; | |||||||
| 
 | 
 | ||||||
| import electrosphere.entity.Entity; | import electrosphere.entity.Entity; | ||||||
| import electrosphere.entity.EntityUtils; | import electrosphere.entity.EntityUtils; | ||||||
| import electrosphere.entity.state.BehaviorTree; | import electrosphere.entity.btree.BehaviorTree; | ||||||
| 
 | 
 | ||||||
| public class ApplyRotationTree implements BehaviorTree { | public class ApplyRotationTree implements BehaviorTree { | ||||||
|      |      | ||||||
|  | |||||||
| @ -3,7 +3,7 @@ package electrosphere.entity.state.movement; | |||||||
| import electrosphere.entity.Entity; | import electrosphere.entity.Entity; | ||||||
| import electrosphere.entity.EntityDataStrings; | import electrosphere.entity.EntityDataStrings; | ||||||
| import electrosphere.entity.EntityUtils; | import electrosphere.entity.EntityUtils; | ||||||
| import electrosphere.entity.state.BehaviorTree; | import electrosphere.entity.btree.BehaviorTree; | ||||||
| import electrosphere.renderer.actor.Actor; | import electrosphere.renderer.actor.Actor; | ||||||
| 
 | 
 | ||||||
| public class FallTree implements BehaviorTree { | public class FallTree implements BehaviorTree { | ||||||
|  | |||||||
| @ -1,12 +1,16 @@ | |||||||
| package electrosphere.entity.state.movement; | package electrosphere.entity.state.movement; | ||||||
| 
 | 
 | ||||||
| import org.joml.Vector3d; | import org.joml.Vector3d; | ||||||
|  | import org.ode4j.math.DVector3C; | ||||||
|  | import org.ode4j.ode.DBody; | ||||||
| 
 | 
 | ||||||
|  | import electrosphere.collision.PhysicsEntityUtils; | ||||||
|  | import electrosphere.collision.PhysicsUtils; | ||||||
| import electrosphere.collision.collidable.Collidable; | import electrosphere.collision.collidable.Collidable; | ||||||
| import electrosphere.entity.Entity; | import electrosphere.entity.Entity; | ||||||
| import electrosphere.entity.EntityDataStrings; | import electrosphere.entity.EntityDataStrings; | ||||||
| import electrosphere.entity.EntityUtils; | import electrosphere.entity.EntityUtils; | ||||||
| import electrosphere.entity.state.BehaviorTree; | import electrosphere.entity.btree.BehaviorTree; | ||||||
| import electrosphere.entity.state.collidable.Impulse; | import electrosphere.entity.state.collidable.Impulse; | ||||||
| import electrosphere.entity.state.gravity.GravityUtils; | import electrosphere.entity.state.gravity.GravityUtils; | ||||||
| import electrosphere.entity.types.collision.CollisionObjUtils; | import electrosphere.entity.types.collision.CollisionObjUtils; | ||||||
| @ -40,12 +44,12 @@ public class JumpTree implements BehaviorTree { | |||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     public void start(){ |     public void start(){ | ||||||
|         if(state == JumpState.INACTIVE){ |         // if(state == JumpState.INACTIVE){ | ||||||
|             state = JumpState.ACTIVE; |             state = JumpState.ACTIVE; | ||||||
|             currentFrame = 0; |             currentFrame = 0; | ||||||
|             currentJumpForce = jumpForce; |             currentJumpForce = jumpForce; | ||||||
|             GravityUtils.clientAttemptActivateGravity(parent); |             GravityUtils.clientAttemptActivateGravity(parent); | ||||||
|         } |         // } | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     @Override |     @Override | ||||||
| @ -62,8 +66,12 @@ public class JumpTree implements BehaviorTree { | |||||||
|             } |             } | ||||||
|             currentFrame++; |             currentFrame++; | ||||||
|             currentJumpForce = currentJumpForce * jumpFalloff; |             currentJumpForce = currentJumpForce * jumpFalloff; | ||||||
|  |             //stop body falling if it is | ||||||
|  |             DBody body = PhysicsEntityUtils.getDBody(parent); | ||||||
|  |             DVector3C linearVelocity = body.getLinearVel(); | ||||||
|  |             body.setLinearVel(linearVelocity.get0(), 0, linearVelocity.get2()); | ||||||
|             //push parent up |             //push parent up | ||||||
|             CollisionObjUtils.getCollidable(parent).addImpulse(new Impulse(new Vector3d(0,1,0), new Vector3d(0,0,0), new Vector3d(EntityUtils.getPosition(parent)), currentJumpForce, Collidable.TYPE_FORCE)); |             body.addForce(0, currentJumpForce, 0); | ||||||
|             //potentially disable |             //potentially disable | ||||||
|             if(currentFrame >= jumpFrames){ |             if(currentFrame >= jumpFrames){ | ||||||
|                 state = JumpState.AWAITING_LAND; |                 state = JumpState.AWAITING_LAND; | ||||||
|  | |||||||
| @ -7,7 +7,7 @@ import electrosphere.engine.Globals; | |||||||
| import electrosphere.entity.Entity; | import electrosphere.entity.Entity; | ||||||
| import electrosphere.entity.EntityDataStrings; | import electrosphere.entity.EntityDataStrings; | ||||||
| import electrosphere.entity.EntityUtils; | import electrosphere.entity.EntityUtils; | ||||||
| import electrosphere.entity.state.BehaviorTree; | import electrosphere.entity.btree.BehaviorTree; | ||||||
| import electrosphere.server.datacell.utils.ServerBehaviorTreeUtils; | import electrosphere.server.datacell.utils.ServerBehaviorTreeUtils; | ||||||
| 
 | 
 | ||||||
| public class ProjectileTree implements BehaviorTree { | public class ProjectileTree implements BehaviorTree { | ||||||
|  | |||||||
| @ -3,7 +3,7 @@ package electrosphere.entity.state.movement; | |||||||
| import electrosphere.entity.Entity; | import electrosphere.entity.Entity; | ||||||
| import electrosphere.entity.EntityDataStrings; | import electrosphere.entity.EntityDataStrings; | ||||||
| import electrosphere.entity.EntityUtils; | import electrosphere.entity.EntityUtils; | ||||||
| import electrosphere.entity.state.BehaviorTree; | import electrosphere.entity.btree.BehaviorTree; | ||||||
| import electrosphere.renderer.actor.Actor; | import electrosphere.renderer.actor.Actor; | ||||||
| 
 | 
 | ||||||
| public class ServerFallTree implements BehaviorTree { | public class ServerFallTree implements BehaviorTree { | ||||||
|  | |||||||
| @ -1,12 +1,15 @@ | |||||||
| package electrosphere.entity.state.movement; | package electrosphere.entity.state.movement; | ||||||
| 
 | 
 | ||||||
| import org.joml.Vector3d; | import org.joml.Vector3d; | ||||||
|  | import org.ode4j.math.DVector3C; | ||||||
|  | import org.ode4j.ode.DBody; | ||||||
| 
 | 
 | ||||||
|  | import electrosphere.collision.PhysicsEntityUtils; | ||||||
| import electrosphere.collision.collidable.Collidable; | import electrosphere.collision.collidable.Collidable; | ||||||
| import electrosphere.entity.Entity; | import electrosphere.entity.Entity; | ||||||
| import electrosphere.entity.EntityDataStrings; | import electrosphere.entity.EntityDataStrings; | ||||||
| import electrosphere.entity.EntityUtils; | import electrosphere.entity.EntityUtils; | ||||||
| import electrosphere.entity.state.BehaviorTree; | import electrosphere.entity.btree.BehaviorTree; | ||||||
| import electrosphere.entity.state.collidable.Impulse; | import electrosphere.entity.state.collidable.Impulse; | ||||||
| import electrosphere.entity.state.gravity.GravityUtils; | import electrosphere.entity.state.gravity.GravityUtils; | ||||||
| import electrosphere.entity.types.collision.CollisionObjUtils; | import electrosphere.entity.types.collision.CollisionObjUtils; | ||||||
| @ -62,8 +65,12 @@ public class ServerJumpTree implements BehaviorTree { | |||||||
|             } |             } | ||||||
|             currentFrame++; |             currentFrame++; | ||||||
|             currentJumpForce = currentJumpForce * jumpFalloff; |             currentJumpForce = currentJumpForce * jumpFalloff; | ||||||
|  |             //stop body falling if it is | ||||||
|  |             DBody body = PhysicsEntityUtils.getDBody(parent); | ||||||
|  |             DVector3C linearVelocity = body.getLinearVel(); | ||||||
|  |             body.setLinearVel(linearVelocity.get0(), 0, linearVelocity.get2()); | ||||||
|             //push parent up |             //push parent up | ||||||
|             CollisionObjUtils.getCollidable(parent).addImpulse(new Impulse(new Vector3d(0,1,0), new Vector3d(0,0,0), new Vector3d(EntityUtils.getPosition(parent)), currentJumpForce, Collidable.TYPE_FORCE)); |             body.addForce(0, currentJumpForce, 0); | ||||||
|             //potentially disable |             //potentially disable | ||||||
|             if(currentFrame >= jumpFrames){ |             if(currentFrame >= jumpFrames){ | ||||||
|                 state = JumpState.AWAITING_LAND; |                 state = JumpState.AWAITING_LAND; | ||||||
|  | |||||||
| @ -2,7 +2,7 @@ package electrosphere.entity.state.movement; | |||||||
| 
 | 
 | ||||||
| import electrosphere.engine.Main; | import electrosphere.engine.Main; | ||||||
| import electrosphere.entity.Entity; | import electrosphere.entity.Entity; | ||||||
| import electrosphere.entity.state.BehaviorTree; | import electrosphere.entity.btree.BehaviorTree; | ||||||
| import electrosphere.entity.state.movement.groundmove.ServerGroundMovementTree; | import electrosphere.entity.state.movement.groundmove.ServerGroundMovementTree; | ||||||
| import electrosphere.entity.state.movement.groundmove.ServerGroundMovementTree.MovementTreeState; | import electrosphere.entity.state.movement.groundmove.ServerGroundMovementTree.MovementTreeState; | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -2,7 +2,7 @@ package electrosphere.entity.state.movement; | |||||||
| 
 | 
 | ||||||
| import electrosphere.engine.Main; | import electrosphere.engine.Main; | ||||||
| import electrosphere.entity.Entity; | import electrosphere.entity.Entity; | ||||||
| import electrosphere.entity.state.BehaviorTree; | import electrosphere.entity.btree.BehaviorTree; | ||||||
| import electrosphere.entity.state.movement.groundmove.GroundMovementTree; | import electrosphere.entity.state.movement.groundmove.GroundMovementTree; | ||||||
| import electrosphere.entity.state.movement.groundmove.GroundMovementTree.MovementTreeState; | import electrosphere.entity.state.movement.groundmove.GroundMovementTree.MovementTreeState; | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -4,16 +4,19 @@ import electrosphere.entity.state.collidable.Impulse; | |||||||
| import electrosphere.entity.state.gravity.ClientGravityTree; | import electrosphere.entity.state.gravity.ClientGravityTree; | ||||||
| import electrosphere.entity.state.gravity.GravityUtils; | import electrosphere.entity.state.gravity.GravityUtils; | ||||||
| import electrosphere.collision.CollisionEngine; | import electrosphere.collision.CollisionEngine; | ||||||
|  | import electrosphere.collision.PhysicsEntityUtils; | ||||||
| import electrosphere.collision.PhysicsUtils; | import electrosphere.collision.PhysicsUtils; | ||||||
| import electrosphere.collision.collidable.Collidable; | import electrosphere.collision.collidable.Collidable; | ||||||
| import electrosphere.engine.Globals; | import electrosphere.engine.Globals; | ||||||
| import electrosphere.engine.Main; | import electrosphere.engine.Main; | ||||||
| import electrosphere.entity.types.camera.CameraEntityUtils; | import electrosphere.entity.types.camera.CameraEntityUtils; | ||||||
|  | import electrosphere.entity.types.collision.CollisionObjUtils; | ||||||
| import electrosphere.entity.types.creature.CreatureUtils; | import electrosphere.entity.types.creature.CreatureUtils; | ||||||
|  | import electrosphere.entity.ClientEntityUtils; | ||||||
| import electrosphere.entity.Entity; | import electrosphere.entity.Entity; | ||||||
| import electrosphere.entity.EntityDataStrings; | import electrosphere.entity.EntityDataStrings; | ||||||
| import electrosphere.entity.EntityUtils; | import electrosphere.entity.EntityUtils; | ||||||
| import electrosphere.entity.state.BehaviorTree; | import electrosphere.entity.btree.BehaviorTree; | ||||||
| import electrosphere.entity.state.attack.AttackTree; | import electrosphere.entity.state.attack.AttackTree; | ||||||
| import electrosphere.entity.state.attack.AttackTree.AttackTreeState; | import electrosphere.entity.state.attack.AttackTree.AttackTreeState; | ||||||
| import electrosphere.entity.state.movement.FallTree; | import electrosphere.entity.state.movement.FallTree; | ||||||
| @ -35,6 +38,9 @@ import org.joml.Quaterniond; | |||||||
| import org.joml.Quaternionf; | import org.joml.Quaternionf; | ||||||
| import org.joml.Vector3d; | import org.joml.Vector3d; | ||||||
| import org.joml.Vector3f; | import org.joml.Vector3f; | ||||||
|  | import org.ode4j.math.DVector3; | ||||||
|  | import org.ode4j.math.DVector3C; | ||||||
|  | import org.ode4j.ode.DBody; | ||||||
| 
 | 
 | ||||||
| /* | /* | ||||||
| Behavior tree for movement in an entity | Behavior tree for movement in an entity | ||||||
| @ -162,6 +168,8 @@ public class GroundMovementTree implements BehaviorTree { | |||||||
|         Vector3d position = EntityUtils.getPosition(parent); |         Vector3d position = EntityUtils.getPosition(parent); | ||||||
|         Vector3d facingVector = CreatureUtils.getFacingVector(parent); |         Vector3d facingVector = CreatureUtils.getFacingVector(parent); | ||||||
|         Vector3d movementVector = new Vector3d(facingVector); |         Vector3d movementVector = new Vector3d(facingVector); | ||||||
|  |         DBody body = PhysicsEntityUtils.getDBody(parent); | ||||||
|  |         DVector3C linearVelocity = body.getLinearVel(); | ||||||
|         switch(facing){ |         switch(facing){ | ||||||
|             case FORWARD: |             case FORWARD: | ||||||
|             movementVector.normalize(); |             movementVector.normalize(); | ||||||
| @ -193,6 +201,11 @@ public class GroundMovementTree implements BehaviorTree { | |||||||
| //        float movementYaw = CameraEntityUtils.getCameraYaw(Globals.playerCamera); | //        float movementYaw = CameraEntityUtils.getCameraYaw(Globals.playerCamera); | ||||||
|         Quaterniond movementQuaternion = new Quaterniond().rotationTo(new Vector3d(0,0,1), new Vector3d(facingVector.x,0,facingVector.z)).normalize(); |         Quaterniond movementQuaternion = new Quaterniond().rotationTo(new Vector3d(0,0,1), new Vector3d(facingVector.x,0,facingVector.z)).normalize(); | ||||||
|         Quaterniond rotation = EntityUtils.getRotation(parent); |         Quaterniond rotation = EntityUtils.getRotation(parent); | ||||||
|  |         //TODO: optimize away and document (I know for the moment if this exception isn't here it will bite me in the ass later) | ||||||
|  |         if(facingVector.length() == 0){ | ||||||
|  |             throw new IllegalStateException("Facing vector length is 0. This will break ODE4J"); | ||||||
|  |         } | ||||||
|  |         rotation.set(movementQuaternion); | ||||||
|          |          | ||||||
|         //parse attached network messages |         //parse attached network messages | ||||||
|         for(EntityMessage message : networkMessageQueue){ |         for(EntityMessage message : networkMessageQueue){ | ||||||
| @ -239,6 +252,7 @@ public class GroundMovementTree implements BehaviorTree { | |||||||
|                         // } |                         // } | ||||||
|                         //we want to always update the server facing vector with where the client says they're facing |                         //we want to always update the server facing vector with where the client says they're facing | ||||||
|                         EntityUtils.getRotation(parent).set(message.getrotationX(),message.getrotationY(),message.getrotationZ(),message.getrotationW()); |                         EntityUtils.getRotation(parent).set(message.getrotationX(),message.getrotationY(),message.getrotationZ(),message.getrotationW()); | ||||||
|  |                         CollisionObjUtils.clientPositionCharacter(parent, position); | ||||||
|                         // CreatureUtils.setFacingVector(parent, new Vector3d(message.getrotationX(),message.getrotationY(),message.getrotationZ())); |                         // CreatureUtils.setFacingVector(parent, new Vector3d(message.getrotationX(),message.getrotationY(),message.getrotationZ())); | ||||||
|                         break; |                         break; | ||||||
|                     } |                     } | ||||||
| @ -272,9 +286,13 @@ public class GroundMovementTree implements BehaviorTree { | |||||||
|                     state = MovementTreeState.MOVE; |                     state = MovementTreeState.MOVE; | ||||||
|                 } |                 } | ||||||
|                 CreatureUtils.setVelocity(parent, velocity); |                 CreatureUtils.setVelocity(parent, velocity); | ||||||
| //                //actually update |                 //actually update | ||||||
|                 collidable.addImpulse(new Impulse(new Vector3d(movementVector), new Vector3d(0,0,0), new Vector3d(0,0,0), velocity * Globals.timekeeper.getSimFrameTime(), "movement")); |                 body.setLinearVel( | ||||||
| //                position.set(newPosition); |                     movementVector.x * velocity * Globals.timekeeper.getSimFrameTime(), | ||||||
|  |                     linearVelocity.get1(), | ||||||
|  |                     movementVector.z * velocity * Globals.timekeeper.getSimFrameTime() | ||||||
|  |                 ); | ||||||
|  |                 body.setAngularVel(0, 0, 0); | ||||||
|                 rotation.set(movementQuaternion); |                 rotation.set(movementQuaternion); | ||||||
|                  |                  | ||||||
|                 GravityUtils.clientAttemptActivateGravity(parent); |                 GravityUtils.clientAttemptActivateGravity(parent); | ||||||
| @ -298,8 +316,12 @@ public class GroundMovementTree implements BehaviorTree { | |||||||
|                     velocity = maxNaturalVelocity; |                     velocity = maxNaturalVelocity; | ||||||
|                     CreatureUtils.setVelocity(parent, velocity); |                     CreatureUtils.setVelocity(parent, velocity); | ||||||
|                 } |                 } | ||||||
|                 collidable.addImpulse(new Impulse(new Vector3d(movementVector), new Vector3d(0,0,0), new Vector3d(0,0,0), velocity * Globals.timekeeper.getSimFrameTime(), "movement")); |                 body.setLinearVel( | ||||||
| //                position.set(newPosition); |                     movementVector.x * velocity * Globals.timekeeper.getSimFrameTime(), | ||||||
|  |                     linearVelocity.get1(), | ||||||
|  |                     movementVector.z * velocity * Globals.timekeeper.getSimFrameTime() | ||||||
|  |                 ); | ||||||
|  |                 body.setAngularVel(0, 0, 0); | ||||||
|                 rotation.set(movementQuaternion); |                 rotation.set(movementQuaternion); | ||||||
|                  |                  | ||||||
|                 GravityUtils.clientAttemptActivateGravity(parent); |                 GravityUtils.clientAttemptActivateGravity(parent); | ||||||
| @ -332,8 +354,12 @@ public class GroundMovementTree implements BehaviorTree { | |||||||
|                     } |                     } | ||||||
|                 } |                 } | ||||||
|                 CreatureUtils.setVelocity(parent, velocity); |                 CreatureUtils.setVelocity(parent, velocity); | ||||||
|                 collidable.addImpulse(new Impulse(new Vector3d(movementVector), new Vector3d(0,0,0), new Vector3d(0,0,0), velocity * Globals.timekeeper.getSimFrameTime(), "movement")); |                 body.setLinearVel( | ||||||
| //                position.set(newPosition); |                     movementVector.x * velocity * Globals.timekeeper.getSimFrameTime(), | ||||||
|  |                     linearVelocity.get1(), | ||||||
|  |                     movementVector.z * velocity * Globals.timekeeper.getSimFrameTime() | ||||||
|  |                 ); | ||||||
|  |                 body.setAngularVel(0, 0, 0); | ||||||
|                 rotation.set(movementQuaternion); |                 rotation.set(movementQuaternion); | ||||||
|                  |                  | ||||||
|                 GravityUtils.clientAttemptActivateGravity(parent); |                 GravityUtils.clientAttemptActivateGravity(parent); | ||||||
|  | |||||||
| @ -3,6 +3,7 @@ package electrosphere.entity.state.movement.groundmove; | |||||||
| import electrosphere.entity.state.collidable.Impulse; | import electrosphere.entity.state.collidable.Impulse; | ||||||
| import electrosphere.entity.state.gravity.GravityUtils; | import electrosphere.entity.state.gravity.GravityUtils; | ||||||
| import electrosphere.collision.CollisionEngine; | import electrosphere.collision.CollisionEngine; | ||||||
|  | import electrosphere.collision.PhysicsEntityUtils; | ||||||
| import electrosphere.collision.PhysicsUtils; | import electrosphere.collision.PhysicsUtils; | ||||||
| import electrosphere.collision.collidable.Collidable; | import electrosphere.collision.collidable.Collidable; | ||||||
| import electrosphere.engine.Globals; | import electrosphere.engine.Globals; | ||||||
| @ -12,7 +13,7 @@ import electrosphere.entity.types.creature.CreatureUtils; | |||||||
| import electrosphere.entity.Entity; | import electrosphere.entity.Entity; | ||||||
| import electrosphere.entity.EntityDataStrings; | import electrosphere.entity.EntityDataStrings; | ||||||
| import electrosphere.entity.EntityUtils; | import electrosphere.entity.EntityUtils; | ||||||
| import electrosphere.entity.state.BehaviorTree; | import electrosphere.entity.btree.BehaviorTree; | ||||||
| import electrosphere.entity.state.attack.ServerAttackTree; | import electrosphere.entity.state.attack.ServerAttackTree; | ||||||
| import electrosphere.entity.state.attack.ServerAttackTree.AttackTreeState; | import electrosphere.entity.state.attack.ServerAttackTree.AttackTreeState; | ||||||
| import electrosphere.entity.state.movement.ServerFallTree; | import electrosphere.entity.state.movement.ServerFallTree; | ||||||
| @ -35,6 +36,8 @@ import org.joml.Quaterniond; | |||||||
| import org.joml.Quaternionf; | import org.joml.Quaternionf; | ||||||
| import org.joml.Vector3d; | import org.joml.Vector3d; | ||||||
| import org.joml.Vector3f; | import org.joml.Vector3f; | ||||||
|  | import org.ode4j.math.DVector3C; | ||||||
|  | import org.ode4j.ode.DBody; | ||||||
| 
 | 
 | ||||||
| /* | /* | ||||||
| Behavior tree for movement in an entity | Behavior tree for movement in an entity | ||||||
| @ -162,6 +165,8 @@ public class ServerGroundMovementTree implements BehaviorTree { | |||||||
|         Vector3d position = EntityUtils.getPosition(parent); |         Vector3d position = EntityUtils.getPosition(parent); | ||||||
|         Vector3d facingVector = CreatureUtils.getFacingVector(parent); |         Vector3d facingVector = CreatureUtils.getFacingVector(parent); | ||||||
|         Vector3d movementVector = new Vector3d(facingVector); |         Vector3d movementVector = new Vector3d(facingVector); | ||||||
|  |         DBody body = PhysicsEntityUtils.getDBody(parent); | ||||||
|  |         DVector3C linearVelocity = body.getLinearVel(); | ||||||
|         switch(facing){ |         switch(facing){ | ||||||
|             case FORWARD: |             case FORWARD: | ||||||
|             movementVector.normalize(); |             movementVector.normalize(); | ||||||
| @ -193,6 +198,11 @@ public class ServerGroundMovementTree implements BehaviorTree { | |||||||
| //        float movementYaw = CameraEntityUtils.getCameraYaw(Globals.playerCamera); | //        float movementYaw = CameraEntityUtils.getCameraYaw(Globals.playerCamera); | ||||||
|         Quaterniond movementQuaternion = new Quaterniond().rotationTo(new Vector3d(0,0,1), new Vector3d(facingVector.x,0,facingVector.z)).normalize(); |         Quaterniond movementQuaternion = new Quaterniond().rotationTo(new Vector3d(0,0,1), new Vector3d(facingVector.x,0,facingVector.z)).normalize(); | ||||||
|         Quaterniond rotation = EntityUtils.getRotation(parent); |         Quaterniond rotation = EntityUtils.getRotation(parent); | ||||||
|  |         //TODO: optimize away and document (I know for the moment if this exception isn't here it will bite me in the ass later) | ||||||
|  |         if(facingVector.length() == 0){ | ||||||
|  |             throw new IllegalStateException("Facing vector length is 0. This will break ODE4J"); | ||||||
|  |         } | ||||||
|  |         rotation.set(movementQuaternion); | ||||||
|          |          | ||||||
|         //parse attached network messages |         //parse attached network messages | ||||||
|         for(EntityMessage message : networkMessageQueue){ |         for(EntityMessage message : networkMessageQueue){ | ||||||
| @ -264,7 +274,12 @@ public class ServerGroundMovementTree implements BehaviorTree { | |||||||
|                 } |                 } | ||||||
|                 CreatureUtils.setVelocity(parent, velocity); |                 CreatureUtils.setVelocity(parent, velocity); | ||||||
| //                //actually update | //                //actually update | ||||||
|                 collidable.addImpulse(new Impulse(new Vector3d(movementVector), new Vector3d(0,0,0), new Vector3d(0,0,0), velocity * Globals.timekeeper.getSimFrameTime(), "movement")); |                 PhysicsEntityUtils.getDBody(parent).setLinearVel( | ||||||
|  |                     movementVector.x * velocity * Globals.timekeeper.getSimFrameTime(), | ||||||
|  |                     linearVelocity.get1(), | ||||||
|  |                     movementVector.z * velocity * Globals.timekeeper.getSimFrameTime() | ||||||
|  |                 ); | ||||||
|  |                 body.setAngularVel(0, 0, 0); | ||||||
| //                position.set(newPosition); | //                position.set(newPosition); | ||||||
|                 rotation.set(movementQuaternion); |                 rotation.set(movementQuaternion); | ||||||
|                  |                  | ||||||
| @ -304,7 +319,12 @@ public class ServerGroundMovementTree implements BehaviorTree { | |||||||
|                     velocity = maxNaturalVelocity; |                     velocity = maxNaturalVelocity; | ||||||
|                     CreatureUtils.setVelocity(parent, velocity); |                     CreatureUtils.setVelocity(parent, velocity); | ||||||
|                 } |                 } | ||||||
|                 collidable.addImpulse(new Impulse(new Vector3d(movementVector), new Vector3d(0,0,0), new Vector3d(0,0,0), velocity * Globals.timekeeper.getSimFrameTime(), "movement")); |                 PhysicsEntityUtils.getDBody(parent).setLinearVel( | ||||||
|  |                     movementVector.x * velocity * Globals.timekeeper.getSimFrameTime(), | ||||||
|  |                     linearVelocity.get1(), | ||||||
|  |                     movementVector.z * velocity * Globals.timekeeper.getSimFrameTime() | ||||||
|  |                 ); | ||||||
|  |                 body.setAngularVel(0, 0, 0); | ||||||
| //                position.set(newPosition); | //                position.set(newPosition); | ||||||
|                 rotation.set(movementQuaternion); |                 rotation.set(movementQuaternion); | ||||||
|                  |                  | ||||||
| @ -353,7 +373,12 @@ public class ServerGroundMovementTree implements BehaviorTree { | |||||||
|                     } |                     } | ||||||
|                 } |                 } | ||||||
|                 CreatureUtils.setVelocity(parent, velocity); |                 CreatureUtils.setVelocity(parent, velocity); | ||||||
|                 collidable.addImpulse(new Impulse(new Vector3d(movementVector), new Vector3d(0,0,0), new Vector3d(0,0,0), velocity * Globals.timekeeper.getSimFrameTime(), "movement")); |                 PhysicsEntityUtils.getDBody(parent).setLinearVel( | ||||||
|  |                     movementVector.x * velocity * Globals.timekeeper.getSimFrameTime(), | ||||||
|  |                     linearVelocity.get1(), | ||||||
|  |                     movementVector.z * velocity * Globals.timekeeper.getSimFrameTime() | ||||||
|  |                 ); | ||||||
|  |                 body.setAngularVel(0, 0, 0); | ||||||
| //                position.set(newPosition); | //                position.set(newPosition); | ||||||
|                 rotation.set(movementQuaternion); |                 rotation.set(movementQuaternion); | ||||||
|                  |                  | ||||||
|  | |||||||
| @ -12,7 +12,7 @@ import electrosphere.engine.Globals; | |||||||
| import electrosphere.entity.Entity; | import electrosphere.entity.Entity; | ||||||
| import electrosphere.entity.EntityDataStrings; | import electrosphere.entity.EntityDataStrings; | ||||||
| import electrosphere.entity.EntityUtils; | import electrosphere.entity.EntityUtils; | ||||||
| import electrosphere.entity.state.BehaviorTree; | import electrosphere.entity.btree.BehaviorTree; | ||||||
| import electrosphere.entity.state.view.ViewUtils; | import electrosphere.entity.state.view.ViewUtils; | ||||||
| import electrosphere.entity.types.creature.CreatureUtils; | import electrosphere.entity.types.creature.CreatureUtils; | ||||||
| import electrosphere.renderer.actor.Actor; | import electrosphere.renderer.actor.Actor; | ||||||
|  | |||||||
| @ -12,7 +12,7 @@ import electrosphere.engine.Globals; | |||||||
| import electrosphere.entity.Entity; | import electrosphere.entity.Entity; | ||||||
| import electrosphere.entity.EntityDataStrings; | import electrosphere.entity.EntityDataStrings; | ||||||
| import electrosphere.entity.EntityUtils; | import electrosphere.entity.EntityUtils; | ||||||
| import electrosphere.entity.state.BehaviorTree; | import electrosphere.entity.btree.BehaviorTree; | ||||||
| import electrosphere.entity.state.view.ViewUtils; | import electrosphere.entity.state.view.ViewUtils; | ||||||
| import electrosphere.entity.types.creature.CreatureUtils; | import electrosphere.entity.types.creature.CreatureUtils; | ||||||
| import electrosphere.renderer.actor.Actor; | import electrosphere.renderer.actor.Actor; | ||||||
|  | |||||||
| @ -5,7 +5,7 @@ import electrosphere.entity.Entity; | |||||||
| import electrosphere.entity.EntityCreationUtils; | import electrosphere.entity.EntityCreationUtils; | ||||||
| import electrosphere.entity.EntityDataStrings; | import electrosphere.entity.EntityDataStrings; | ||||||
| import electrosphere.entity.EntityUtils; | import electrosphere.entity.EntityUtils; | ||||||
| import electrosphere.entity.state.BehaviorTree; | import electrosphere.entity.btree.BehaviorTree; | ||||||
| 
 | 
 | ||||||
| import org.joml.Matrix4f; | import org.joml.Matrix4f; | ||||||
| import org.joml.Quaternionf; | import org.joml.Quaternionf; | ||||||
|  | |||||||
| @ -41,10 +41,6 @@ public class CollisionObjUtils { | |||||||
|         rVal.putData(EntityDataStrings.COLLISION_ENTITY_COLLISION_OBJECT, planeObject); |         rVal.putData(EntityDataStrings.COLLISION_ENTITY_COLLISION_OBJECT, planeObject); | ||||||
|         rVal.putData(EntityDataStrings.COLLISION_ENTITY_COLLIDABLE, collidable); |         rVal.putData(EntityDataStrings.COLLISION_ENTITY_COLLIDABLE, collidable); | ||||||
|         rVal.putData(EntityDataStrings.PHYSICS_MASS, mass); |         rVal.putData(EntityDataStrings.PHYSICS_MASS, mass); | ||||||
|         //inertia tensor |  | ||||||
|         //https://scienceworld.wolfram.com/physics/MomentofInertiaCylinder.html |  | ||||||
|         Matrix4f inertiaTensor = new Matrix4f().zero(); |  | ||||||
|         rVal.putData(EntityDataStrings.PHYSICS_INVERSE_INERTIA_TENSOR, inertiaTensor); |  | ||||||
|         rVal.putData(EntityDataStrings.DATA_STRING_DRAW, true); |         rVal.putData(EntityDataStrings.DATA_STRING_DRAW, true); | ||||||
|          |          | ||||||
|         return rVal; |         return rVal; | ||||||
| @ -67,10 +63,6 @@ public class CollisionObjUtils { | |||||||
|         rVal.putData(EntityDataStrings.COLLISION_ENTITY_COLLISION_OBJECT, planeObject); |         rVal.putData(EntityDataStrings.COLLISION_ENTITY_COLLISION_OBJECT, planeObject); | ||||||
|         rVal.putData(EntityDataStrings.COLLISION_ENTITY_COLLIDABLE, collidable); |         rVal.putData(EntityDataStrings.COLLISION_ENTITY_COLLIDABLE, collidable); | ||||||
|         rVal.putData(EntityDataStrings.PHYSICS_MASS, mass); |         rVal.putData(EntityDataStrings.PHYSICS_MASS, mass); | ||||||
|         //inertia tensor |  | ||||||
|         //https://scienceworld.wolfram.com/physics/MomentofInertiaCylinder.html |  | ||||||
|         Matrix4f inertiaTensor = new Matrix4f().zero(); |  | ||||||
|         rVal.putData(EntityDataStrings.PHYSICS_INVERSE_INERTIA_TENSOR, inertiaTensor); |  | ||||||
|         rVal.putData(EntityDataStrings.DATA_STRING_DRAW, true); |         rVal.putData(EntityDataStrings.DATA_STRING_DRAW, true); | ||||||
|          |          | ||||||
|         return rVal; |         return rVal; | ||||||
| @ -94,10 +86,6 @@ public class CollisionObjUtils { | |||||||
|         rVal.putData(EntityDataStrings.COLLISION_ENTITY_COLLISION_OBJECT, cubeObject); |         rVal.putData(EntityDataStrings.COLLISION_ENTITY_COLLISION_OBJECT, cubeObject); | ||||||
|         rVal.putData(EntityDataStrings.COLLISION_ENTITY_COLLIDABLE, collidable); |         rVal.putData(EntityDataStrings.COLLISION_ENTITY_COLLIDABLE, collidable); | ||||||
|         rVal.putData(EntityDataStrings.PHYSICS_MASS, mass); |         rVal.putData(EntityDataStrings.PHYSICS_MASS, mass); | ||||||
|         //inertia tensor |  | ||||||
|         //https://hepweb.ucsd.edu/ph110b/110b_notes/node26.html |  | ||||||
|         Matrix4f inertiaTensor = new Matrix4f().identity().scale(mass * scale.x * scale.x / 6.0f).m33(1); |  | ||||||
|         rVal.putData(EntityDataStrings.PHYSICS_INVERSE_INERTIA_TENSOR, inertiaTensor.invert()); |  | ||||||
|         rVal.putData(EntityDataStrings.DATA_STRING_DRAW, true); |         rVal.putData(EntityDataStrings.DATA_STRING_DRAW, true); | ||||||
|          |          | ||||||
|         return rVal; |         return rVal; | ||||||
| @ -120,10 +108,6 @@ public class CollisionObjUtils { | |||||||
|         rVal.putData(EntityDataStrings.COLLISION_ENTITY_COLLISION_OBJECT, cubeObject); |         rVal.putData(EntityDataStrings.COLLISION_ENTITY_COLLISION_OBJECT, cubeObject); | ||||||
|         rVal.putData(EntityDataStrings.COLLISION_ENTITY_COLLIDABLE, collidable); |         rVal.putData(EntityDataStrings.COLLISION_ENTITY_COLLIDABLE, collidable); | ||||||
|         rVal.putData(EntityDataStrings.PHYSICS_MASS, mass); |         rVal.putData(EntityDataStrings.PHYSICS_MASS, mass); | ||||||
|         //inertia tensor |  | ||||||
|         //https://hepweb.ucsd.edu/ph110b/110b_notes/node26.html |  | ||||||
|         Matrix4f inertiaTensor = new Matrix4f().identity().scale(mass * scale.x * scale.x / 6.0f).m33(1); |  | ||||||
|         rVal.putData(EntityDataStrings.PHYSICS_INVERSE_INERTIA_TENSOR, inertiaTensor.invert()); |  | ||||||
|         rVal.putData(EntityDataStrings.DATA_STRING_DRAW, true); |         rVal.putData(EntityDataStrings.DATA_STRING_DRAW, true); | ||||||
|          |          | ||||||
|         return rVal; |         return rVal; | ||||||
| @ -145,13 +129,6 @@ public class CollisionObjUtils { | |||||||
|         rVal.putData(EntityDataStrings.COLLISION_ENTITY_COLLISION_OBJECT, cubeObject); |         rVal.putData(EntityDataStrings.COLLISION_ENTITY_COLLISION_OBJECT, cubeObject); | ||||||
|         rVal.putData(EntityDataStrings.COLLISION_ENTITY_COLLIDABLE, collidable); |         rVal.putData(EntityDataStrings.COLLISION_ENTITY_COLLIDABLE, collidable); | ||||||
|         rVal.putData(EntityDataStrings.PHYSICS_MASS, mass); |         rVal.putData(EntityDataStrings.PHYSICS_MASS, mass); | ||||||
|         //inertia tensor |  | ||||||
|         //https://scienceworld.wolfram.com/physics/MomentofInertiaCylinder.html |  | ||||||
|         Matrix4f inertiaTensor = new Matrix4f(); |  | ||||||
|         inertiaTensor.m00(mass * scale.y * scale.y / 12.0f + mass * scale.x * scale.x / 4.0f); |  | ||||||
|         inertiaTensor.m11(mass * scale.y * scale.y / 12.0f + mass * scale.x * scale.x / 4.0f); |  | ||||||
|         inertiaTensor.m22(mass * scale.x * scale.x / 2.0f); |  | ||||||
|         rVal.putData(EntityDataStrings.PHYSICS_INVERSE_INERTIA_TENSOR, inertiaTensor.invert()); |  | ||||||
|         rVal.putData(EntityDataStrings.DATA_STRING_DRAW, true); |         rVal.putData(EntityDataStrings.DATA_STRING_DRAW, true); | ||||||
|          |          | ||||||
|         return rVal; |         return rVal; | ||||||
| @ -173,13 +150,6 @@ public class CollisionObjUtils { | |||||||
|         rVal.putData(EntityDataStrings.COLLISION_ENTITY_COLLISION_OBJECT, cubeObject); |         rVal.putData(EntityDataStrings.COLLISION_ENTITY_COLLISION_OBJECT, cubeObject); | ||||||
|         rVal.putData(EntityDataStrings.COLLISION_ENTITY_COLLIDABLE, collidable); |         rVal.putData(EntityDataStrings.COLLISION_ENTITY_COLLIDABLE, collidable); | ||||||
|         rVal.putData(EntityDataStrings.PHYSICS_MASS, mass); |         rVal.putData(EntityDataStrings.PHYSICS_MASS, mass); | ||||||
|         //inertia tensor |  | ||||||
|         //https://scienceworld.wolfram.com/physics/MomentofInertiaCylinder.html |  | ||||||
|         Matrix4f inertiaTensor = new Matrix4f(); |  | ||||||
|         inertiaTensor.m00(mass * scale.y * scale.y / 12.0f + mass * scale.x * scale.x / 4.0f); |  | ||||||
|         inertiaTensor.m11(mass * scale.y * scale.y / 12.0f + mass * scale.x * scale.x / 4.0f); |  | ||||||
|         inertiaTensor.m22(mass * scale.x * scale.x / 2.0f); |  | ||||||
|         rVal.putData(EntityDataStrings.PHYSICS_INVERSE_INERTIA_TENSOR, inertiaTensor.invert()); |  | ||||||
|         rVal.putData(EntityDataStrings.DATA_STRING_DRAW, true); |         rVal.putData(EntityDataStrings.DATA_STRING_DRAW, true); | ||||||
|          |          | ||||||
|         return rVal; |         return rVal; | ||||||
| @ -193,10 +163,6 @@ public class CollisionObjUtils { | |||||||
| 
 | 
 | ||||||
|         float mass = 1.0f; |         float mass = 1.0f; | ||||||
|         parent.putData(EntityDataStrings.PHYSICS_MASS, mass); |         parent.putData(EntityDataStrings.PHYSICS_MASS, mass); | ||||||
|         //inertia tensor |  | ||||||
|         //https://scienceworld.wolfram.com/physics/MomentofInertiaCylinder.html |  | ||||||
|         Matrix4f inertiaTensor = new Matrix4f().zero(); |  | ||||||
|         parent.putData(EntityDataStrings.PHYSICS_INVERSE_INERTIA_TENSOR, inertiaTensor); |  | ||||||
|          |          | ||||||
|         return rVal; |         return rVal; | ||||||
|     } |     } | ||||||
| @ -209,10 +175,6 @@ public class CollisionObjUtils { | |||||||
| 
 | 
 | ||||||
|         float mass = 1.0f; |         float mass = 1.0f; | ||||||
|         parent.putData(EntityDataStrings.PHYSICS_MASS, mass); |         parent.putData(EntityDataStrings.PHYSICS_MASS, mass); | ||||||
|         //inertia tensor |  | ||||||
|         //https://scienceworld.wolfram.com/physics/MomentofInertiaCylinder.html |  | ||||||
|         Matrix4f inertiaTensor = new Matrix4f().zero(); |  | ||||||
|         parent.putData(EntityDataStrings.PHYSICS_INVERSE_INERTIA_TENSOR, inertiaTensor); |  | ||||||
|          |          | ||||||
|         return rVal; |         return rVal; | ||||||
|     } |     } | ||||||
| @ -224,10 +186,6 @@ public class CollisionObjUtils { | |||||||
| 
 | 
 | ||||||
|         float mass = 1.0f; |         float mass = 1.0f; | ||||||
|         parent.putData(EntityDataStrings.PHYSICS_MASS, mass); |         parent.putData(EntityDataStrings.PHYSICS_MASS, mass); | ||||||
|         //inertia tensor |  | ||||||
|         //https://hepweb.ucsd.edu/ph110b/110b_notes/node26.html |  | ||||||
|         Matrix4f inertiaTensor = new Matrix4f().identity().scale(mass * scale.x * scale.x / 6.0f).m33(1); |  | ||||||
|         parent.putData(EntityDataStrings.PHYSICS_INVERSE_INERTIA_TENSOR, inertiaTensor.invert()); |  | ||||||
|          |          | ||||||
|         return rVal; |         return rVal; | ||||||
|     } |     } | ||||||
| @ -240,10 +198,6 @@ public class CollisionObjUtils { | |||||||
| 
 | 
 | ||||||
|         float mass = 1.0f; |         float mass = 1.0f; | ||||||
|         parent.putData(EntityDataStrings.PHYSICS_MASS, mass); |         parent.putData(EntityDataStrings.PHYSICS_MASS, mass); | ||||||
|         //inertia tensor |  | ||||||
|         //https://hepweb.ucsd.edu/ph110b/110b_notes/node26.html |  | ||||||
|         Matrix4f inertiaTensor = new Matrix4f().identity().scale(mass * scale.x * scale.x / 6.0f).m33(1); |  | ||||||
|         parent.putData(EntityDataStrings.PHYSICS_INVERSE_INERTIA_TENSOR, inertiaTensor.invert()); |  | ||||||
|          |          | ||||||
|         return rVal; |         return rVal; | ||||||
|     } |     } | ||||||
| @ -255,13 +209,6 @@ public class CollisionObjUtils { | |||||||
| 
 | 
 | ||||||
|         float mass = 1.0f; |         float mass = 1.0f; | ||||||
|         parent.putData(EntityDataStrings.PHYSICS_MASS, mass); |         parent.putData(EntityDataStrings.PHYSICS_MASS, mass); | ||||||
|         //inertia tensor |  | ||||||
|         //https://scienceworld.wolfram.com/physics/MomentofInertiaCylinder.html |  | ||||||
|         Matrix4f inertiaTensor = new Matrix4f(); |  | ||||||
|         inertiaTensor.m00(mass * scale.y * scale.y / 12.0f + mass * scale.x * scale.x / 4.0f); |  | ||||||
|         inertiaTensor.m11(mass * scale.y * scale.y / 12.0f + mass * scale.x * scale.x / 4.0f); |  | ||||||
|         inertiaTensor.m22(mass * scale.x * scale.x / 2.0f); |  | ||||||
|         parent.putData(EntityDataStrings.PHYSICS_INVERSE_INERTIA_TENSOR, inertiaTensor.invert()); |  | ||||||
|          |          | ||||||
|         return rVal; |         return rVal; | ||||||
|     } |     } | ||||||
| @ -274,13 +221,6 @@ public class CollisionObjUtils { | |||||||
| 
 | 
 | ||||||
|         float mass = 1.0f; |         float mass = 1.0f; | ||||||
|         parent.putData(EntityDataStrings.PHYSICS_MASS, mass); |         parent.putData(EntityDataStrings.PHYSICS_MASS, mass); | ||||||
|         //inertia tensor |  | ||||||
|         //https://scienceworld.wolfram.com/physics/MomentofInertiaCylinder.html |  | ||||||
|         Matrix4f inertiaTensor = new Matrix4f(); |  | ||||||
|         inertiaTensor.m00(mass * scale.y * scale.y / 12.0f + mass * scale.x * scale.x / 4.0f); |  | ||||||
|         inertiaTensor.m11(mass * scale.y * scale.y / 12.0f + mass * scale.x * scale.x / 4.0f); |  | ||||||
|         inertiaTensor.m22(mass * scale.x * scale.x / 2.0f); |  | ||||||
|         parent.putData(EntityDataStrings.PHYSICS_INVERSE_INERTIA_TENSOR, inertiaTensor.invert()); |  | ||||||
|          |          | ||||||
|         return rVal; |         return rVal; | ||||||
|     } |     } | ||||||
| @ -306,13 +246,6 @@ public class CollisionObjUtils { | |||||||
|         entity.putData(EntityDataStrings.COLLISION_ENTITY_COLLISION_OBJECT, collisionObject); |         entity.putData(EntityDataStrings.COLLISION_ENTITY_COLLISION_OBJECT, collisionObject); | ||||||
|         entity.putData(EntityDataStrings.COLLISION_ENTITY_COLLIDABLE, collidable); |         entity.putData(EntityDataStrings.COLLISION_ENTITY_COLLIDABLE, collidable); | ||||||
|         entity.putData(EntityDataStrings.PHYSICS_MASS, mass); |         entity.putData(EntityDataStrings.PHYSICS_MASS, mass); | ||||||
|         //inertia tensor |  | ||||||
|         //https://scienceworld.wolfram.com/physics/MomentofInertiaCylinder.html |  | ||||||
|         Matrix4f inertiaTensor = new Matrix4f(); |  | ||||||
|         inertiaTensor.m00(mass * scale.y * scale.y / 12.0f + mass * scale.x * scale.x / 4.0f); |  | ||||||
|         inertiaTensor.m11(mass * scale.y * scale.y / 12.0f + mass * scale.x * scale.x / 4.0f); |  | ||||||
|         inertiaTensor.m22(mass * scale.x * scale.x / 2.0f); |  | ||||||
|         entity.putData(EntityDataStrings.PHYSICS_INVERSE_INERTIA_TENSOR, inertiaTensor.invert()); |  | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
| @ -337,13 +270,6 @@ public class CollisionObjUtils { | |||||||
|         entity.putData(EntityDataStrings.COLLISION_ENTITY_COLLISION_OBJECT, collisionObject); |         entity.putData(EntityDataStrings.COLLISION_ENTITY_COLLISION_OBJECT, collisionObject); | ||||||
|         entity.putData(EntityDataStrings.COLLISION_ENTITY_COLLIDABLE, collidable); |         entity.putData(EntityDataStrings.COLLISION_ENTITY_COLLIDABLE, collidable); | ||||||
|         entity.putData(EntityDataStrings.PHYSICS_MASS, mass); |         entity.putData(EntityDataStrings.PHYSICS_MASS, mass); | ||||||
|         //inertia tensor |  | ||||||
|         //https://scienceworld.wolfram.com/physics/MomentofInertiaCylinder.html |  | ||||||
|         Matrix4f inertiaTensor = new Matrix4f(); |  | ||||||
|         inertiaTensor.m00(mass * scale.y * scale.y / 12.0f + mass * scale.x * scale.x / 4.0f); |  | ||||||
|         inertiaTensor.m11(mass * scale.y * scale.y / 12.0f + mass * scale.x * scale.x / 4.0f); |  | ||||||
|         inertiaTensor.m22(mass * scale.x * scale.x / 2.0f); |  | ||||||
|         entity.putData(EntityDataStrings.PHYSICS_INVERSE_INERTIA_TENSOR, inertiaTensor.invert()); |  | ||||||
|     } |     } | ||||||
|      |      | ||||||
|     public static DBody getCollisionBody(Entity e){ |     public static DBody getCollisionBody(Entity e){ | ||||||
| @ -377,9 +303,5 @@ public class CollisionObjUtils { | |||||||
|         return (float)e.getData(EntityDataStrings.PHYSICS_MASS); |         return (float)e.getData(EntityDataStrings.PHYSICS_MASS); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     public static Matrix4f getInverseInertiaTensor(Entity e){ |  | ||||||
|         return (Matrix4f)e.getData(EntityDataStrings.PHYSICS_INVERSE_INERTIA_TENSOR); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|      |      | ||||||
| } | } | ||||||
|  | |||||||
| @ -18,7 +18,7 @@ import electrosphere.entity.EntityCreationUtils; | |||||||
| import electrosphere.entity.EntityDataStrings; | import electrosphere.entity.EntityDataStrings; | ||||||
| import electrosphere.entity.EntityTags; | import electrosphere.entity.EntityTags; | ||||||
| import electrosphere.entity.EntityUtils; | import electrosphere.entity.EntityUtils; | ||||||
| import electrosphere.entity.state.BehaviorTree; | import electrosphere.entity.btree.BehaviorTree; | ||||||
| import electrosphere.entity.state.attack.AttackTree; | import electrosphere.entity.state.attack.AttackTree; | ||||||
| import electrosphere.entity.state.attack.ServerAttackTree; | import electrosphere.entity.state.attack.ServerAttackTree; | ||||||
| import electrosphere.entity.state.attack.ShooterTree; | import electrosphere.entity.state.attack.ShooterTree; | ||||||
| @ -158,7 +158,7 @@ public class CreatureUtils { | |||||||
|                     } |                     } | ||||||
|                     //round out end of move system |                     //round out end of move system | ||||||
|                     rVal.putData(EntityDataStrings.CLIENT_MOVEMENT_BT, moveTree); |                     rVal.putData(EntityDataStrings.CLIENT_MOVEMENT_BT, moveTree); | ||||||
|                     CreatureUtils.setFacingVector(rVal, new Vector3d(0,0,0)); |                     CreatureUtils.setFacingVector(rVal, new Vector3d(0,0,1)); | ||||||
|                     rVal.putData(EntityDataStrings.DATA_STRING_MAX_NATURAL_VELOCITY, groundMovementSystem.getMaxVelocity()); |                     rVal.putData(EntityDataStrings.DATA_STRING_MAX_NATURAL_VELOCITY, groundMovementSystem.getMaxVelocity()); | ||||||
|                     rVal.putData(EntityDataStrings.DATA_STRING_ACCELERATION, groundMovementSystem.getAcceleration()); |                     rVal.putData(EntityDataStrings.DATA_STRING_ACCELERATION, groundMovementSystem.getAcceleration()); | ||||||
|                     rVal.putData(EntityDataStrings.DATA_STRING_VELOCITY, 0f); |                     rVal.putData(EntityDataStrings.DATA_STRING_VELOCITY, 0f); | ||||||
| @ -216,7 +216,7 @@ public class CreatureUtils { | |||||||
|                     airplaneMovementTree.setMaxRotationSpeed(airplaneMovementSystem.getMaxRotationSpeed()); |                     airplaneMovementTree.setMaxRotationSpeed(airplaneMovementSystem.getMaxRotationSpeed()); | ||||||
|                     //register misc stuff |                     //register misc stuff | ||||||
|                     rVal.putData(EntityDataStrings.CLIENT_MOVEMENT_BT, airplaneMovementTree); |                     rVal.putData(EntityDataStrings.CLIENT_MOVEMENT_BT, airplaneMovementTree); | ||||||
|                     CreatureUtils.setFacingVector(rVal, new Vector3d(0,0,0)); |                     CreatureUtils.setFacingVector(rVal, new Vector3d(0,0,1)); | ||||||
|                     Globals.clientScene.registerBehaviorTree(airplaneMovementTree); |                     Globals.clientScene.registerBehaviorTree(airplaneMovementTree); | ||||||
|                     Globals.clientScene.registerEntityToTag(rVal, EntityTags.MOVEABLE); |                     Globals.clientScene.registerEntityToTag(rVal, EntityTags.MOVEABLE); | ||||||
|                 } break; |                 } break; | ||||||
| @ -454,7 +454,7 @@ public class CreatureUtils { | |||||||
|                     } |                     } | ||||||
|                     //round out end of move system |                     //round out end of move system | ||||||
|                     rVal.putData(EntityDataStrings.SERVER_MOVEMENT_BT, moveTree); |                     rVal.putData(EntityDataStrings.SERVER_MOVEMENT_BT, moveTree); | ||||||
|                     CreatureUtils.setFacingVector(rVal, new Vector3d(0,0,0)); |                     CreatureUtils.setFacingVector(rVal, new Vector3d(0,0,1)); | ||||||
|                     rVal.putData(EntityDataStrings.DATA_STRING_MAX_NATURAL_VELOCITY, groundMovementSystem.getMaxVelocity()); |                     rVal.putData(EntityDataStrings.DATA_STRING_MAX_NATURAL_VELOCITY, groundMovementSystem.getMaxVelocity()); | ||||||
|                     rVal.putData(EntityDataStrings.DATA_STRING_ACCELERATION, groundMovementSystem.getAcceleration()); |                     rVal.putData(EntityDataStrings.DATA_STRING_ACCELERATION, groundMovementSystem.getAcceleration()); | ||||||
|                     rVal.putData(EntityDataStrings.DATA_STRING_VELOCITY, 0f); |                     rVal.putData(EntityDataStrings.DATA_STRING_VELOCITY, 0f); | ||||||
| @ -512,7 +512,7 @@ public class CreatureUtils { | |||||||
|                     airplaneMovementTree.setMaxRotationSpeed(airplaneMovementSystem.getMaxRotationSpeed()); |                     airplaneMovementTree.setMaxRotationSpeed(airplaneMovementSystem.getMaxRotationSpeed()); | ||||||
|                     //register misc stuff |                     //register misc stuff | ||||||
|                     rVal.putData(EntityDataStrings.SERVER_MOVEMENT_BT, airplaneMovementTree); |                     rVal.putData(EntityDataStrings.SERVER_MOVEMENT_BT, airplaneMovementTree); | ||||||
|                     CreatureUtils.setFacingVector(rVal, new Vector3d(0,0,0)); |                     CreatureUtils.setFacingVector(rVal, new Vector3d(0,0,1)); | ||||||
|                     ServerBehaviorTreeUtils.attachBTreeToEntity(rVal, airplaneMovementTree); |                     ServerBehaviorTreeUtils.attachBTreeToEntity(rVal, airplaneMovementTree); | ||||||
|                     ServerEntityTagUtils.attachTagToEntity(rVal, EntityTags.MOVEABLE); |                     ServerEntityTagUtils.attachTagToEntity(rVal, EntityTags.MOVEABLE); | ||||||
|                 } break; |                 } break; | ||||||
|  | |||||||
| @ -196,9 +196,6 @@ public class ItemUtils { | |||||||
|         if(item.containsKey(EntityDataStrings.PHYSICS_COLLISION_BODY)){ |         if(item.containsKey(EntityDataStrings.PHYSICS_COLLISION_BODY)){ | ||||||
|             item.removeData(EntityDataStrings.PHYSICS_COLLISION_BODY); |             item.removeData(EntityDataStrings.PHYSICS_COLLISION_BODY); | ||||||
|         } |         } | ||||||
|         if(item.containsKey(EntityDataStrings.PHYSICS_COLLISION_BODY_OFFSET)){ |  | ||||||
|             item.removeData(EntityDataStrings.PHYSICS_COLLISION_BODY_OFFSET); |  | ||||||
|         } |  | ||||||
|         if(item.containsKey(EntityDataStrings.PHYSICS_MODEL_TEMPLATE)){ |         if(item.containsKey(EntityDataStrings.PHYSICS_MODEL_TEMPLATE)){ | ||||||
|             item.removeData(EntityDataStrings.PHYSICS_MODEL_TEMPLATE); |             item.removeData(EntityDataStrings.PHYSICS_MODEL_TEMPLATE); | ||||||
|         } |         } | ||||||
|  | |||||||
| @ -16,7 +16,7 @@ import electrosphere.entity.EntityCreationUtils; | |||||||
| import electrosphere.entity.EntityDataStrings; | import electrosphere.entity.EntityDataStrings; | ||||||
| import electrosphere.entity.EntityTags; | import electrosphere.entity.EntityTags; | ||||||
| import electrosphere.entity.EntityUtils; | import electrosphere.entity.EntityUtils; | ||||||
| import electrosphere.entity.state.BehaviorTree; | import electrosphere.entity.btree.BehaviorTree; | ||||||
| import electrosphere.entity.state.collidable.ClientCollidableTree; | import electrosphere.entity.state.collidable.ClientCollidableTree; | ||||||
| import electrosphere.entity.state.collidable.ServerCollidableTree; | import electrosphere.entity.state.collidable.ServerCollidableTree; | ||||||
| import electrosphere.entity.state.gravity.ClientGravityTree; | import electrosphere.entity.state.gravity.ClientGravityTree; | ||||||
|  | |||||||
| @ -15,10 +15,12 @@ import org.joml.Vector3f; | |||||||
| import org.joml.Vector4d; | import org.joml.Vector4d; | ||||||
| import org.joml.Vector4f; | import org.joml.Vector4f; | ||||||
| import org.ode4j.ode.DBody; | import org.ode4j.ode.DBody; | ||||||
|  | import org.ode4j.ode.DCylinder; | ||||||
| 
 | 
 | ||||||
| import electrosphere.audio.VirtualAudioSource; | import electrosphere.audio.VirtualAudioSource; | ||||||
| import electrosphere.audio.VirtualAudioSourceManager.VirtualAudioSourceType; | import electrosphere.audio.VirtualAudioSourceManager.VirtualAudioSourceType; | ||||||
| import electrosphere.collision.CollisionBodyCreation; | import electrosphere.collision.CollisionBodyCreation; | ||||||
|  | import electrosphere.collision.PhysicsEntityUtils; | ||||||
| import electrosphere.collision.PhysicsUtils; | import electrosphere.collision.PhysicsUtils; | ||||||
| import electrosphere.collision.collidable.Collidable; | import electrosphere.collision.collidable.Collidable; | ||||||
| import electrosphere.engine.Globals; | import electrosphere.engine.Globals; | ||||||
| @ -28,7 +30,7 @@ import electrosphere.entity.EntityCreationUtils; | |||||||
| import electrosphere.entity.EntityDataStrings; | import electrosphere.entity.EntityDataStrings; | ||||||
| import electrosphere.entity.EntityTags; | import electrosphere.entity.EntityTags; | ||||||
| import electrosphere.entity.EntityUtils; | import electrosphere.entity.EntityUtils; | ||||||
| import electrosphere.entity.state.BehaviorTree; | import electrosphere.entity.btree.BehaviorTree; | ||||||
| import electrosphere.entity.types.attach.AttachUtils; | import electrosphere.entity.types.attach.AttachUtils; | ||||||
| import electrosphere.entity.types.instance.InstanceTemplate; | import electrosphere.entity.types.instance.InstanceTemplate; | ||||||
| import electrosphere.entity.types.instance.InstancedEntityUtils; | import electrosphere.entity.types.instance.InstancedEntityUtils; | ||||||
| @ -124,9 +126,17 @@ public class ProceduralTree { | |||||||
|             treeModel.getPhysicsBody().getDimension2(), |             treeModel.getPhysicsBody().getDimension2(), | ||||||
|             Collidable.TYPE_STATIC_BIT |             Collidable.TYPE_STATIC_BIT | ||||||
|         ); |         ); | ||||||
|  |         DCylinder cylinder = (DCylinder)rigidBody.getGeomIterator().next(); | ||||||
|  |         cylinder.setOffsetPosition(0,treeModel.getPhysicsBody().getOffsetY(),0); | ||||||
|  |         CollisionBodyCreation.setKinematic(Globals.clientSceneWrapper.getCollisionEngine(), rigidBody); | ||||||
|         Collidable collidable = new Collidable(trunkChild, Collidable.TYPE_OBJECT); |         Collidable collidable = new Collidable(trunkChild, Collidable.TYPE_OBJECT); | ||||||
|         trunkChild.putData(EntityDataStrings.PHYSICS_COLLISION_BODY, rigidBody); |         trunkChild.putData(EntityDataStrings.PHYSICS_COLLISION_BODY, rigidBody); | ||||||
|         trunkChild.putData(EntityDataStrings.PHYSICS_COLLISION_BODY_OFFSET, new Vector3f(0,treeModel.getPhysicsBody().getOffsetY(),0)); |         Matrix4d offsetTransform = new Matrix4d().translationRotateScale( | ||||||
|  |             0,treeModel.getPhysicsBody().getOffsetY(),0, //translate | ||||||
|  |             0,0,0,1, //rotate | ||||||
|  |             1, 1, 1 //scale | ||||||
|  |         ); | ||||||
|  |         trunkChild.putData(EntityDataStrings.PHYSICS_COLLISION_BODY_TRANSFORM, offsetTransform); | ||||||
|         trunkChild.putData(EntityDataStrings.PHYSICS_MODEL_TEMPLATE, treeModel.getPhysicsBody()); |         trunkChild.putData(EntityDataStrings.PHYSICS_MODEL_TEMPLATE, treeModel.getPhysicsBody()); | ||||||
|         trunkChild.putData(EntityDataStrings.PHYSICS_COLLIDABLE, collidable); |         trunkChild.putData(EntityDataStrings.PHYSICS_COLLIDABLE, collidable); | ||||||
|         trunkChild.putData(EntityDataStrings.PHYSICS_MASS, TREE_MASS); |         trunkChild.putData(EntityDataStrings.PHYSICS_MASS, TREE_MASS); | ||||||
| @ -383,9 +393,17 @@ public class ProceduralTree { | |||||||
|             treeModel.getPhysicsBody().getDimension2(), |             treeModel.getPhysicsBody().getDimension2(), | ||||||
|             Collidable.TYPE_STATIC_BIT |             Collidable.TYPE_STATIC_BIT | ||||||
|         ); |         ); | ||||||
|  |         DCylinder cylinder = (DCylinder)rigidBody.getGeomIterator().next(); | ||||||
|  |         cylinder.setOffsetPosition(0,treeModel.getPhysicsBody().getOffsetY(),0); | ||||||
|  |         CollisionBodyCreation.setKinematic(realm.getCollisionEngine(), rigidBody); | ||||||
|         Collidable collidable = new Collidable(trunkChild, Collidable.TYPE_FOLIAGE_STATIC); |         Collidable collidable = new Collidable(trunkChild, Collidable.TYPE_FOLIAGE_STATIC); | ||||||
|         trunkChild.putData(EntityDataStrings.PHYSICS_COLLISION_BODY, rigidBody); |         trunkChild.putData(EntityDataStrings.PHYSICS_COLLISION_BODY, rigidBody); | ||||||
|         trunkChild.putData(EntityDataStrings.PHYSICS_COLLISION_BODY_OFFSET, new Vector3f(0,treeModel.getPhysicsBody().getOffsetY(),0)); |         Matrix4d offsetTransform = new Matrix4d().translationRotateScale( | ||||||
|  |             0,treeModel.getPhysicsBody().getOffsetY(),0, //translate | ||||||
|  |             0,0,0,1, //rotate | ||||||
|  |             1, 1, 1 //scale | ||||||
|  |         ); | ||||||
|  |         trunkChild.putData(EntityDataStrings.PHYSICS_COLLISION_BODY_TRANSFORM, offsetTransform); | ||||||
|         trunkChild.putData(EntityDataStrings.PHYSICS_MODEL_TEMPLATE, treeModel.getPhysicsBody()); |         trunkChild.putData(EntityDataStrings.PHYSICS_MODEL_TEMPLATE, treeModel.getPhysicsBody()); | ||||||
|         trunkChild.putData(EntityDataStrings.PHYSICS_COLLIDABLE, collidable); |         trunkChild.putData(EntityDataStrings.PHYSICS_COLLIDABLE, collidable); | ||||||
|         trunkChild.putData(EntityDataStrings.PHYSICS_MASS, TREE_MASS); |         trunkChild.putData(EntityDataStrings.PHYSICS_MASS, TREE_MASS); | ||||||
|  | |||||||
| @ -3,7 +3,11 @@ package electrosphere.menu; | |||||||
| import java.util.HashMap; | import java.util.HashMap; | ||||||
| import java.util.Map; | import java.util.Map; | ||||||
| 
 | 
 | ||||||
|  | import org.ode4j.ode.DBody; | ||||||
|  | 
 | ||||||
| import electrosphere.audio.VirtualAudioSource; | import electrosphere.audio.VirtualAudioSource; | ||||||
|  | import electrosphere.collision.PhysicsEntityUtils; | ||||||
|  | import electrosphere.collision.PhysicsUtils; | ||||||
| import electrosphere.controls.ControlHandler.ControlsState; | import electrosphere.controls.ControlHandler.ControlsState; | ||||||
| import electrosphere.engine.Globals; | import electrosphere.engine.Globals; | ||||||
| import electrosphere.entity.EntityUtils; | import electrosphere.entity.EntityUtils; | ||||||
| @ -166,6 +170,13 @@ public class ImGuiWindowMacros { | |||||||
|                 ImGui.text("Player Entity Details"); |                 ImGui.text("Player Entity Details"); | ||||||
|                 if(Globals.playerEntity != null){ |                 if(Globals.playerEntity != null){ | ||||||
|                     ImGui.text("Position: " + EntityUtils.getPosition(Globals.playerEntity)); |                     ImGui.text("Position: " + EntityUtils.getPosition(Globals.playerEntity)); | ||||||
|  |                     DBody body = PhysicsEntityUtils.getDBody(Globals.playerEntity); | ||||||
|  |                     if(body != null){ | ||||||
|  |                         ImGui.text("Velocity: " + body.getLinearVel()); | ||||||
|  |                         ImGui.text("Force: " + body.getForce()); | ||||||
|  |                         ImGui.text("Angular Velocity: " + body.getAngularVel()); | ||||||
|  |                         ImGui.text("Torque: " + body.getTorque()); | ||||||
|  |                     } | ||||||
|                 } |                 } | ||||||
|                 if(ImGui.button("Toggle Player Camera Lock")){ |                 if(ImGui.button("Toggle Player Camera Lock")){ | ||||||
|                     Globals.cameraHandler.setTrackPlayerEntity(!Globals.cameraHandler.getTrackPlayerEntity()); |                     Globals.cameraHandler.setTrackPlayerEntity(!Globals.cameraHandler.getTrackPlayerEntity()); | ||||||
|  | |||||||
| @ -45,7 +45,7 @@ public class EntityProtocol { | |||||||
|                 LoggerInterface.loggerNetworking.DEBUG("Spawn Creature " + message.getentityID() + " at " + message.getpositionX() + " " + message.getpositionY() + " " + message.getpositionZ()); |                 LoggerInterface.loggerNetworking.DEBUG("Spawn Creature " + message.getentityID() + " at " + message.getpositionX() + " " + message.getpositionY() + " " + message.getpositionZ()); | ||||||
|                 CreatureTemplate template = Utilities.deserialize(message.getcreatureTemplate(), CreatureTemplate.class); |                 CreatureTemplate template = Utilities.deserialize(message.getcreatureTemplate(), CreatureTemplate.class); | ||||||
|                 newlySpawnedEntity = CreatureUtils.clientSpawnBasicCreature(template.getCreatureType(),template); |                 newlySpawnedEntity = CreatureUtils.clientSpawnBasicCreature(template.getCreatureType(),template); | ||||||
|                 EntityUtils.getPosition(newlySpawnedEntity).set(message.getpositionX(),message.getpositionY(),message.getpositionZ()); |                 ClientEntityUtils.initiallyPositionEntity(newlySpawnedEntity, new Vector3d(message.getpositionX(),message.getpositionY(),message.getpositionZ())); | ||||||
|                 Globals.clientSceneWrapper.mapIdToId(newlySpawnedEntity.getId(), message.getentityID()); |                 Globals.clientSceneWrapper.mapIdToId(newlySpawnedEntity.getId(), message.getentityID()); | ||||||
|                 break; |                 break; | ||||||
|             case SPAWNITEM: |             case SPAWNITEM: | ||||||
|  | |||||||
| @ -38,6 +38,7 @@ public class ClientSynchronizationManager { | |||||||
|     public void processMessages(){ |     public void processMessages(){ | ||||||
|         List<SynchronizationMessage> messagesToClear = new LinkedList<SynchronizationMessage>(); |         List<SynchronizationMessage> messagesToClear = new LinkedList<SynchronizationMessage>(); | ||||||
|         for(SynchronizationMessage message : messages){ |         for(SynchronizationMessage message : messages){ | ||||||
|  |             if(Globals.clientSceneWrapper.containsServerId(message.getentityId())){ | ||||||
|                 messagesToClear.add(message); |                 messagesToClear.add(message); | ||||||
|                 switch(message.getMessageSubtype()){ |                 switch(message.getMessageSubtype()){ | ||||||
|                     case UPDATECLIENTSTATE:{ |                     case UPDATECLIENTSTATE:{ | ||||||
| @ -57,6 +58,7 @@ public class ClientSynchronizationManager { | |||||||
|                     } break; |                     } break; | ||||||
|                 } |                 } | ||||||
|             } |             } | ||||||
|  |         } | ||||||
|         for(SynchronizationMessage message : messagesToClear){ |         for(SynchronizationMessage message : messagesToClear){ | ||||||
|             messages.remove(message); |             messages.remove(message); | ||||||
|         } |         } | ||||||
|  | |||||||
| @ -158,6 +158,7 @@ public class Realm { | |||||||
|     protected void simulate(){ |     protected void simulate(){ | ||||||
|         //simulate bullet physics engine step |         //simulate bullet physics engine step | ||||||
|         collisionEngine.simulatePhysics((float)Globals.timekeeper.getSimFrameTime()); |         collisionEngine.simulatePhysics((float)Globals.timekeeper.getSimFrameTime()); | ||||||
|  |         collisionEngine.updateDynamicObjectTransforms(); | ||||||
|         //main simulation |         //main simulation | ||||||
|         dataCellManager.simulate(); |         dataCellManager.simulate(); | ||||||
|         //data cell manager update misc variables (player positions, unload not-in-use cells) |         //data cell manager update misc variables (player positions, unload not-in-use cells) | ||||||
|  | |||||||
| @ -2,6 +2,7 @@ package electrosphere.server.datacell; | |||||||
| 
 | 
 | ||||||
| import electrosphere.engine.Globals; | import electrosphere.engine.Globals; | ||||||
| import electrosphere.entity.Entity; | import electrosphere.entity.Entity; | ||||||
|  | import electrosphere.entity.EntityUtils; | ||||||
| import electrosphere.entity.Scene; | import electrosphere.entity.Scene; | ||||||
| import electrosphere.entity.types.creature.CreatureUtils; | import electrosphere.entity.types.creature.CreatureUtils; | ||||||
| import electrosphere.entity.types.foliage.FoliageUtils; | import electrosphere.entity.types.foliage.FoliageUtils; | ||||||
|  | |||||||
| @ -6,7 +6,7 @@ import java.util.Map; | |||||||
| import java.util.Set; | import java.util.Set; | ||||||
| 
 | 
 | ||||||
| import electrosphere.entity.Entity; | import electrosphere.entity.Entity; | ||||||
| import electrosphere.entity.state.BehaviorTree; | import electrosphere.entity.btree.BehaviorTree; | ||||||
| import electrosphere.server.datacell.ServerDataCell; | import electrosphere.server.datacell.ServerDataCell; | ||||||
| 
 | 
 | ||||||
| /** | /** | ||||||
|  | |||||||
| @ -8,8 +8,8 @@ import electrosphere.entity.Entity; | |||||||
| import electrosphere.entity.EntityDataStrings; | import electrosphere.entity.EntityDataStrings; | ||||||
| import electrosphere.entity.EntityTags; | import electrosphere.entity.EntityTags; | ||||||
| import electrosphere.entity.EntityUtils; | import electrosphere.entity.EntityUtils; | ||||||
|  | import electrosphere.entity.btree.BehaviorTree; | ||||||
| import electrosphere.entity.scene.EntityDescriptor; | import electrosphere.entity.scene.EntityDescriptor; | ||||||
| import electrosphere.entity.state.BehaviorTree; |  | ||||||
| import electrosphere.entity.state.ParticleTree; | import electrosphere.entity.state.ParticleTree; | ||||||
| import electrosphere.entity.state.attack.AttackTree; | import electrosphere.entity.state.attack.AttackTree; | ||||||
| import electrosphere.entity.state.collidable.ClientCollidableTree; | import electrosphere.entity.state.collidable.ClientCollidableTree; | ||||||
| @ -47,10 +47,6 @@ public class MicroSimulation { | |||||||
|      |      | ||||||
|     public void simulate(ServerDataCell dataCell, HitboxManager hitboxManager){ |     public void simulate(ServerDataCell dataCell, HitboxManager hitboxManager){ | ||||||
|         if(dataCell.isReady()){ |         if(dataCell.isReady()){ | ||||||
|             //update dynamic entity positions calculated by bullet |  | ||||||
|     //        Globals.collisionEngine.updateDynamicObjectTransforms(); |  | ||||||
|             //list dynamic object positions |  | ||||||
|     //        Globals.collisionEngine.listBodyPositions(); |  | ||||||
|             //simulate ai |             //simulate ai | ||||||
|             Globals.aiManager.simulate(); |             Globals.aiManager.simulate(); | ||||||
|             //update actor animations |             //update actor animations | ||||||
| @ -84,11 +80,6 @@ public class MicroSimulation { | |||||||
|                     HitboxUtils.serverCollideEntities(currentHitbox); |                     HitboxUtils.serverCollideEntities(currentHitbox); | ||||||
|                 } |                 } | ||||||
|             } |             } | ||||||
|             //tally collidables and offset position accordingly |  | ||||||
|             // for(Entity currentCollidable : Globals.entityManager.getEntitiesWithTag(EntityTags.COLLIDABLE)){ |  | ||||||
|             //     CollidableTree tree = CollidableTree.getCollidableTree(currentCollidable); |  | ||||||
|             //     tree.simulate(Main.deltaFrames); |  | ||||||
|             // } |  | ||||||
|             //simulate behavior trees |             //simulate behavior trees | ||||||
|             dataCell.getScene().simulateBehaviorTrees((float)Globals.timekeeper.getSimFrameTime()); |             dataCell.getScene().simulateBehaviorTrees((float)Globals.timekeeper.getSimFrameTime()); | ||||||
|             //sum collidable impulses |             //sum collidable impulses | ||||||
|  | |||||||
| @ -235,7 +235,7 @@ public class ServerTerrainManager { | |||||||
|             returnedChunk = chunkCache.get(key); |             returnedChunk = chunkCache.get(key); | ||||||
|             return returnedChunk; |             return returnedChunk; | ||||||
|         } else { |         } else { | ||||||
|             if(chunkCacheContents.size() > cacheSize){ |             if(chunkCacheContents.size() >= cacheSize){ | ||||||
|                 String oldChunk = chunkCacheContents.remove(chunkCacheContents.size() - 1); |                 String oldChunk = chunkCacheContents.remove(chunkCacheContents.size() - 1); | ||||||
|                 chunkCache.remove(oldChunk); |                 chunkCache.remove(oldChunk); | ||||||
|             } |             } | ||||||
| @ -261,8 +261,10 @@ public class ServerTerrainManager { | |||||||
|      * @param position The position to save |      * @param position The position to save | ||||||
|      */ |      */ | ||||||
|     public void savePositionToDisk(Vector3i position){ |     public void savePositionToDisk(Vector3i position){ | ||||||
|  |         if(chunkDiskMap != null){ | ||||||
|             chunkDiskMap.saveToDisk(getChunk(position.x, position.y, position.z)); |             chunkDiskMap.saveToDisk(getChunk(position.x, position.y, position.z)); | ||||||
|         } |         } | ||||||
|  |     } | ||||||
|      |      | ||||||
|     /** |     /** | ||||||
|      * Applies a deform to terrain at a given location |      * Applies a deform to terrain at a given location | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user