creating an animated terrain
Blitz3D Forums/Blitz3D Beginners Area/creating an animated terrain
| ||
I want to make some animating water. I have three terrain .bmp's. I want to load one, set an animation key, load another, set another animation key, then load the final terrain, set an animation key, and finally animate the terrain. This is the code I have so far, but it is not working. Could you please tell me why and how to fix it? Function createmywater() s=LoadTerrain("watert1.bmp") ScaleEntity s,2,2,2 PositionEntity s,-512,-8,-512 EntityColor s,50,80,140 EntityAlpha s,.3 SetAnimKey s,0 s=0 s=LoadTerrain("watert2.bmp") ScaleEntity s,2,2,2 PositionEntity s,-512,-8,-512 EntityColor s,50,80,140 EntityAlpha s,.3 SetAnimKey s,10 s=0 s=LoadTerrain("watert3.bmp") ScaleEntity s,2,2,2 PositionEntity s,-512,-8,-512 EntityColor s,50,80,140 EntityAlpha s,.3 SetAnimKey s,20 seq=AddAnimSeq(s,20) Animate s,1,1,0 End Function Any help or advise would be greatly appreiciated! |
| ||
I don't think you can set animkey's with a blitz terrain. You would need to build the terrain using the blitz commands to construct a mesh, positioning each vertex from each pixel of the bitmap. |
| ||
Ok, i've edited this post and created a better function. It's basically an updated load terrain function, that produces a mesh, rather than a blitz terrain. It works exactly the same as the load terrain command, except it will centre your mesh and takes any bitmap. It doesn't need to be square. This is all you need to do: global terrain = load_terrain("heightmap.bmp") The function you copy into your code... Function load_terrain(file$) temp = LoadImage(file$) If temp = 0 Then Return 0 x = ImageWidth(temp) y = ImageHeight(temp) mesh = CreateMesh() surf = CreateSurface(mesh) For ly = 0 To y For lx = 0 To x AddVertex surf,lx , 0, ly, 1.0/lx, 1.0/ly Next Next RenderWorld For ly = 0 To y-1 For lx = 0 To x-1 AddTriangle surf, lx + ((x+1)*ly), lx + ((x+1)*ly) + (x+1), (lx+1) + ((x+1)*ly) AddTriangle surf, (lx+1) + ((x+1)*ly), lx + ((x+1)*ly) + (x+1), (lx+1) + ((x+1)*ly) + (x+1) Next Next PositionMesh mesh, -x/2.0,0,-y/2.0 SetBuffer ImageBuffer(temp) For lx = 0 To x For ly = 0 To y GetColor lx,ly index = lx + ((x+1)*ly) VertexCoords surf, index , VertexX(surf,index), ColorRed()/20.0, VertexZ(surf,index) Next Next SetBuffer BackBuffer() UpdateNormals mesh End Function |
| ||
Thanks! Now, how could I load all three terrain meshes and animate between them. Sorry if it seems like I am making you do all of the work, but I have no idea how to do it and it would help me a lot in this and many other situations. |
| ||
i dunno really, i've never used to setanimkey function :o) Does the above not do what you need? I'm not quite sure how it actualy works... |
| ||
Have a look at the setanimkey command, in the manual. It seems to have a piece of code to set up a bouncing ball animation, using setanimkey(). :o) |
| ||
Look at my origonal code. I already used setanimkey. The problem is that I want to load one, then set a key, then delete that mesh from the s variable, then load another and set another key. The problem I am having is the part were I have to free the previous mesh from the first key and replace it with a different one for the second key while working from inside the s variable the whole time so that I don't free the entire variable so the keys that were already set are not lost. I know this might sound confusing, but really it is quite simple. The only problem is that I don't know how to say it very clearly. Sorry, if anyone knows what I am talking about please clarify for those who don't. |
| ||
Does the above not do what you need? I'm not quite sure how it actualy works... The above code helps a lot, so thanks, but it only goes half way, I still need help on the animation part (as stated above). |