📄 texturedplane.java
字号:
// TexturedPlane.java
// Andrew Davison, March 2003, dandrew@ratree.psu.ac.th
/* Creates a single quad array of 4 vertices with a texture mapping.
This is a non-animation version of ImagesSeries from /Shooter3D
*/
import javax.vecmath.*;
import javax.media.j3d.*;
import com.sun.j3d.utils.geometry.*;
import com.sun.j3d.utils.image.*;
public class TexturedPlane extends Shape3D
{
private static final int NUM_VERTS = 4;
public TexturedPlane(Point3f p1, Point3f p2, Point3f p3, Point3f p4,
String fnm)
{ createGeometry(p1, p2, p3, p4);
createAppearance(fnm);
} // end of TexturedPlane()
private void createGeometry(Point3f p1, Point3f p2, Point3f p3, Point3f p4)
{
QuadArray plane = new QuadArray(NUM_VERTS,
GeometryArray.COORDINATES |
GeometryArray.TEXTURE_COORDINATE_2 );
// anti-clockwise from bottom left
plane.setCoordinate(0, p1);
plane.setCoordinate(1, p2);
plane.setCoordinate(2, p3);
plane.setCoordinate(3, p4);
TexCoord2f q = new TexCoord2f();
q.set(0.0f, 0.0f);
plane.setTextureCoordinate(0, 0, q);
q.set(1.0f, 0.0f);
plane.setTextureCoordinate(0, 1, q);
q.set(1.0f, 1.0f);
plane.setTextureCoordinate(0, 2, q);
q.set(0.0f, 1.0f);
plane.setTextureCoordinate(0, 3, q);
setGeometry(plane);
} // end of createGeometry()
private void createAppearance(String fnm)
{
System.out.println("Loading texture from " + fnm);
TextureLoader loader = new TextureLoader(fnm, null);
ImageComponent2D im = loader.getImage();
if(im == null)
System.out.println("Load failed for texture: " + fnm);
else {
Appearance app = new Appearance();
// blended transparency so texture can be irregular
TransparencyAttributes tra = new TransparencyAttributes();
tra.setTransparencyMode( TransparencyAttributes.BLENDED );
app.setTransparencyAttributes( tra );
// Create a two dimensional texture
// Set the texture from the first loaded image
Texture2D texture = new Texture2D(Texture2D.BASE_LEVEL, Texture.RGBA,
im.getWidth(), im.getHeight());
texture.setImage(0, im);
app.setTexture(texture);
setAppearance(app);
}
} // end of createAppearance()
} // end of TexturedPlane class
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -