[Elvarg] Moving The Camera for Cutscenes
I have been playing around with the camera packets and cannot seem to figure out how they work exactly. I get the gist of it, but I get very confused when it comes to exact positioning. If someone could take the time to briefly explain how it all works I would greatly appreciate it.
I'm trying to get the camera to face white wolf mountain, and the exact local coordinates for the spot I want the camera are X: 51 and Y: 51. When I use these the camera goes to the spot but then does a 180 and looks the complete opposite way like so:
https://i.gyazo.com/5100b19a27dbd57c...0cda504d8b.gif
Also, it seems the end result is not the same every time even when using the same command with the same local coordinates:
https://i.gyazo.com/d1e9649e33b788ca...230f574372.gif
This wouldn't really be an issue if I could figure out how to make the camera face a certain direction. Whenever I try to rotate the camera after I move it, nothing really happens. It just stays in the same spot like so:
https://gyazo.com/18f7a03a36b2139cb58f80a5d1afed9e.gif
But when trying to rotate from the normal camera view it just seems to do the same thing every single time no matter what coordinates I use:
https://gyazo.com/6fd3fa27d544f25cce4c1c7a381c8040.gif
and
https://gyazo.com/4447b8f266e7b263f8a620efe9ce6a3a.gif
I'm not sure if the methods are wrong, or if there's a different approach to this, or simply just using them wrong.
These are the methods that I am using inside the packetsender class:
Code:
public PacketSender turnCameraTowardLocation(int x, int y, int level, int speed, int angle) {
PacketBuilder out = new PacketBuilder(177);
out.put(x / 64);
out.put(y / 64);
out.putShort(level);
out.put(speed);
out.put(angle);
player.getSession().write(out);
return this;
}
public PacketSender moveCameraToLocation(int x, int y, int z, int speed, int angle) {
PacketBuilder out = new PacketBuilder(166);
out.put(x);
out.put(y);
out.putShort(z);
out.put(speed);
out.put(angle);
player.getSession().write(out);
return this;
}
And these are the commands I am using to access these:
Code:
if (parts[0].startsWith("movecam")) {
int x = Integer.parseInt(parts[1]);
int y = Integer.parseInt(parts[2]);
int z = Integer.parseInt(parts[3]);
int cs = Integer.parseInt(parts[4]);
int vs = Integer.parseInt(parts[5]);
player.getPacketSender().moveCameraToLocation(x, y, z, cs, vs);
}
if (parts[0].startsWith("rotcam")) {
int x = Integer.parseInt(parts[1]);
int y = Integer.parseInt(parts[2]);
int z = Integer.parseInt(parts[3]);
int cs = Integer.parseInt(parts[4]);
int vs = Integer.parseInt(parts[5]);
player.getPacketSender().turnCameraTowardLocation(x, y, z, cs, vs);
}
Ill also post the client side methods as well:
Code:
if (opcode == PacketConstants.ROTATE_CAMERA) {
oriented = true;
x = incoming.readUnsignedByte();
y = incoming.readUnsignedByte();
height = incoming.readUShort();
speed = incoming.readUnsignedByte();
angle = incoming.readUnsignedByte();
if (angle >= 100) {
xCameraPos = x * 128 + 64;
yCameraPos = y * 128 + 64;
zCameraPos = getCenterHeight(plane, yCameraPos, xCameraPos) - height;
}
opcode = -1;
return true;
}
if (opcode == PacketConstants.MOVE_CAMERA) { //Gradually turn camera to spatial point.
oriented = true;
cinematicCamXViewpointLoc = incoming.readUnsignedByte();
cinematicCamYViewpointLoc = incoming.readUnsignedByte();
cinematicCamZViewpointLoc = incoming.readUShort();
constCinematicCamRotationSpeed = incoming.readUnsignedByte();
varCinematicCamRotationSpeedPromille = incoming.readUnsignedByte();
if (varCinematicCamRotationSpeedPromille >= 100) {
int cinCamXViewpointPos = cinematicCamXViewpointLoc * 128 + 64;
int cinCamYViewpointPos = cinematicCamYViewpointLoc * 128 + 64;
int cinCamZViewpointPos = getCenterHeight(plane, cinCamYViewpointPos, cinCamXViewpointPos) - cinematicCamZViewpointLoc;
int dXPos = cinCamXViewpointPos - xCameraPos;
int dYPos = cinCamYViewpointPos - yCameraPos;
int dZPos = cinCamZViewpointPos - zCameraPos;
int flatDistance = (int) Math.sqrt(dXPos * dXPos + dYPos * dYPos);
yCameraCurve = (int) (Math.atan2(dZPos, flatDistance) * 325.94900000000001D)
& 0x7ff;
xCameraCurve = (int) (Math.atan2(dXPos, dYPos) * -325.94900000000001D)
& 0x7ff;
if (yCameraCurve < 128)
yCameraCurve = 128;
if (yCameraCurve > 383)
yCameraCurve = 383;
}
opcode = -1;
return true;
}
If someone could lend a hand and point me in the right direction, it would be very helpful since i've been stuck on this for awhile now.