Align a quad to vector
Blitz3D Forums/Blitz3D Beginners Area/Align a quad to vector
| ||
lol, just gotta say, Ive been here for 17 hours, my fingers hurt and I love it!! Anyways, I created a quad to represent a shadow on a mesh terrain and I use linepick and aligntovector to orient the quad with the underlying terrain. The problem is the quad moves off center of the sphere, raises and lowers on the y-axis. I dont understand any of this. When I use a flattened sphere mesh to represent the shadow and the same exact linepick and aligntovector code, it works perfectly. Is it something Im doing wrong in making the quad? heres the code... ;Blob Shadow Using Quad Mesh with Mesh Terrain Xample ;By Xyle ;9-2-06 Graphics3D 1024,768,32,1 SetBuffer BackBuffer () Sphere = CreateSphere() PositionEntity Sphere,577,3,1378 ScaleEntity Sphere,3,3,3 Shdw = CreateQuad() ShdwTex = LoadTexture("Shadow.png",2) ;Used flag 2 for alpha EntityFX Shdw,16 EntityTexture Shdw,ShdwTex PositionEntity Shdw,EntityX(Sphere,True)-8,EntityY(Sphere,True)-45,EntityZ(Sphere,True)-8 Terr = LoadMesh("Terrain.x") PositionEntity Terr, 0,0,0 ScaleEntity Terr,5,5,5 EntityPickMode Terr,2 Cam = CreateCamera() PositionEntity Cam,EntityX(Sphere,True)-40,EntityY(Sphere,True)+100,EntityZ(Sphere,True)-40 CameraRange Cam,1,2000 PointEntity Cam,Sphere Lit = CreateLight() PositionEntity Lit,EntityX(Sphere,True),EntityY(Sphere,True)+150,EntityZ(Sphere,True) PointEntity Lit,Terr CamPiv = CreatePivot() PositionEntity CamPiv,EntityX(Sphere,True),EntityY(Sphere,True),EntityZ(Sphere,True) EntityParent Cam,CamPiv EntityParent CamPiv,Sphere While Not KeyHit(1) Cls x# = 0 z# = 0 pitch# = 0 yaw# = 0 roll# = 0 If KeyDown(208) Then pitch# = -1 If KeyDown(200) Then pitch# = 1 If KeyDown(203) Then yaw# = -1 If KeyDown(205) Then yaw# = 1 If KeyDown(17) Then z# = 1 If KeyDown(31) Then z# = -1 If KeyDown(30) Then x# = -1 If KeyDown(32) Then x# = 1 MoveEntity Sphere,x#,0,z# TurnEntity CamPiv,pitch#,yaw#,roll# SphereX# = EntityX(Sphere,True) SphereY# = EntityY(Sphere,True) SphereZ# = EntityZ(Sphere,True) Temp = 0 Temp = LinePick(SphereX,SphereY,SphereZ, 0, -2000, 0 ) PositionEntity Sphere,SphereX#,PickedY()+6,SphereZ# AlignToVector( Shdw, PickedNX(), PickedNY(), PickedNZ(),2,1 ) ;TurnEntity Shdw,0,180,0 ;MoveEntity Shdw,0,0,0.05 PositionEntity Shdw,EntityX(Sphere,True)-8,EntityY(Sphere,True)-45,EntityZ(Sphere,True)-8 UpdateWorld RenderWorld Flip ;Vsync on Wend End Function CreateQuad() ;Compliments of jfk EO-11110 mesh=CreateMesh() surf=CreateSurface(mesh) ;Texture Coords ;(0,0) ... (1,0) ; . . ; . . ; . . ;(0,1) ... (1,1) v0=AddVertex(surf, 0,40,0, 0,1) v1=AddVertex(surf, 31,40,0, 1,1) v2=AddVertex(surf, 0,40,31, 0,0) v3=AddVertex(surf, 31,40,31, 1,0) AddTriangle(surf,v0,v2,v1) AddTriangle(surf,v1,v2,v3) UpdateNormals mesh Return mesh End Function or you can download the project here http://www.hilbily-works.com/Downloads1/Blob_Shadow_wQuad_wMeshTerrain.zip any help would be greatly appreciated!! [Edit] oops, you need to comment out ;TurnEntity Shdw,0,180,0 ;MoveEntity Shdw,0,0,0.05 right after the linepicking, I used this to see if it would fix the problem. |
| ||
As far as being offcenter of the sphere, try this:PositionEntity Shdw,EntityX(Sphere,True)-MeshWidth(Sphere)/2,EntityY(Sphere,True)-5.9,EntityZ(Sphere,True)-MeshWidth(Sphere)/2 As an aside: I don't understand why you created your quad 40 units along the positive Y-axis. You could have done this: v0=addvertex(surf,0,0,0) v1=addvertex(surf,0,0,31) v2=addvertex(surf,31,0,31) v3=addvertex(surf,31,0,0) addtriangle(surf,v0,v1,v2) addtriangle(surf,v0,v2,v3) This would put the first vertex (v0) comfortably at the origin 0,0,0. Much easier to transform, IMO. |
| ||
Kevin thanks for the help there, I created the quad on they y axis like that due to placement around the sphere in the beginning stages of the program, since then I modified the sphere placement, terrain placement and never updated the quad generation code. Everything seemed to work ok except the positionentity you have. I had to multiply * 4 to get the shadow to be under the sphere. It all worked great except the y value of the shadow, something seems to get all buggered up after a linepick because the shadow quad moves up and down along the y axis. I gave up on trying to fix the Blitz3d created quad and just made a quad model, textured and exported to b3d. It works great, just need to figure out this alpha channel transparancy thing, lol. Thanks for the help there! |