Jump to content

A few questions regarding models


Bobrocket

Recommended Posts

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 <3

Edited by Bobrocket
Link to comment
Share on other sites

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 by Botre
  • Like 1
Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

  • Like 1
Link to comment
Share on other sites

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!

Link to comment
Share on other sites

 

Play around with it a bit smile.png

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 tongue.png

 

Edit: was right; higher index = closer to the front of the stack.

Edited by Bobrocket
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

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