Shape editor
Blitz3D Forums/Blitz3D Programming/Shape editor
| ||
Hi all. I'm looking at creating a simple shape editor for a custom level editor i am making. I want to be able to use a square (cube or plane) and move the corners to make it irregular, how can i do this? Ideally i want to this with planes rather then flat cubes, can Blitz create multiple planes of curtain sizes rather then just the infinate one? Any help would be great. |
| ||
You want to create a quad. Create a surface with 4 vertices, at (-1,-1), (-1,1), (1,-1) and (1,1). Make two triangles that divide the quad in half. You can then easily make irregular quads by moving the vertices using VertexCoords(). Look up the manual's sections on surfaces, particularly AddVertex() and AddTriangle(). |
| ||
I'm having trouble getting anything to display. I have to be honest im not sure im doing it write. Heres what i have: ; Sets 3D graphics mode Graphics3D 640,480,16,0 SetBuffer BackBuffer() camera=CreateCamera() light=CreateLight() PositionEntity (camera, 4,4,4) ;Create a mesh water_mesh = CreateMesh() ;create a surface and attach to mesh water_surface = CreateSurface(water_mesh) ;create 3 vertex water_vertex1 = AddVertex(water_surface, 0,0,0) water_vertex2 = AddVertex(water_surface, 2,2,2) water_vertex3 = AddVertex(water_surface, 3,3,3) water_triangle = AddTriangle(water_surface, water_vertex1, water_vertex2, water_vertex3) brush=CreateBrush(120,120,5) PaintMesh(water_mesh, brush) While Not KeyDown( 1 ) RenderWorld Flip Wend End Any help! |
| ||
1) your vertices are in a straight line i.e. a very thin triangle which will be hard to see at all 2) your camera is in front of the triangle and also too high above the triangle in any case, so it can't see it 3) you don't need to assign a variable to each vertex you create 4) AddTriangle does not take those variables you assigned, it just needs the index number of each vertex With as few changes as required here is the result... ; Sets 3D graphics mode Graphics3D 640,480,16,0 SetBuffer BackBuffer() camera=CreateCamera() light=CreateLight() PositionEntity (camera, 0,1,-4) ;Create a mesh water_mesh = CreateMesh() ;create a surface and attach to mesh water_surface = CreateSurface(water_mesh) ;create 3 vertex in clockwise order, a triangle facing upwards AddVertex(water_surface, 0,0,0) ;this is vertex 0 AddVertex(water_surface, 0,0,1) ;this is vertex 1 AddVertex(water_surface, 1,0,1) ;this is vertex 2 water_triangle = AddTriangle(water_surface, 0,1,2) brush=CreateBrush(120,120,5) PaintMesh(water_mesh, brush) While Not KeyDown( 1 ) RenderWorld Flip Wend End |
| ||
Also, the triangle will not be lit by your light because 1) The vertices do not have any normals 2) The directional light you created is not pointing at the triangle To fix this I gave each vertex a normal which pointed up and changed the light to a point light then moved it above the triangle. This must be alot to take in but stick with it! ;) ; Sets 3D graphics mode Graphics3D 640,480,16,0 SetBuffer BackBuffer() camera=CreateCamera() light=CreateLight(2); create a point light, this sends light in all directions PositionEntity (camera, 0,1,-4) PositionEntity light,0,100,0 ;move light above the triangle ;Create a mesh water_mesh = CreateMesh() ;create a surface and attach to mesh water_surface = CreateSurface(water_mesh) ;create 3 vertex AddVertex(water_surface, 0,0,0):VertexNormal(water_surface,0,0,1,0) ;vertex 0 and normal AddVertex(water_surface, 0,0,1):VertexNormal(water_surface,1,0,1,0) ;vertex 1 and normal AddVertex(water_surface, 1,0,1):VertexNormal(water_surface,2,0,1,0) ;vertex 2 and normal water_triangle = AddTriangle(water_surface, 0,1,2) brush=CreateBrush(120,120,5) PaintMesh(water_mesh, brush) While Not KeyDown( 1 ) RenderWorld Flip Wend End |
| ||
Grovesy : Your coordinate values are very iffy. You use the same value for x, y, and z positions, in the vertices and the camera. Are you sure your happy with the idea of coordinates? Ordinarily the camera is placed at 0,0,-100, or whatever distance, leaving x and y as the horizontal and vertical axis relative to the screen. This'll match up with 2D coordinates, although by default unlike 2D the centre of the screen is (0,0) rather than the top left. If you wanted to draw a square in the middle of the screen, you'd position the corners at Top Left : (-1,1) Top Right : (1,1) Bottom Left : (-1,-1) Bottom Right : (1,-1) Once you've created a little mesh you can use ScaleMesh to move the vertices out further. eg ScaleMesh water_mesh,10,10,10 would move the vertices to Top Left : (-10,10) Top Right : (10,10) Bottom Left : (-10,-10) Bottom Right : (10,-10) Your coordinates would be similar in 2D to three points at (0,0), (2,2) and (3,3), which I'm sure you see is a straight line. |
| ||
You can use updatenormals() command if you want, rather than manually creating them. |