Heres the camera from my QuantumAPI, I fixed a few issues since I posted that snippet. You'll need to adapt it to work without the API but it shouldn't be hard:
package rip.quantum.api;
import java.awt.Point;
import java.awt.event.MouseEvent;
import org.osbot.rs07.api.map.Position;
import org.osbot.rs07.api.model.Entity;
import org.osbot.rs07.api.model.Vector3D;
import org.osbot.rs07.script.MethodProvider;
import rip.quantum.QuantumAPI;
/**
* Camera that uses the middle-mouse button and mouse movements.
*
* @author lemons
*/
public class QuantumCamera extends QuantumAPI {
public QuantumCamera(MethodProvider methodProdiver) {
super(methodProdiver);
}
/**
* Moves the camera to the desired yaw and pitch.
*
* @param yaw
* @param pitch
*/
public void moveCamera(int yaw, int pitch) {
if (pitch > 67)
pitch = 67;
else if (pitch < 34)
pitch = 34;
int pitchCur = getPitchAngle(),
yawCur = getYawAngle(),
pitchDir = pitch < pitchCur ? -1 : 1,
pitchDiff = Math.abs(pitch - pitchCur),
yawDir = yaw > yawCur ? -1 : 1,
yawDiff = Math.abs(yaw - yawCur);
if (yawDiff > 180) {
// Flip how we get there
yawDiff = 360 - yawDiff;
yawDir *= -1;
}
if (yawDiff < 22 && pitchDiff < 14)
return;
int x = yawDir * yawDiff * 3,
y = pitchDir * pitchDiff * 3;
int minX = 40 - (yawDir == -1 ? x : 0),
maxX = 724 - (yawDir == 1 ? x : 0),
minY = 40 + (pitchDir == -1 ? y : 0),
maxY = 460 + (pitchDir == 1 ? y: 0);
try {
Point bot = getMouse().getPosition();
for (int i = 0; i < 5 && !getMouse().isOnScreen(); i++) {
getMouse().move(random(minX, maxX), random(minY, maxY));
sleep(50);
}
if (bot.x < minX || bot.x > maxX
|| bot.y < minY || bot.y > maxY) {
getMouse().move(random(minX, maxX), random(minY, maxY));
sleep(50);
}
mousePress(true);
bot = getMouse().getPosition();
int newX = Math.min(764, Math.max(0, bot.x + x)),
newY = Math.min(502, Math.max(0, bot.y + y));
// Use OSBots move here
getMethods().getMouse().move(newX, newY);
sleep(50);
mousePress(false);
} catch (InterruptedException e) {
getLogger().error("", e);
}
}
public boolean toEntity(Entity e) {
return toEntity(myPosition(), e);
}
/**
* Turns the camera toward the entity as if the player were positioned at origin.
* @param origin
* @param e
* @return
*/
public boolean toEntity(Vector3D origin, Entity e) {
if (e == null)
return false;
moveCamera(getAngleTo(origin, e), getPitchTo(origin, e));
return true;
}
/**
* Turns the camera toward the tile as if the player were positioned at origin.
* @param origin
* @param tile
* @return
*/
public boolean toVector3D(Vector3D origin, Vector3D tile) {
if (getMap().distance(origin, myPosition()) > 16)
return false;
moveCamera(getAngleTo(origin, tile), getPitchTo(origin, tile));
return true;
}
/**
* Turns the camera towards tile from the players current position.
* @param tile
* @return
*/
public boolean toVector3D(Vector3D tile) {
return toVector3D(myPosition(), tile);
}
/**
* Turns the camera towards the position from the origin.
* @param tile
* @return
*/
public boolean toPosition(Position origin, Position p) {
return toVector3D(origin, p);
}
public boolean toPosition(Position p) {
return toVector3D(p);
}
/**
* Faces the camera roughly north.
*/
public void toNorth() {
int r = random(0, 30);
if (r > 15)
r = 375 - r;
getCamera().moveYaw(r);
}
/**
* Faces the camera roughly west.
*/
public void toWest() {
getCamera().moveYaw(75 + random(0, 30));
}
/**
* Faces the camera roughly south.
*/
public void toSouth() {
getCamera().moveYaw(165 + random(0, 30));
}
/**
* Faces the camera roughly east.
*/
public void toEast() {
getCamera().moveYaw(255 + random(0, 30));
}
public int getLowestPitchAngle() {
return getMethods().getCamera().getLowestPitchAngle();
}
public int getPitchAngle() {
return getMethods().getCamera().getPitchAngle();
}
public int getX() {
return getMethods().getCamera().getX();
}
public int getY() {
return getMethods().getCamera().getY();
}
public int getYawAngle() {
return getMethods().getCamera().getYawAngle();
}
public int getZ() {
return getMethods().getCamera().getZ();
}
public boolean isDefaultScaleZ() {
return getMethods().getCamera().isDefaultScaleZ();
}
public boolean movePitch(int degrees) {
moveCamera(getYawAngle(), degrees);
return true;
}
public boolean moveYaw(int degrees) {
moveCamera(degrees, getPitchAngle());
return true;
}
public boolean toBottom() {
return movePitch(0);
}
public boolean toTop() {
return movePitch(67);
}
private void mousePress(boolean press) {
getBot()
.getMouseEventHandler()
.generateBotMouseEvent(press ? MouseEvent.MOUSE_PRESSED : MouseEvent.MOUSE_RELEASED,
System.currentTimeMillis(), 0,
getMouse().getPosition().x,
getMouse().getPosition().y, 1, false,
MouseEvent.BUTTON2, true);
}
private int getPitchTo(Vector3D origin, Vector3D t) {
int pitch = 67 - (int) (getMap().distance(origin, t) * 4);
if (pitch > 67) {
pitch = 67;
} else if (pitch < 22) {
pitch = 22;
}
return pitch;
}
private int getAngleTo(Vector3D origin, Vector3D tile) {
int degree = (int) Math.toDegrees(Math.atan2(
tile.getY() - origin.getY(), tile.getX() - origin.getX()));
int a = ((degree >= 0 ? degree : 360 + degree) - 90) % 360;
return a < 0 ? a + 360 : a;
}
}