TForm
Blitz3D Forums/Blitz3D Programming/TForm
| ||
Hey, i think i'm pretty thick, cause i STILL can't grasp the tfrom thing. The one i'd use to make a quad face the camera. So, anyone up to the challenge of explaining this, simply, to me ? Would be eternally grateful, and it would speed up my particle system probably. |
| ||
Well, to make an entity point at another, tform isn't your only option. I understand what TFormVector() is supposed to do, but I've never been able to get it to work in a satisfactory way for me. There is, of course, PointEntity(), but if you want angle values to work with I suggest looking into DeltaPitch() and DeltaYaw(). |
| ||
Hope this is of some use :)Graphics3D 800,600,16,2 HidePointer camera=CreateCamera() PositionEntity camera,0,0,-4 cube=CreateCube() PositionEntity cube,0,-2,0 EntityColor cube,0,0,255 quad=CreateMesh() surf=CreateSurface(quad) AddVertex surf,0,0,0 ,0,0 AddVertex surf,0,0,0 ,0,0 AddVertex surf,0,0,0 ,0,0 AddVertex surf,0,0,0 ,0,0 AddTriangle surf,2,1,0 AddTriangle surf,3,2,0 EntityColor quad,255,0,0 Repeat ;camera control TurnEntity camera,MouseYSpeed()/5.0,-MouseXSpeed()/5.0,0 MoveMouse 400,300 If KeyDown(200) MoveEntity camera,0,0,0.2 EndIf If KeyDown(208) MoveEntity camera,0,0,-0.2 EndIf If KeyDown(205) MoveEntity camera,0.2,0,0 EndIf If KeyDown(203) MoveEntity camera,-0.2,0,0 EndIf ;make the quad face the camera FaceQuad(quad,camera) RenderWorld Flip Until KeyDown(1) End Function FaceQuad(quad,camera,xsize#=1,ysize#=1) xsize=xsize/2 ysize=ysize/2 surf=GetSurface(quad,1) ;top left corner TFormVector -xsize,-ysize,0,camera,0 x#=EntityX(quad)+TFormedX() y#=EntityY(quad)+TFormedY() z#=EntityZ(quad)+TFormedZ() VertexCoords surf,0,x#,y#,z# ;top right corner TFormVector xsize,-ysize,0,camera,0 x#=EntityX(quad)+TFormedX() y#=EntityY(quad)+TFormedY() z#=EntityZ(quad)+TFormedZ() VertexCoords surf,1,x#,y#,z# ;bottom right corner TFormVector xsize,ysize,0,camera,0 x#=EntityX(quad)+TFormedX() y#=EntityY(quad)+TFormedY() z#=EntityZ(quad)+TFormedZ() VertexCoords surf,2,x#,y#,z# ;bottom left corner TFormVector -xsize,ysize,0,camera,0 x#=EntityX(quad)+TFormedX() y#=EntityY(quad)+TFormedY() z#=EntityZ(quad)+TFormedZ() VertexCoords surf,3,x#,y#,z# End Function |
| ||
That's very nice man, thanks :D. I'll try this method out and compare speeds with my sin/cos methid. Thanks again man!! |
| ||
Here's a way to do it using the AlignToVector command. In this code the cone is being aligned on its Y axis to point at the sphere. Assuming your quad is pointing along its positive local Z axis then you'd use a 3 at the end of the AlignToVector command instead of a 2. You can also add a tween value from 0.0 to 1.0 at the end of the AlignToVector command to smooth out the rate of alignment. Check out the AlignToVector command docs for more info on this. Graphics3D 800,600 light = CreateLight () TurnEntity light, 45.0, 0.0, 0.0, True camera = CreateCamera () CameraZoom camera, 1.6 TurnEntity camera, -90.0, 0.0, 0.0, True MoveEntity camera, 0.0, 0.0, -30.0 cone = CreateCone ( 8, True ) MoveEntity cone, 0.0, 0.0, 5.0 sphere = CreateSphere ( 16 ) ;MoveEntity sphere, 0.0, 0.0, -2.5 While Not KeyHit ( 1 ) ; -- Move the cone by pressing the arrow keys. If KeyDown( 200 ) ; The up arrow key. MoveEntity cone, 0.0, 0.0, 0.2 EndIf If KeyDown( 208 ) ; The down arrow key. MoveEntity cone, 0.0, 0.0, -0.2 EndIf If KeyDown( 205 ) ; The right arrow key. MoveEntity cone, 0.2, 0.0, 0.0 EndIf If KeyDown( 203 ) ; The left arrow key. MoveEntity cone, -0.2, 0.0, 0.0 EndIf ;^^^^^^ ; -- Align the y axis of the cone to point towards the sphere. AlignToVector cone, EntityX# ( sphere, True ) - EntityX# ( cone, True ), EntityY# ( sphere, True ) - EntityY# ( cone, True ), EntityZ# ( sphere, True ) - EntityZ# ( cone, True ), 2 ; Use a 3 at the end here to align the z axis instead. ;^^^^^^ UpdateWorld RenderWorld Flip Wend End |
| ||
I can't align to vector because it's a single surface particle system. I'm using 2 tri's, 4 vertexs to make up a face. It's all part of the one mesh. Thanks anyway man :) |