diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/stage.c | 37 | 
1 files changed, 19 insertions, 18 deletions
| diff --git a/src/stage.c b/src/stage.c index 2a8a5a5..70c5424 100644 --- a/src/stage.c +++ b/src/stage.c @@ -356,11 +356,12 @@ void stage_get_position(stage_t *stage, v2f_t *res_position)  	*res_position = stage->position;  } -/* translate an aabb having origin origin at pos position into a dest rect witin stage_rect */ -static void aabb_to_rect(const v2f_t *stage_pos, const aabb_t *aabb, const v2f_t *aabb_origin, const v2f_t *aabb_pos, const SDL_Rect *stage_rect, SDL_Rect *res_rect) + +/* translate a node's aabb within the given stage to a rect witin stage_rect, storing result in *res_rect */ +static void node_to_rect(const stage_t *stage, const stage_node_t *node, const SDL_Rect *stage_rect, SDL_Rect *res_rect)  { -	float	aabb_w = (aabb->max.x - aabb->min.x); -	float	aabb_h = (aabb->max.y - aabb->min.y); +	float	aabb_w = (node->aabb.max.x - node->aabb.min.x); +	float	aabb_h = (node->aabb.max.y - node->aabb.min.y);  	/* res dimensions are simply aabb dimensions scaled by stage dimensions */  	res_rect->w = floorf(aabb_w * .5f * (float)stage_rect->w); @@ -370,21 +371,21 @@ static void aabb_to_rect(const v2f_t *stage_pos, const aabb_t *aabb, const v2f_t  	res_rect->x = stage_rect->x + floorf((float)stage_rect->w * .5f);  	res_rect->y = stage_rect->y + floorf((float)stage_rect->h * .5f); -	/* apply stage_pos (scaled relative to stage_rect) */ -	res_rect->x += floorf(stage_pos->x * .5f * (float)stage_rect->w); -	res_rect->y += -floorf(stage_pos->y * .5f * (float)stage_rect->h); +	/* apply stage->position (scaled relative to stage_rect) */ +	res_rect->x += floorf(stage->position.x * .5f * (float)stage_rect->w); +	res_rect->y += -floorf(stage->position.y * .5f * (float)stage_rect->h); -	/* apply aabb_pos (scaled relative to stage_rect) */ -	res_rect->x += floorf(aabb_pos->x * .5f * (float)stage_rect->w); -	res_rect->y += -floorf(aabb_pos->y * .5f * (float)stage_rect->h); +	/* apply node->position (scaled relative to stage_rect) */ +	res_rect->x += floorf(node->position.x * .5f * (float)stage_rect->w); +	res_rect->y += -floorf(node->position.y * .5f * (float)stage_rect->h); -	/* apply aabb_origin (scaled relative to scaled aabb_w) (this probably needs to be inverted) */ -	res_rect->x += floorf(aabb_origin->x * .5f * (float)res_rect->w); -	res_rect->y += -floorf(aabb_origin->y * .5f * (float)res_rect->h); +	/* apply node->origin (scaled relative to scaled aabb_w) (this probably needs to be inverted) */ +	res_rect->x += floorf(node->origin.x * .5f * (float)res_rect->w); +	res_rect->y += -floorf(node->origin.y * .5f * (float)res_rect->h); -	/* apply aabb (scaled relative to stage_rect) */ -	res_rect->x += floorf(aabb->min.x * .5f * (float)stage_rect->w); -	res_rect->y += -floorf(aabb->max.y * .5f * (float)stage_rect->h); +	/* apply node->aabb (scaled relative to stage_rect) */ +	res_rect->x += floorf(node->aabb.min.x * .5f * (float)stage_rect->w); +	res_rect->y += -floorf(node->aabb.max.y * .5f * (float)stage_rect->h);  	/* Prevent producing 0-dimensioned non-zero rects even if it's technicaly incorrect,  	 * what's likely going on is the window has been resized very small.  Rather @@ -410,7 +411,7 @@ static void render_nodes(const stage_t *stage, const list_head_t *head, SDL_Rend  			continue;  		/* scale the node's aabb stage coordinates to destination renderer coordinates */ -		aabb_to_rect(&stage->position, &node->aabb, &node->origin, &node->position, dest_rect, &node_rect); +		node_to_rect(stage, node, dest_rect, &node_rect);  		/* if we have a cached texture, see if the dimensions changed */  		if (node->cached.texture && @@ -518,7 +519,7 @@ stage_node_t * stage_node_lookup_cartesian(const stage_t *stage, int x, int y)  			if (!node->active)  				continue; -			aabb_to_rect(&stage->position, &node->aabb, &node->origin, &node->position, &rect, &node_rect); +			node_to_rect(stage, node, &rect, &node_rect);  			if (x >= node_rect.x && x < node_rect.x + node_rect.w &&  			    y >= node_rect.y && y < node_rect.y + node_rect.h)  				return node; | 
