Aligning Sprite to Terrain

Blitz3D Forums/Blitz3D Programming/Aligning Sprite to Terrain

wizzlefish(Posted 2005) [#1]
I still can't figure out how to align a sprite to a mesh.

I've tried align to vector, and a bakajillion other things. My sprite is called "p\entityhandle" and I've already done "LinePick" and everything. I've tried using "AlignToVector" but it won't appear. I can't figure out how to make it align to a mesh.


GfK(Posted 2005) [#2]
try using EntityFX p\entityhandle,16. Blitz seems to align sprites faced down (meaning they aren't visible) - so you need to disable backface culling or rotate it 180 degrees in the X axis.

You will also need to use SpriteViewMode p\entityhandle,2 if you haven't done so already.


wizzlefish(Posted 2005) [#3]
ok


GfK(Posted 2005) [#4]
ok

Don't mention it.









Oh, you didn't.


Ion-Storm(Posted 2005) [#5]
the Unmannered Newbie...


wizzlefish(Posted 2005) [#6]
Sorry.

Thanks though. Although you may not accept it now.


_PJ_(Posted 2005) [#7]
On this subject (the topic, not the subject of manners etc.!)

How do I 'get' the vector from the terrain/mesh that I want the sprite aligned-to?

As in, what values do I put in to the AlignToVector command if these will be dependant on the angle of camera and the angle of the terrain/mesh vertices.


Yan(Posted 2005) [#8]
Use the normal from a collision or pick:
Graphics3D 800, 600, 0, 2

cam = CreateCamera()
PositionEntity cam, 0, 0, -5

cube = CreateCube()
EntityPickMode cube, 2
RotateEntity cube, 45, 45, 0

light = CreateLight(2)
PositionEntity light, 500, 500, -2000

sprite = CreateSprite()
EntityColor sprite, 0, 0, 200
ScaleSprite sprite, 0.2, 0.2
SpriteViewMode sprite, 2

Repeat
	If CameraPick(cam, MouseX(), MouseY())
		PositionEntity sprite, PickedX() + (PickedNX() * 0.01), PickedY() + (PickedNY() * 0.01), PickedZ() + (PickedNZ() * 0.01)
		AlignToVector sprite, -PickedNX(), -PickedNY(), -PickedNZ(), 3, 1
		
		;I could've used:
		;PositionEntity sprite, PickedX(), PickedY(), PickedZ()
		;AlignToVector sprite, -PickedNX(), -PickedNY(), -PickedNZ(), 3, 1
		;MoveEntity sprite, 0, 0, -0.01
	EndIf
	
	RenderWorld
	Flip
Until KeyHit(1)

End



cermit(Posted 2005) [#9]
That's a good example Neville, very usefull.


wizzlefish(Posted 2005) [#10]
Darn - your code didn't work, although maybe it was how it was implemented. I messed around with my code, and although it still doesn't work, here's what I got:
	If gun=1 
	If ammo >= 1 
	If MouseHit(1)  
		ammo = ammo - 1 
	 	picked = LinePick(400, 300, EntityZ(camera), 1, 1, 10)
	 	p.hole = New hole
	 	p\entityhandle = CopyEntity(bullethole)
	 	p\alpha = 0.9
	 	p\typething = "pistol"
	 	nx# = PickedNX()
     	ny# = PickedNY()
     	nz# = PickedNZ()
		EntityFX p\entityhandle, 16
		PositionEntity p\entityhandle, PickedX() + (PickedNX() * 0.01), PickedY() + (PickedNY() * 0.01), PickedZ() + (PickedNZ() * 0.01)
		AlignToVector p\entityhandle, -PickedNX(), -PickedNY(), -PickedNZ(), 3, 1
		MoveEntity p\entityhandle, 0, 0, -0.05
		e.explosion = New explosion
		e\x = PickedX()
		e\y = PickedY()
		e\z = PickedZ()
		e\entity = CopyEntity(explosion)
	 	Emitter_Start(e\entity)
		PositionEntity e\entity, e\x, e\y, e\z
	EndIf
	EndIf
	EndIf



big10p(Posted 2005) [#11]
Looks like your using LinePick all wrong - are those screen coords you're using with it? Take a look at the docs and have another go. :)


wizzlefish(Posted 2005) [#12]
Well then how would I create a LinePick from the center of the screen?

I looked at the docs, and I'm pretty sure everything but the last two numbers are correct.


DJWoodgate(Posted 2005) [#13]
Well the centre of the screen or viewport should be the centre of the camera. So Entityx(camera,1),Entityy(camera,1),Entityz(camera,1). A linepick uses world coords for the start of the line, you are confusing it with camerapick that uses screen coords. It must be said the docs do not make this very clear.


wizzlefish(Posted 2005) [#14]
Thanks you guys! This might fix everything! :D


wizzlefish(Posted 2005) [#15]
It did!


DJWoodgate(Posted 2005) [#16]
Really? I was forgetting something. That line you are projecting will always be along the z axis. Well in fact it is mostly along the z axis, I do not know why you have the x and y components set to 1 which would push it up and to the right a bit. Now linepick does not know anything about camera orientation so if your camera is facing elsewhere you would also need to do something like Tformvector 0,0,10,camera,0 and then
linepick entityx(camera,1),entityy(camera,1),entityz(camera,1),tformedx(),tformedy(),tformedz().


wizzlefish(Posted 2005) [#17]
Well, it didn't work with Linepick - but it worked with CameraPick :D