📄 materialretained.java
字号:
/* * $RCSfile: MaterialRetained.java,v $ * * Copyright (c) 2007 Sun Microsystems, Inc. All rights reserved. * * Use is subject to license terms. * * $Revision: 1.5 $ * $Date: 2007/02/09 17:18:10 $ * $State: Exp $ */package javax.media.j3d;import javax.vecmath.Color3f;import java.util.ArrayList;/** * The MaterialRetained object defines the appearance of an object under * illumination. */class MaterialRetained extends NodeComponentRetained { // Initialize default values for all class variables Color3f ambientColor = new Color3f(0.2f, 0.2f, 0.2f); Color3f emissiveColor = new Color3f(0.0f, 0.0f, 0.0f); Color3f diffuseColor = new Color3f(1.0f, 1.0f, 1.0f); Color3f specularColor = new Color3f(1.0f, 1.0f, 1.0f); float shininess = 64.0f; int colorTarget = Material.DIFFUSE; // Lighting enable switch for this material object boolean lightingEnable = true; // A list of pre-defined bits to indicate which component // in this Material object changed. static final int AMBIENT_COLOR_CHANGED = 0x01; static final int EMISSIVE_COLOR_CHANGED = 0x02; static final int DIFFUSE_COLOR_CHANGED = 0x04; static final int SPECULAR_COLOR_CHANGED = 0x08; static final int SHININESS_CHANGED = 0x10; static final int ENABLE_CHANGED = 0x20; static final int COLORTARGET_CHANGED = 0x40; /** * Constructs and initializes a new material object using the specified * parameters. * @param ambientColor the material's ambient color * @param emissiveColor the material's emissive color * @param diffuseColor the material's diffuse color when illuminated by a * light * @param specularColor the material's specular color when illuminated * to generate a highlight * @param shininess the material's shininess in the * range [1.0, 128.0] with 1.0 being not shiny and 128.0 being very shiny */ void createMaterial(Color3f aColor, Color3f eColor, Color3f dColor, Color3f sColor, float shine) { ambientColor.set(aColor); emissiveColor.set(eColor); diffuseColor.set(dColor); specularColor.set(sColor); shininess = shine; } /** Initializes this material's ambient color * This specifies how much ambient light is reflected by * the surface. The ambient light color is the product of this * color and the material diffuseColor. * @param color the material's ambient color */ final void initAmbientColor(Color3f color) { this.ambientColor.set(color); } /** * Sets this material's ambient color and sends a message notifying * the interested structures of the change. * This specifies how much ambient light is reflected by * the surface. The ambient light color is the product of this * color and the material diffuseColor. * @param color the material's ambient color */ final void setAmbientColor(Color3f color) { initAmbientColor(color); sendMessage(AMBIENT_COLOR_CHANGED, new Color3f(color)); } /** * Sets this material's ambient color * @param r the new ambient color's red component * @param g the new ambient color's green component * @param b the new ambient color's blue component */ final void initAmbientColor(float r, float g, float b) { this.ambientColor.set(r, g, b); } /** * Sets this material's ambient color and sends a message notifying * the interested structures of the change. * @param r the new ambient color's red component * @param g the new ambient color's green component * @param b the new ambient color's blue component */ final void setAmbientColor(float r, float g, float b) { initAmbientColor(r, g, b); sendMessage(AMBIENT_COLOR_CHANGED, new Color3f(r, g, b)); } /** * Retrieves this material's ambient color. * @return the material's ambient color */ final void getAmbientColor(Color3f color) { color.set(this.ambientColor); } /** * Sets this material's emissive color * This is the color of light, if any, that the material emits. * @param color the new emissive color */ final void initEmissiveColor(Color3f color) { this.emissiveColor.set(color); } /** * Sets this material's emissive color and sends a message notifying * the interested structures of the change. * This is the color of light, if any, that the material emits. * @param color the new emissive color */ final void setEmissiveColor(Color3f color) { initEmissiveColor(color); sendMessage(EMISSIVE_COLOR_CHANGED, new Color3f(color)); } /** * Sets this material's emissive color. * This is the color of light, if any, that the material emits. * @param r the new emissive color's red component * @param g the new emissive color's green component * @param b the new emissive color's blue component */ final void initEmissiveColor(float r, float g, float b) { this.emissiveColor.set(r, g, b); } /** * Sets this material's emissive color and sends a message notifying * the interested structures of the change. * This is the color of light, if any, that the material emits. * @param r the new emissive color's red component * @param g the new emissive color's green component * @param b the new emissive color's blue component */ final void setEmissiveColor(float r, float g, float b) { initEmissiveColor(r, g, b); sendMessage(EMISSIVE_COLOR_CHANGED, new Color3f(r, g, b)); } /** * Retrieves this material's emissive color and stores it in the * argument provided. * @param color the vector that will receive this material's emissive color */ final void getEmissiveColor(Color3f color) { color.set(this.emissiveColor); } /** * Sets this material's diffuse color. * This is the color of the material when illuminated by a light source. * @param color the new diffuse color */ final void initDiffuseColor(Color3f color) { this.diffuseColor.set(color); } /** * Sets this material's diffuse color and sends a message notifying * the interested structures of the change. * This is the color of the material when illuminated by a light source. * @param color the new diffuse color */ final void setDiffuseColor(Color3f color) { initDiffuseColor(color); sendMessage(DIFFUSE_COLOR_CHANGED, new Color3f(color)); } /** * Sets this material's diffuse color. * @param r the new diffuse color's red component * @param g the new diffuse color's green component * @param b the new diffuse color's blue component */ final void initDiffuseColor(float r, float g, float b) { this.diffuseColor.set(r, g, b); } /** * Sets this material's diffuse color and sends a message notifying * the interested structures of the change. * @param r the new diffuse color's red component * @param g the new diffuse color's green component * @param b the new diffuse color's blue component */ final void setDiffuseColor(float r, float g, float b) { initDiffuseColor(r, g, b); sendMessage(DIFFUSE_COLOR_CHANGED, new Color3f(r, g, b)); } /** * Sets this material's diffuse color plus alpha. * This is the color of the material when illuminated by a light source. * @param r the new diffuse color's red component * @param g the new diffuse color's green component * @param b the new diffuse color's blue component * @param a the alpha component used to set transparency */ final void initDiffuseColor(float r, float g, float b, float a) { this.diffuseColor.set(r, g, b); } /** * Sets this material's diffuse color plus alpha and sends * a message notifying the interested structures of the change. * This is the color of the material when illuminated by a light source. * @param r the new diffuse color's red component * @param g the new diffuse color's green component * @param b the new diffuse color's blue component * @param a the alpha component used to set transparency */ final void setDiffuseColor(float r, float g, float b, float a) { initDiffuseColor(r, g, b); sendMessage(DIFFUSE_COLOR_CHANGED, new Color3f(r, g, b)); } /** * Retrieves this material's diffuse color. * @param color the vector that will receive this material's diffuse color */ final void getDiffuseColor(Color3f color) { color.set(this.diffuseColor); } /** * Sets this material's specular color. * This is the specular highlight color of the material. * @param color the new specular color */ final void initSpecularColor(Color3f color) { this.specularColor.set(color); } /** * Sets this material's specular color and sends a message notifying * the interested structures of the change. * This is the specular highlight color of the material. * @param color the new specular color */ final void setSpecularColor(Color3f color) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -