Coder Social home page Coder Social logo

Click/hit detection about isomer HOT 17 OPEN

jdan avatar jdan commented on September 2, 2024 3
Click/hit detection

from isomer.

Comments (17)

KenoLeon avatar KenoLeon commented on September 2, 2024 11

I was recently stuck trying to bring hit detection to isomers cousin ( Obelisk.js) and no joke I almost drove myself potty as well.
In the end I channeled my inner MacGyver and added another library ( easel.js), which allows for bitmaps to be used along mouse events. Here's the stackOverflow thread: Intersecting an isometric cube in obelisk.js I even made a little interactive thing: Codepen- The toners !

So what I hear you say, this is Isomer land, well, it works just as fine for Isomer, It might not scale and you might have some issues with overlapping geometry, but its a relatively painless way of adding some interactivity ( easel.js is something like 87k), Here's a very basic example:

Codepen - Isomer mouseover:

And the result:

isomerhitdetection

Cheers !

from isomer.

jdan avatar jdan commented on September 2, 2024

Not yet, could be cool to play around with though - good idea!

from isomer.

mcintyre321 avatar mcintyre321 commented on September 2, 2024

I drove myself potty trying isometric hit detection once.

A depth buffer might do it, depends on your code :)

sent from my mobile
On 28 Apr 2014 16:55, "Jordan Scales" [email protected] wrote:

Not yet, could be cool to play around with though - good idea!


Reply to this email directly or view it on GitHubhttps://github.com//issues/15#issuecomment-41576008
.

from isomer.

jdan avatar jdan commented on September 2, 2024

@mcintyre321 any experience with depth buffering? #9 needs it big time.

from isomer.

mcintyre321 avatar mcintyre321 commented on September 2, 2024

Whoops, accidentally deleted my comment. I'll attempt to remember it.

"As you are using canvas fills, as opposed to per-pixel rendering, you could render shapes (in depth order) to a second canvas using a unique colour for the whole shape, creating a colour=>shape lookup table. To do mouse events, get pixel colour at a particular cell, and use it as a key for the lookup table"

from isomer.

mcintyre321 avatar mcintyre321 commented on September 2, 2024

My edit was going to be: at some point you might just want to go with an orthographic projection in threejs under the hood, and use it's z-buffer facilities (assuming it has them :))

from isomer.

jdan avatar jdan commented on September 2, 2024

Wow that's super smart, thanks! And yeah, I'm not totally sure if I want to use Threejs or something else under the hood - the whole idea was to make something crazy small and portable that could be used for simple web graphics. I didn't intend it to be a super powerful graphics engine, just a simple one.

from isomer.

mcintyre321 avatar mcintyre321 commented on September 2, 2024

Which is a commendable goal - I had a look at the code and it is crazy small!

I'd like to be able to write simple web games using Isomer (hence the hit detection request), and there are a couple of other features that would be nice (e.g. removal of Shapes, a Camera class) - are these features likely to be on the roadmap?

from isomer.

jdan avatar jdan commented on September 2, 2024

Yeah definitely. Keeping track of objects in the scene has a pretty big priority.

from isomer.

nijikokun avatar nijikokun commented on September 2, 2024

Position seems more reliable than color

from isomer.

jdan avatar jdan commented on September 2, 2024

What he means is drawing a flat color on a separate canvas - not shaded - so that it's easy to do a lookup based on mouse position.

from isomer.

nijikokun avatar nijikokun commented on September 2, 2024

I get that part, but doesn't it seem like a roundabout way to keep track of the object, rather than relying on x,y and then checking what is the foremost z index object?

from isomer.

jdan avatar jdan commented on September 2, 2024

Not totally sure I understand, sorry.

from isomer.

nijikokun avatar nijikokun commented on September 2, 2024

Imagine, there is a flat plane with (x, y) coordinates, now at the center of the plane is a dot which we can reference as z.

Now if we take the plane from being 2d and make it 3d, the z coordinate becomes depth.

Assuming that the higher the z coordinate is on an entity the closer it is to you, and the lower, the further away it is.

When you click with a mouse you get two coordinates (x, y) using those two positions you can cross reference from the highest z coordinate to the lowest z coordinate to find the block they clicked on (assuming you have some sort of collision detection / contains (x, y) on each entity)

Another way is to create a camera and a raycaster to get the intersection (which is basically what you are doing, is intersecting)

Should you not be using a depth-coordinate at all, it will be a little easier as all you have to do is translate the mouse click to an absolute tile click.

Imagine you are using same colors, or image tiles, or they are touching, you are screwed in a sense if you use colors.

from isomer.

mcintyre321 avatar mcintyre321 commented on September 2, 2024

Pixel xy to object mapping is going to be tricky once you take into account
different shapes and rotation..

Given that, I suspect any other methods will end up being equivalent to
rendering a single colour per shape to a second canvas (you need the second
canvas in order to avoid the issues you mention with textures).

from isomer.

DaveKinsella avatar DaveKinsella commented on September 2, 2024

The flat color render on a separate canvas is a very clever idea, I guess, as it's not a canvas that will be displayed, you could just assign any color to each object so you would only run into trouble if you have over 16.5 million objects?

from isomer.

FabrizioC avatar FabrizioC commented on September 2, 2024

@DaveKinsella the answer to your question could be: "Is javascript a good solution to render a canvas with 16.5 million objects?"
Well, to be serious my opinion is exactly as your.

from isomer.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.