3D Graphics
3D Images with Core PHP is a PEAR program and can be obtained here for your server. There is no documentation of this program, so if you decide to dabble think about sharing your experiences at the PEAR site. 3D Images As far as I know at this time, TandemTables.com and the ArborHosting WebbyServer are the only servers to have this program. Canvas With this program you can create the basic forms for 3D figures. They can then be taken into GD scripts and finished and added to, to obtain a finished graphic. The only graphics that can be imported are 3ds. And I have yet to be able to do that. This program is cubes, cones, spheres, and other shapes assembled to produce a 3D figure. The shape arrangement is given lighting effects just asif it were a stage. And colors, sizes, rotation, detail, and position are all controlled by your script. Unlike GD and Ming which have the 0x0 point the upper left corner, for this 0x0 is dead center of the canvas. So if our canvas is 400x400 the 0x0 point is at 200x200. Confusing? Yes, at first. Therefore, if you want to move something to the right give it a plus value, to the left a minus value. If you want to move something down use a plus value and up use a minus value. Working with 3D requires three planes, x, y, and z. X is the width as usual and Y is the height. Z is the same as the z-index in CSS, the layers coming out from the screen toward you. But for this, the layers can also go inside away from you. This is the positive value and coming out from the screen the negative. This is the code that creates the canvas and its color.. $world = new Image_3D(); $world->setColor(new Image_3D_Color(255, 255, 255)); Lighting There are four lighting types.
The colors of the lights and their point, changes the color and shadow of the drawn object. Below, the light is created, and the array represents the x,y,z, position in that order. So the light is 100px from left, 100px from top, and 100px out from the screen. The color is white. $light = $world->createLight('Light', array(-100, -100, -100)); $light->setColor(new Image_3D_Color(255, 255, 255)); The lighting can change the entire view of something. Your object can be white and your lights a combination of colors....so the lights become the color of the objects. Or you can keep to whites in the lighting and make your objects different colors, then of course you can mix them both. Knowing a little about color theory can be very helpful here.... If you want some color info...Color Stuff Sphere Here we create a sphere. The 'r' stand for radius. The 'detail' determines how many polygons will be used to make the sphere. The more detail, the smoother it will be and also the more memory it takes for the server to make it. If you are making a pie chart for a business nice and smooth because it's small. But with drawing an object less detail is used because you have so many more shapes. Good detail is four but with outer layers even 2 is enough. That does not mean it only uses 2 polygons, it means 2 is the basis of the algorythm. $sphere = $world->createObject('sphere', array('r' => 50, 'detail' => 4)); The color is set and it's position determined. This is a white sphere which sits at 0x0 or 200x200 and it is 30 pixel INTO the canvas. Note the sphere may appear as colored when viewed...this is the effect from the lighting. $sphere->setColor(new Image_3D_Color(300, 300, 300)); $sphere->transform($world->createMatrix('Move', array(0, 0, 30))); Cone Here we create a cone with a detail of 10. The color is set. Note: This color value has an Alpha or transparency channel of 100. $cone = $world->createObject('cone', array('detail' => 10)); $cone->setColor(new Image_3D_Color(255, 00, 00, 100)); To obtain the size of the cone we need the radius of the base, the x, how tall it is, the y, and how far it sticks out from the screen, the z. This is done with a 'scale' command. $cone->transform($world->createMatrix('Scale', array(50, 200, 50))); To position the cone, rotation has been added so you can move the point of the cone where you want it. By default the cone points down. Positioning after rotating is tricky as in all these programs. $cone->transform($world->createMatrix('Move', array(0, -80, 0))); $cone->transform($world->createMatrix('Rotation', array(150, 150, 150))); The remainder of the script is output information, the perspective, size, GD use and output to FM. Here ia a working script and it's output. Once you start moving things around you'll see how it goes. Change the layer values, and see what it does, add another cone or sphere...just be sure to give it its own name... http://simplysally.com/GD/lessons/BASIC-3D.zip
|