Browse Source

improved kamera rotation

Kolja Strohm 2 năm trước cách đây
mục cha
commit
8f8c2dea2f

+ 1 - 0
FactoryCraft/Chunk.h

@@ -14,6 +14,7 @@ class Chunk : public Framework::Model3DCollection
 {
 private:
 	Framework::Punkt location;
+	// TODO: use native array for bedder performance?
 	Framework::RCArray<Block> blocks;
 	bool isLoading;
 	Framework::Critical cs;

+ 6 - 0
FactoryCraft/CraftingGrid.cpp

@@ -145,6 +145,8 @@ void CraftingGridView::api(char* message)
 	}
 	case 1: // set count of items
 	{
+		if (!slots)
+			return;
 		int id = *(int*)(message + 1);
 		int count = *(int*)(message + 5);
 		for (int i = 0; i < slots->getEintragAnzahl(); i++)
@@ -169,6 +171,8 @@ void CraftingGridView::api(char* message)
 	}
 	case 2: // add new stack
 	{
+		if (!slots)
+			return;
 		int id = *(int*)(message + 1);
 		for (int i = 0; i < slots->getEintragAnzahl(); i++)
 		{
@@ -274,6 +278,8 @@ void CraftingGridView::render(Bild& rObj)
 
 void CraftingGridView::doMausEreignis(MausEreignis& me, bool userRet)
 {
+	if (!slots)
+		return;
 	craft->doPublicMausEreignis(me);
 	DragController<InventoryDragSource, int>* controller = ((Game*)(Menu*)menuRegister->get("game"))->zInventoryDragController();
 	int x = 0;

+ 1 - 0
FactoryCraft/Dimension.cpp

@@ -103,6 +103,7 @@ Block* Dimension::getBlock(Vec3<int> location)
 void Dimension::addEntity(Entity* entity)
 {
 	entities->add(entity);
+	currentGame->setVisibility(entity, 1);
 }
 
 void Dimension::setChunk(Chunk* chunk, Punkt center, World* zWorld)

+ 6 - 0
FactoryCraft/InventoryView.cpp

@@ -148,6 +148,8 @@ void InventoryView::api(char* message)
 	}
 	case 1: // set count of items
 	{
+		if (!slots)
+			return;
 		int id = *(int*)(message + 1);
 		int count = *(int*)(message + 5);
 		for (int i = 0; i < slots->getEintragAnzahl(); i++)
@@ -172,6 +174,8 @@ void InventoryView::api(char* message)
 	}
 	case 2: // add new stack
 	{
+		if (!slots)
+			return;
 		int id = *(int*)(message + 1);
 		for (int i = 0; i < slots->getEintragAnzahl(); i++)
 		{
@@ -225,6 +229,8 @@ void InventoryView::render(Bild& rObj)
 
 void InventoryView::doMausEreignis(MausEreignis& me, bool userRet)
 {
+	if (!slots)
+		return;
 	DragController<InventoryDragSource, int>* controller = ((Game*)(Menu*)menuRegister->get("game"))->zInventoryDragController();
 	int x = 0;
 	int y = 0;

+ 32 - 24
FactoryCraft/PlayerKam.cpp

@@ -13,6 +13,8 @@ PlayerKam::PlayerKam(Framework::Bildschirm3D* zScreen)
 	setStyle(Kam3D::Style::Tick | Kam3D::Style::Movable | Kam3D::Style::Rotatable);
 	setRotation({ (float)PI / 2.f, 0, 0 });
 	entityId = -1;
+	transmittedDirection = getWorldDirection(getScreenPos() + getScreenSize() / 2);
+	timeSiceTransmision = 0;
 }
 
 void PlayerKam::setDirection(Framework::Vec3<float> direction)
@@ -128,7 +130,7 @@ void PlayerKam::doTastaturEreignis(Framework::TastaturEreignis& te)
 			bool oldControl = kameraControll;
 			kameraControll = 0;
 			setShowCursor(true);
-			if(!oldControl)
+			if (!oldControl)
 				((Game*)(Menu*)menuRegister->get("game"))->closeCurrentDialog();
 		}
 		if (te.taste == T_Tab)
@@ -151,34 +153,12 @@ void PlayerKam::doMausEreignis(Framework::MausEreignis& me)
 		if (!kameraControll)
 		{
 			if (me.id == ME_PLinks)
-			{
-				lastMousePos = { me.originalX, me.originalY };
-				kameraControll = 1;
-			}
+				setControlEnabled(1);
 		}
 		else
 		{
 			if (kameraControll)
 			{
-				if (me.id == ME_Bewegung)
-				{
-					int yDir = lastMousePos.y - me.originalY;
-					int xDir = lastMousePos.x - me.originalX;
-					setRotation({ min(max(getRotation().x - yDir * 0.005f, 0.1f), 2.5f), getRotation().y, getRotation().z - xDir * 0.005f });
-					if (getRotation().z > 2 * PI)
-						setRotation({ getRotation().x, getRotation().y, getRotation().z - 2.f * (float)PI });
-					if (getRotation().z < -2 * PI)
-						setRotation({ getRotation().x, getRotation().y, getRotation().z + 2.f * (float)PI });
-					Vec3<float> direction = getWorldDirection(getScreenPos() + getScreenSize() / 2);
-					char action[13];
-					action[0] = 2;
-					*(float*)(action + 1) = direction.x;
-					*(float*)(action + 5) = direction.y;
-					*(float*)(action + 9) = direction.z;
-					network->zFactoryClient()->sendPlayerAction(action, 13);
-					SetCursorPos(lastMousePos.x + window->getPosition().x, lastMousePos.y + window->getPosition().y);
-					setShowCursor(false);
-				}
 				if (me.id == ME_PLinks)
 				{
 					char action[2] = { 1, 8 };
@@ -229,6 +209,30 @@ bool PlayerKam::tick(double time)
 			((Game*)(Menu*)menuRegister->get("game"))->updatePosition(entity->getPos(), 0, { 0, 0, 0 });
 		}
 	}
+	if (kameraControll)
+	{
+		Punkt dir = window->getGröße() / 2 - (getMausPos() - window->getPosition());
+		setRotation({ min(max(getRotation().x - dir.y * (float)time * 0.2f, 0.1f), 2.5f), getRotation().y, getRotation().z - dir.x * (float)time * 0.2f });
+		if (getRotation().z > 2 * PI)
+			setRotation({ getRotation().x, getRotation().y, getRotation().z - 2.f * (float)PI });
+		if (getRotation().z < -2 * PI)
+			setRotation({ getRotation().x, getRotation().y, getRotation().z + 2.f * (float)PI });
+		SetCursorPos(window->getPosition().x + window->getKörperGröße().x / 2, window->getPosition().y + window->getKörperGröße().y / 2);
+		setShowCursor(false);
+		setMausPos(window->getPosition() + window->getGröße() / 2);
+	}
+	timeSiceTransmision += time;
+	if (timeSiceTransmision > 0.5 && transmittedDirection != getWorldDirection(getScreenPos() + getScreenSize() / 2))
+	{
+		transmittedDirection = getWorldDirection(getScreenPos() + getScreenSize() / 2);
+		char action[13];
+		action[0] = 2;
+		*(float*)(action + 1) = transmittedDirection.x;
+		*(float*)(action + 5) = transmittedDirection.y;
+		*(float*)(action + 9) = transmittedDirection.z;
+		network->zFactoryClient()->sendPlayerAction(action, 13);
+		timeSiceTransmision = 0;
+	}
 	return result;
 }
 
@@ -241,4 +245,8 @@ void PlayerKam::setControlEnabled(bool enabled)
 {
 	kameraControll = enabled;
 	setShowCursor(!kameraControll);
+	if (kameraControll)
+	{
+		SetCursorPos(window->getPosition().x + window->getKörperGröße().x / 2, window->getPosition().y + window->getKörperGröße().y / 2);
+	}
 }

+ 3 - 1
FactoryCraft/PlayerKam.h

@@ -2,13 +2,15 @@
 #include <Kam3D.h>
 #include <TastaturEreignis.h>
 #include <Bildschirm.h>
+#include <Zeit.h>
 
 class PlayerKam : public Framework::Kam3D
 {
 private:
 	bool kameraControll;
-	Framework::Punkt lastMousePos;
 	int entityId;
+	Framework::Vec3<float> transmittedDirection;
+	double timeSiceTransmision;
 
 public:
 	PlayerKam(Framework::Bildschirm3D* zScreen);

BIN
FactoryCraft/data_release/bilder/system.ltdb


BIN
FactoryCraft/data_release/textures/blocks.ltdb


BIN
FactoryCraft/data_release/textures/player.ltdb


BIN
FactoryCraft/error_core_memory_dump.dmp