Author Topic: Best way to perform clipping with irregular shapes  (Read 4315 times)

0 Members and 2 Guests are viewing this topic.

Offline Michael0x18

  • LV0 Newcomer (Next: 5)
  • Posts: 4
  • Rating: +0/-0
    • View Profile
    • One man programming group
Best way to perform clipping with irregular shapes
« on: February 22, 2021, 04:18:42 pm »
I asked this on Cemetech, but based on my prior experience they're mostly focused on the [e]Z80 calculators, and I'm basically the only new 68K programmer in the last several years, so I'm not optimistic about getting an answer. So I'm cross posting here, in the hopes that people here might be more familiar with the SDK.

Anyway, here goes:

I'm making a somewhat complicated RPG for the more recent 68K calcs, and I need to figure out how to test collisions with weird shapes, for example curved and diagonal walls. What I'm trying to do now is to draw the clipping data to a "virtual screen" and test pixels to sense collisions. Here are the questions I have regarding this topic:

1: Is there some way to redirect TIGCC/GCC4TI's sprite functions to a virtual buffer, and somehow tell it that this buffer isn't 240x128 pixels, but 256x256 pixels?

2: Is there better way to perform clipping operations?

3: In the event that I can't redirect the functions from the standard library, should I abuse ExtGraph's tile map engine or write something to copy data into the plane?

Thanks,
Michael

Offline NonstickAtom785

  • LV3 Member (Next: 100)
  • ***
  • Posts: 78
  • Rating: +4/-0
  • Just live life. Cal-cu-lat-or style!
    • View Profile
Re: Best way to perform clipping with irregular shapes
« Reply #1 on: February 22, 2021, 04:31:54 pm »
Hmm... what programming language is this in? I think I read somewhere that you could program on the 68k series with C. I could be misremembering though. In any case though clipping can be done by grabbing the pixels and rotating them in. I don't know how the TI-86k screen is setup but maybe this could be of some help. Just thought I would show some interest. Is there an emulator for this calculator?
Grammer2 is Good!

Offline Michael0x18

  • LV0 Newcomer (Next: 5)
  • Posts: 4
  • Rating: +0/-0
    • View Profile
    • One man programming group
Re: Best way to perform clipping with irregular shapes
« Reply #2 on: February 22, 2021, 04:41:06 pm »
Yeah this is in C.

To be clear, I'm using the GCC4TI SDK, running in WINE, because I couldn't get a native install to work correctly. I'm already using ExtGraph to draw the tiles, so using another few buffers probably wouldn't hurt.

Offline Xeda112358

  • they/them
  • Moderator
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 4704
  • Rating: +719/-6
  • Calc-u-lator, do doo doo do do do.
    • View Profile
Re: Best way to perform clipping with irregular shapes
« Reply #3 on: February 22, 2021, 04:47:29 pm »
I think what I would suggest is what you are already trying to do. For irregular collision boxes, I set a "collision buffer" the size of the screen (1bpp), and in that buffer I set the pixel on if it's a collision point, else off. Then when I am drawing the tile, so draw it's collision sprite to the collision buffer.

I have no idea how to do this on the 68k calcs :P

Offline Michael0x18

  • LV0 Newcomer (Next: 5)
  • Posts: 4
  • Rating: +0/-0
    • View Profile
    • One man programming group
Re: Best way to perform clipping with irregular shapes
« Reply #4 on: February 22, 2021, 05:04:48 pm »
Okay, thank you. That's settled, then.
I currently have two different "collision buffers," which are each 256x256 pixels (one for each map layer, 8192 bytes each). GCC4TI's sprite routines expect a buffer that is 240x128 (the size of the 92's screen), but mine is larger. This essentially means that I can't use the built in sprite functions to draw it, unless there's something I can change to "edit" the size of the screen.

I'll try to come up with some code that draws it myself, but it'll take a while.

Thanks for the help!

Offline E37

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 358
  • Rating: +23/-0
  • Trial and error is the best teacher
    • View Profile
Re: Best way to perform clipping with irregular shapes
« Reply #5 on: February 22, 2021, 08:15:03 pm »
If you can reduce every shape down to a series of lines (or can get away with approximating them as such) then you could just take the lines that outline the shape you want to test and check it against every line that makes up the environment. There are pretty simple formulas that you can use to check if 2 line segments intersect. If the calc you are using has a built in multiplication instruction it would likely be faster than drawing lines and use less memory depending on how it is implemented. But if you use really complex shapes or need precision with curved surfaces drawing to a buffer is your best bet. Drawing to a buffer also lets you save the buffer if the area doesn't change which makes it really fast.

If you are having trouble drawing to the larger area, you could use the built in sprite routines to draw the whole thing to the 240x128 area, copy that much to the 256x256 buffer, shift everything over, draw again, copy that much to the larger buffer and repeat until all the area is filled. If you are redrawing that every frame, it could get pretty slow.

Additionally, if you only have one object you are testing for collision, you can simply shift the environment around that one object. Since the things it will collide with will be inside the size of the default sprite drawing box, you don't need to worry about using a larger buffer. This does assume that you redraw the clipping buffer each frame/update.

Since you said you are making an rpg, I assume the environment is pretty static and using my second suggestion of a collision buffer, drawing everything to the screen just copying it chunk by chunk to the buffer is probably the best since it is the simplest.
I'm still around... kind of.

Offline Michael0x18

  • LV0 Newcomer (Next: 5)
  • Posts: 4
  • Rating: +0/-0
    • View Profile
    • One man programming group
Re: Best way to perform clipping with irregular shapes
« Reply #6 on: February 22, 2021, 08:58:18 pm »
Well, thanks everyone for the suggestions. I think I'm going to stick with the clipping plane thing. I got some assistance from @Lionel Debroux over on Ti-planet (not my first choice, since my French is terrible) and I'm using a modified version of the SDK sprite routines to draw.