Reshaping an object works in much the same ways as scaling or resizing in that it uses the ScaleEntity command. The difference this time is that if you want to stretch or squish an object, the number that you enter for the x, y, and z values will be different. Let’s go back and open the saved version of the “cone” file we created earlier to illustrate how we reshape our object. With this code, we will stretch the cone along the y axis.
cone = CreateCone() PositionEntity cone,0,0,5 ScaleEntity cone, 1,2,1
We entered the numbers 1,2,1 which mean we are going to scale the x axis by multiplying it by 1 (which will result in no change, because any number multiplied by 1 remains the same), multiplying the y axis by 2, which will double the size of the shape along the y axis, and multiplying the z axis by 1. The result is that we end up with a cone that has been stretched along the y axis, as seen in Figure 5.13.
Note: Now You Try
Take a look at Figure 5.13, which is an image of a cylinder that has been stretched along one axis and reduced along another. Try to re-create this effect and then compare it to the actual code below.
; demo05-04.bb - Resizing a cone ; ------------------ Graphics3D 640,480 SetBuffer BackBuffer() Const ESC_KEY = 1 ; Create camera camera = CreateCamera() ; Create a light light = CreateLight() ;Create the cone cone=CreateCone() PositionEntity cone,0,0,5 ScaleEntity cone, 3,0.5,1 ; This following code makes our program run While Not KeyDown(ESC_KEY) RenderWorld Flip Wend End
Figure 5.14 shows what this program looks like when run.
3.147.28.206