Bobrocket Posted July 26, 2015 Share Posted July 26, 2015 (edited) I have 2 questions regarding models: How do I check which model or object is at the top of where the cursor is? For example, say I have my camera moved in such a way where a seed stall is infront of the master farmer, and I move my mouse to the master farmer and left click. This is going to click the seed stall. How can I detect that the seed stall is the first object there so I can choose to right click? How do I check for visible parts of the model? For example, say 2 models are slightly overlapping (let's use the seed stall and master farmer example once more), and this leaves the master farmer with about half his actual model as actual visible space (to us). The client, however, recognises his entire model as visible. How can I see which bits of the model are actually visible to the client? Sorry if these do not make sense, I just woke up. EDIT: I am still looking for how to find which objects appear in front of my specified object. pls help Edited July 26, 2015 by Bobrocket Quote Link to comment Share on other sites More sharing options...
Botre Posted July 26, 2015 Share Posted July 26, 2015 (edited) I have 2 questions regarding models: How do I check which model or object is at the top of where the cursor is? For example, say I have my camera moved in such a way where a seed stall is infront of the master farmer, and I move my mouse to the master farmer and left click. This is going to click the seed stall. How can I detect that the seed stall is the first object there so I can choose to right click? How do I check for visible parts of the model? For example, say 2 models are slightly overlapping (let's use the seed stall and master farmer example once more), and this leaves the master farmer with about half his actual model as actual visible space (to us). The client, however, recognises his entire model as visible. How can I see which bits of the model are actually visible to the client? Sorry if these do not make sense, I just woke up. 1. getMouse().getEntitiesOnCursor().contains(...); Might do the trick, or you could derive it from the action displayed in the top left corner, however I'm not sure whether the API supports that out of the box. 2. You could get the 3D bounding boxes of multiple entities' models and obtain a new model(s) by subtracting overlapping ones. Edited July 26, 2015 by Botre 1 Quote Link to comment Share on other sites More sharing options...
Bobrocket Posted July 26, 2015 Author Share Posted July 26, 2015 1. getMouse().getEntitiesOnCursor().contains(...); Might do the trick, or you could derive it from the action displayed in the top left corner, however I'm not sure whether the API supports that out of the box. 2. You could get the 3D bounding boxes of multiple entities' models and obtain a new model(s) by subtracting overlapping ones. Thank you. I'll see what I can do about the bounding boxes and edit the first post with a solution for those looking for it. Also, for the first one, I am looking to see if the Master Farmer is on top of the stack. I know that the mouse will have the entity on the cursor, but I simply need to know if the farmer is on top or not. Also, while I'm asking questions, I seem to have something which is more of a problem with Entity#isVisible(), for some reason, when the entity goes off the game screen but still within the actual applet, it seems to return true. Is there a method that checks if an entity is within the window? Quote Link to comment Share on other sites More sharing options...
blabla123 Posted July 26, 2015 Share Posted July 26, 2015 Use client.getToolTip() for the top left messages. In my interaction method I check if the action parameter is in the toolTip, if yes I left click, otherwise I right click. To check if your entity is first on cursor you could maybe use something like: if getMouse().getEntitiesOnCursor()[0].equals(yourEntity).... and so on. 1 Quote Link to comment Share on other sites More sharing options...
Bobrocket Posted July 26, 2015 Author Share Posted July 26, 2015 Use client.getToolTip() for the top left messages. In my interaction method I check if the action parameter is in the toolTip, if yes I left click, otherwise I right click. To check if your entity is first on cursor you could maybe use something like: if getMouse().getEntitiesOnCursor()[0].equals(yourEntity).... and so on. Would index 0 really be the first object though? Because the items are drawn in a layered fashion, so the first visible object is drawn the last. Maybe I'm overthinking this though Also, didn't know about getToolTip(). Thanks! Quote Link to comment Share on other sites More sharing options...
blabla123 Posted July 26, 2015 Share Posted July 26, 2015 (edited) Play around with it a bit public void onPaint(Graphics2D g){ for(int i = 0; i < mouse.getEntitiesOnCurson().size(); i++){ g.drawString("Entity number: " +i +" = " +mouse.getEntitiesOnCurson()[i], x, y + (i*15)); } } Edited July 26, 2015 by blabla123 Quote Link to comment Share on other sites More sharing options...
Bobrocket Posted July 26, 2015 Author Share Posted July 26, 2015 (edited) Play around with it a bit public void onPaint(Graphics2D g){ for(int i = 0; i < mouse.getEntitiesOnCurson().size(); i++){ g.drawString("Entity number: " +i +" = " +mouse.getEntitiesOnCurson()[i], x, y + (i*15)); } } Yeah will do, just hoped you had the answer Edit: was right; higher index = closer to the front of the stack. Edited July 26, 2015 by Bobrocket Quote Link to comment Share on other sites More sharing options...
blabla123 Posted July 26, 2015 Share Posted July 26, 2015 Nah, haven't tried it myself yet. Post here what you'll find out please Quote Link to comment Share on other sites More sharing options...
Bobrocket Posted July 26, 2015 Author Share Posted July 26, 2015 Nah, haven't tried it myself yet. Post here what you'll find out please I edited my post saying that the higher index = the closer to the front of the stack. Working on the code still for the proper bounding boxes. Quote Link to comment Share on other sites More sharing options...