// ----------------------------------------------------------------------- // CONSTRUCTOR: // ----------------------------------------------------------------------- // ! Constructor of cMaterial. public JMaterial() { // default graphic settings ambient = new JColorf(); ambient.set(0.5f, 0.5f, 0.5f, 1.0f); diffuse = new JColorf(); diffuse.set(0.7f, 0.7f, 0.7f, 1.0f); specular = new JColorf(); specular.set(0.4f, 0.4f, 0.4f, 1.0f); emission = new JColorf(); emission.set(0.4f, 0.4f, 0.4f, 1.0f); shininess = 64; // default haptic settings viscosity = 0.0; stiffness = 0.0; staticFriction = 0.0; dynamicFriction = 0.0; vibrationFrequency = 0.0; vibrationAmplitude = 0.0; stickSlipForceMax = 0.0; stickSlipStiffness = 0.0; }
/** Render this material in OpenGL2. */ public void render() { GL2 gl = GLContext.getCurrent().getGL().getGL2(); gl.glEnable(GL2.GL_COLOR_MATERIAL); gl.glMaterialfv(GL2.GL_FRONT_AND_BACK, GL2.GL_AMBIENT, ambient.getComponents(), 0); gl.glMaterialfv(GL2.GL_FRONT_AND_BACK, GL2.GL_DIFFUSE, diffuse.getComponents(), 0); gl.glMaterialfv(GL2.GL_FRONT_AND_BACK, GL2.GL_SPECULAR, specular.getComponents(), 0); gl.glMaterialfv(GL2.GL_FRONT_AND_BACK, GL2.GL_EMISSION, emission.getComponents(), 0); gl.glMateriali(GL2.GL_FRONT_AND_BACK, GL2.GL_SHININESS, shininess); }
/** * //! set transparency level (sets the alpha value for all color properties). * * @param aLevelTransparency */ public void setTransparencyLevel(float aLevelTransparency) { // make sur value is in range [0.0 - 1.0] float level = JMaths.jClamp(aLevelTransparency, 0.0f, 1.0f); // apply new value ambient.setA(level); diffuse.setA(level); specular.setA(level); emission.setA(level); }
// ! tells you whether this material includes partial transparency. public final boolean isTransparent() { return (ambient.getA() < 1.0f || diffuse.getA() < 1.0f || specular.getA() < 1.0f || emission.getA() < 1.0f); }