|
@@ -13,6 +13,8 @@ PlayerKam::PlayerKam(Framework::Bildschirm3D* zScreen)
|
|
setStyle(Kam3D::Style::Tick | Kam3D::Style::Movable | Kam3D::Style::Rotatable);
|
|
setStyle(Kam3D::Style::Tick | Kam3D::Style::Movable | Kam3D::Style::Rotatable);
|
|
setRotation({ (float)PI / 2.f, 0, 0 });
|
|
setRotation({ (float)PI / 2.f, 0, 0 });
|
|
entityId = -1;
|
|
entityId = -1;
|
|
|
|
+ transmittedDirection = getWorldDirection(getScreenPos() + getScreenSize() / 2);
|
|
|
|
+ timeSiceTransmision = 0;
|
|
}
|
|
}
|
|
|
|
|
|
void PlayerKam::setDirection(Framework::Vec3<float> direction)
|
|
void PlayerKam::setDirection(Framework::Vec3<float> direction)
|
|
@@ -128,7 +130,7 @@ void PlayerKam::doTastaturEreignis(Framework::TastaturEreignis& te)
|
|
bool oldControl = kameraControll;
|
|
bool oldControl = kameraControll;
|
|
kameraControll = 0;
|
|
kameraControll = 0;
|
|
setShowCursor(true);
|
|
setShowCursor(true);
|
|
- if(!oldControl)
|
|
|
|
|
|
+ if (!oldControl)
|
|
((Game*)(Menu*)menuRegister->get("game"))->closeCurrentDialog();
|
|
((Game*)(Menu*)menuRegister->get("game"))->closeCurrentDialog();
|
|
}
|
|
}
|
|
if (te.taste == T_Tab)
|
|
if (te.taste == T_Tab)
|
|
@@ -151,34 +153,12 @@ void PlayerKam::doMausEreignis(Framework::MausEreignis& me)
|
|
if (!kameraControll)
|
|
if (!kameraControll)
|
|
{
|
|
{
|
|
if (me.id == ME_PLinks)
|
|
if (me.id == ME_PLinks)
|
|
- {
|
|
|
|
- lastMousePos = { me.originalX, me.originalY };
|
|
|
|
- kameraControll = 1;
|
|
|
|
- }
|
|
|
|
|
|
+ setControlEnabled(1);
|
|
}
|
|
}
|
|
else
|
|
else
|
|
{
|
|
{
|
|
if (kameraControll)
|
|
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)
|
|
if (me.id == ME_PLinks)
|
|
{
|
|
{
|
|
char action[2] = { 1, 8 };
|
|
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 });
|
|
((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;
|
|
return result;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -241,4 +245,8 @@ void PlayerKam::setControlEnabled(bool enabled)
|
|
{
|
|
{
|
|
kameraControll = enabled;
|
|
kameraControll = enabled;
|
|
setShowCursor(!kameraControll);
|
|
setShowCursor(!kameraControll);
|
|
|
|
+ if (kameraControll)
|
|
|
|
+ {
|
|
|
|
+ SetCursorPos(window->getPosition().x + window->getKörperGröße().x / 2, window->getPosition().y + window->getKörperGröße().y / 2);
|
|
|
|
+ }
|
|
}
|
|
}
|