Jump to content

Getting the visible points of an object


Recommended Posts

Posted (edited)

So I want to get the visible points of an object, because sometimes doing isVisible() returns false although some points of an object are visible.

I tried looking into the Model class of the api but didn't find anything useful to me.

 

EDIT:

I was guessing I could do something with getRasterizedPoints(), but the api doesn't tell what it really does :/

Edited by Vilius
Posted (edited)

get the model area of the object and check the intersection bounds with the game canvas.

					RS2Object object = ...; 
					Rectangle modelBounds = object.getModel().getArea(object.getGridX(), object.getGridX(), object.getZ()).getBounds();
					Rectangle canvasBounds = getBot().getCanvas().getBounds();
					Rectangle intersection = modelBounds.intersection(canvasBounds);
					int minimumDimension = 5;
					boolean visible = intersection.width > minimumDimension && intersection.height > minimumDimension;
Edited by Botre
Posted

You might want to look at GraphicUtilities#getSuitablePoint(MouseDestination destination). For an entity it calls GraphicUtilities#getModelMeshTriangles and checks what is within MAIN_SCREEN_CLIP, I think that's what you want.

Thank you very much, exactly what I needed.

Code for those who need it:

	private boolean isPointOnScreen(Entity e) {
		if (e != null) {
			ArrayList<Polygon> poly = GraphicUtilities.getModelMeshTriangles(bot, e.getGridX(), e.getGridY(), e.getZ(),
					e.getModel());
			for (Polygon p : poly) {
				if (GraphicUtilities.MAIN_SCREEN_CLIP.contains(p.getBounds())) {
					return true;
				}
			}
		}
		return false;
	}
  • Like 2

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...