Object Overlap question

Here you can ask questions or provide insights about how to use efficiently 6502 assembly code on the Oric.
User avatar
Twilighte
Game master
Posts: 819
Joined: Sat Jan 07, 2006 12:07 am
Location: Luton, UK
Contact:

Object Overlap question

Post by Twilighte »

I have two objects, each with X,Y,Width and Height properties, and i'm trying to find out if they overlap and where they overlap.
I need to plot only the area they overlap with each other.

Here is the code i currently have...

Code: Select all

	;Now check if object overlaps sprite
	lda object_x
	clc
	adc object_w
	cmp sprite_x
	bcc NotOverlapping
	sta object_r	;Right
	lda object_y
	clc
	adc object_h
	cmp sprite_y
	bcc NotOverlapping
	sta object_b	;Bottom
	lda sprite_x
	clc
	adc sprite_w
	cmp object_x
	bcc NotOverlapping
	lda sprite_y
	clc
	adc sprite_h
	cmp object_y
	bcc NotOverlapping
	;AFAIK, at this point, the sprite overlays the object?

	;Calculate overlap dimension(Size) and position
User avatar
Chema
Game master
Posts: 3014
Joined: Tue Jan 17, 2006 10:55 am
Location: Gijón, SPAIN
Contact:

Re: Object Overlap question

Post by Chema »

Twilighte wrote:I have two objects, each with X,Y,Width and Height properties, and i'm trying to find out if they overlap and where they overlap.
I need to plot only the area they overlap with each other.

Here is the code i currently have...
You are using the same method I use for checking intersections, so I suppose it should work.

On the question of finding the interection area, a friend of mine gave me this idea, supposing (0,0) is the top right corner of the screen, else change step 2 to be max instead of min:

Input: {{x1, y1, h1, v1}, {x2, y2, h2, v2}}.
1. Calculate x = min(x1,x2).
2. Calculate y = min(y1,y2).
Output: {x, y, h2+abs(x2-x1), v2+abs(y2-y1)}.

This is quite easy to code in asm, I think. I finally did not use it, buy may in the future. You can calculate the min with a substraction, so you also have the result for calculating h and v in the output, and perform the abs at the same time.

Regards,
Post Reply