Java Reference
In-Depth Information
The mapping of the points on the surface to a point on the images is the job of the TriangleMesh . We built a
MeshView with a user-defined TriangleMesh earlier in this chapter. In fact, the predefined 3D shapes are also based
on TriangleMesh es internally. Therefore they are also capable of being texturized. Recall that in TriangleMesh , each
face is defined by six indices: p0 , t0 , p1 , t1 , p2 , t2 , where p0 , p1 , p2 are indices into the points array, and t0 , t1 , t2 are
indices into the texCoords array. Looking up the texCoords array with t0 , t1 , t2 we get the ( u0 , v0 ), ( u1 , v1 ), and ( u2 ,
v2 ) coordinates. The triangular portion of the image determined by these three coordinates is mapped to the face of
the 3D shape.
In the program in Listing 10-8, we use a world map image as the diffuseMap of a sphere to make a globe.
Listing 10-8. EarthSphere.java
import javafx.application.Application;
import javafx.beans.property.DoubleProperty;
import javafx.beans.property.SimpleDoubleProperty;
import javafx.scene.Group;
import javafx.scene.PerspectiveCamera;
import javafx.scene.PointLight;
import javafx.scene.Scene;
import javafx.scene.image.Image;
import javafx.scene.input.MouseEvent;
import javafx.scene.paint.Color;
import javafx.scene.paint.PhongMaterial;
import javafx.scene.shape.Sphere;
import javafx.scene.transform.Rotate;
import javafx.stage.Stage;
public class EarthSphere extends Application {
double anchorX, anchorY;
private double anchorAngleX = 0;
private double anchorAngleY = 0;
private final DoubleProperty angleX = new SimpleDoubleProperty(0);
private final DoubleProperty angleY = new SimpleDoubleProperty(0);
PerspectiveCamera scenePerspectiveCamera = new PerspectiveCamera(false);
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage stage) {
stage.setTitle("EarthSphere");
Image diffuseMap = new Image(EarthSphere.class
.getResource("earth-mercator.jpg")
.toExternalForm());
PhongMaterial earthMaterial = new PhongMaterial();
earthMaterial.setDiffuseMap(diffuseMap);
 
Search WWH ::




Custom Search