3D Sprite question

Blitz3D Forums/Blitz3D Programming/3D Sprite question

semar(Posted 2004) [#1]
All,
I create a sprite and set it pickable with EntityPickMode sprite, 3 (with sprites you can only use mode 1 or 3).

Then I use CameraPick to pick that sprite, and everything works just fine.

A problem occurs when I scale the sprite using ScaleSprite command.

If I do so, the area where the sprite can be pickable, is bigger than the scaled sprite itself; in other terms, the pickable area seems to refer always to the original non-scaled sprite.

Is there any way to make the pickable area scaled as the sprite ? I've tryed with EntityBox, didn't help.

This behaviour does not happens to meshes though.

Sergio.


_PJ_(Posted 2004) [#2]
Do you set the PickMode before or after scaling?

Try changing this- does it help?

Try -Coping the sprite, after scaling and use this new sprite for Picking, removing the original.


BlackD(Posted 2004) [#3]
Actually, EntityBox DOES help, but you have to understand more about sprites. :) The entitypickmode on sprites creates a FAKE EntityBox which won't show up in the collisions list for the entity, so resizing this collision box doesn't help.

The thing about sprites, is they don't extend from 0,0 to 1,1 - they extend from -1,-1 to 1,1. I imagine when you're creating the new entity box, you're doing something like:
EntityBox sprite,0,0,0,2,2,0
Whereas it's already extended from -1 to 1, so to double that size with entitybox, you need to reflect this in the command. EntityBox sprite,x,y,w,h - in other words:
EntityBox sprite,-2,-2,0,4,4,0
will set the entity box for a double-sized sprite that had "ScaleEntity sprite,2,2" applied.

to scale it to 3x, the command would be:
EntityBox sprite,-3,-3,0,6,6,0

Example code:


From the manual:
Creates a sprite entity and returns its handle. Sprites are simple flat (usually textured) rectangles made from two triangles. Unlike other entity objects they don't actually have a mesh that can be manipulated.

The sprite will be positioned at 0,0,0 and extend from 1,-1 to +1,+1.

Note that's a typo in the manual. It means -1,-1, not 1,-1.

+BlackD


BlackD(Posted 2004) [#4]
hehe malice - by coincidence - I tried both of those in testing, before I clicked onto the reading the CreateSprite help text more carefully and noticing the -1,-1 to 1,1.

tempsprite=copysprite(sprite)
freeentity sprite
sprite=copysprite(tempsprite)
entitypickmode sprite,3

didn't work :( Actually, i just spent the last 40 minutes exploring this.. dammit :)

Anyway semar, the reason this doesn't happen with meshes, is because sprites are a special kind of entity that don't follow even half the rules that other entities do. For instance, they have no Z depth which makes half the entity commands invalid for them. I guess Mark forgot to add into the ScaleSprite code to resize the fake entitybox as well. :)


semar(Posted 2004) [#5]
Thanks you all, very appreciated.

So BlackD, you're telling me that giving EntityBox the correct parameters, it would work - well I can't try it now, but once at home I'll check it out.

I scale the sprite to make it smaller, but I think that once sorted out the right values for EntityBox, it should work the same, shouldn't it ?.

Thanks a lot,
Sergio.


BlackD(Posted 2004) [#6]
Yes, and the new entitybox should still be handled by Blitz as a fake so it doesn't actually "collide" or tie up CPU time. :)