[SNIPPET][PAPER] Intersection of the player's vision and the block face

Discussion in 'Resources' started by ase34, Apr 29, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    ase34

    Hello,

    I recently have written a snippet of code for determining the intersection point of the player's line of vision and a map hanging on an item frame for clickable buttons on the map.

    Now, I have improved the snippet to find the intersection of any line and plane, and created a pdf paper containing the full mathematical explanation (if you're actually interested in), a full usage example and the the code (also available on GitHub Gist). If you have any questions, please ask them.

    Demonstration GIF:
    [​IMG]

    May it will be useful ;)
     
    jjssman, Plo124, gkovalecyn and 15 others like this.
  2. Offline

    Flybelette

    You are one of the best developper I have see here :p
     
    NerdsWBNerds, MrAwellstein and ase34 like this.
  3. Offline

    Onlineids

    Probably how mineplex does there drawing game.
     
  4. Offline

    ase34

    Well, I actually assume they used the Bukkit-provided method getLineOfSight, which uses a different technique internally. Drawing on maps would not be possible with that method as it can only detect whole blocks, not intersection points.
     
    Plo124 and bobacadodl like this.
  5. Offline

    AstramG

    This is so cool dude!
     
  6. Offline

    Phasesaber

    Could you give out the src for the map drawing?
     
  7. Offline

    ase34

    Phasesaber The code is a mess, but I'll try my best to clean it up and giving it out.
     
    Phasesaber likes this.
  8. Offline

    Superckl1

    ase34

    My question is a bit off topic, but what software did you use to generate that image of the plane in the xyz-space? I've been trying to find a good program for a long time.

    Also, your paper is missing a lot of periods. Mainly after mathematical declarations you make. Just thought I'd point it out ;)
     
  9. Offline

    desht

  10. Offline

    ccrama

    Although it is a very awesome accomplishment, apart from drawing on maps, do you have any other ideas on how it can be used? I have a few ideas, but don't know if it's possible to trigger areas of a block (perhaps a pin you enter to open doors?). Do you have any idea if it's possible?
    Thanks
     
  11. Offline

    ase34

    I used latex and tikz/3dplot for the image. Google will help you ;)



    Yes, it used a different equation for the plane and line, which makes the solving of the equation easier as there is only one unknown. However, this method gives you only the absolute position of the vector, and does need additional computations to find the offsets of defined sub-axes. (See the vector u and v in the fig. 2 of the paper)

    Yes, it is even easier that the drawing. You just have to check if the intersection point is inside a specified rectangle.
     
    ccrama likes this.
  12. Offline

    ccrama

    ase34 Sweet, thanks for the info
     
  13. Offline

    ase34



    The source code for the gif is now hosted on GitHub Gist.
     
  14. Offline

    Superckl1

    ase34

    Thanks, I've never looked at tikz before.

    Also, I just wanted to say how much I appreciate you writing up your math with LaTeX. It's really nice for us math nerds :p. Is it possible for me to get snippets of the actual LaTeX (mainly how you draw the pictures) code?
     
  15. Offline

    ase34

    Superckl1 No problem, I just have created a GitHub gist with the source. Please keep in mind that I as well am new to latex, and that the code/syntax might not be the best one.
     
  16. Offline

    SoThatsIt

    Why so complicated? xD

    I did this before with perfect accuracy by just getting the unit vector of the players looking direction and then getting where that intersects there getTargetBlock... Its not as elegant but it works just as well. Maybe your method is more efficient? just another way of doing it i guess.
     
    bobacadodl likes this.
  17. Offline

    Skyost

  18. Offline

    Superckl1

    SoThatsIt

    Because math.

    ase34

    Thanks for the raw code! It really helped me get my project on Gauss's Theorem along. I was struggling with drawing the proper images, but now it's a piece of cake :D
     
  19. Offline

    ase34

    SoThatsIt Of course, your method works as well, but you are limited to block faces, and you can only compute the absolute point. With my method, you can define any plane and any line and still you can find the intersection point with defined axes for a sub-coordinate-system.
     
  20. Offline

    Superckl1

    ase34

    Still off topic, but I just wanted to show you some of the images I was able to generate thanks to you :)
    Show Spoiler

    [​IMG]
    [​IMG]
    [​IMG]
    [​IMG]
    [​IMG]
    [​IMG]

    Once again, thank you!
     
  21. Offline

    creepers84

    Your map code doesn't work. Here is the error message:
    [​IMG]
     
  22. Offline

    macguy8

    creepers84
    That error means nothing without your code. Perhaps attaching some would help out a bit
     
  23. Offline

    Phasesaber

  24. Offline

    desht

    You need to change that demo code to use a map ID that definitely exists on your server, otherwise you'll get a null MapView object. You'll probably also need to modify the co-ordinates in the draw() method to reflect your map's location and orientation.

    A "production" plugin would need to allocate a new map ID for itself with Bukkit.createMap(), but not every time the plugin starts up, otherwise you're wasting map IDs (there are only 65,536), not to mention having to get a new map item each time. Allocate it on the first run and store the returned ID (in a config file or however you want), and on subsequent runs use that stored ID to get your MapView object.
     
  25. Offline

    ase34

    creepers84 Exactly as desht stated, you have to change the map ID in the code as well as the location and vectors. See the lines 112 and 145-147. I should had marked it more clearly :).
     
  26. Offline

    creepers84

    ase34 How do I get the MapID and specific locations?
     
  27. Offline

    ase34

    The map ID gets displayed if you hover a drawn map in Minecraft. To get the locations, use the f3 debug screen. I'm really sorry that I couldn't give clear instructions on how exactly to do this, I honestly do not know how. But I am convinced you can find out yourself. As a hint, the map is 1/16th of a block thick (or 0.0625 block)
     
  28. Offline

    JUSTCAMH

    I had a try and I can't seem to be able to rig it
    ase34
    Could you please make some sort of tutorial or written explanation on how to do this?
    If you could it would really help me and alot of over devs.
    oh and btw your code is amazing!
     
  29. Offline

    ase34

    JUSTCAMH Ok. With the f3 debug screen, (a) try to get the block vector (X, Y and Z end with .0) of the top left corner of the frame. Then, (b) get the direction (north, east, south, west) to where the player looking to the frame would stand. Then, with given x,y,z from (a) and direction from (b):

    yDirection = (0,-1,0)
    xDirection = if north: (-1,0,0); if west: (0,0,1); if south: (1,0,0); if east: (0,0,-1)
    planeOrigin = if north: (x,y,z-0.0625); if west: (x-0.0625,y,z); if south: (x,y,z+0.0625); if east: (x+0.0625,y,z)

    You can now pass these values into the lines 145-147. I hope this makes it a bit more clearly, although I do know that the way I have written this eventually makes this even more complicated. Let's hope for the best :D
     
  30. epic! I didnt read all, but can you put the code you used in the GIF?
     
Thread Status:
Not open for further replies.

Share This Page