Package edu.cnu.mdi.mdi3D.item3D
Class Sphere
java.lang.Object
edu.cnu.mdi.mdi3D.item3D.Item3D
edu.cnu.mdi.mdi3D.item3D.Sphere
A solid sphere, optionally with drawn latitude/longitude gridlines and
optional Phong-style lighting.
-
Field Summary
Fields inherited from class edu.cnu.mdi.mdi3D.item3D.Item3D
_panel3D, FILLALPHA, FILLCOLOR, FONT, LINE_WIDTH, LINEALPHA, LINECOLOR, TEXT_COLOR -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoiddraw(com.jogamp.opengl.GLAutoDrawable drawable) The custom drawing methodfloat[]A representative point for transparent sorting, in world coordinates.booleanWhether Phong-style lighting is enabled for this sphere.voidsetCenter(float x, float y, float z) Set the center of the sphere.voidsetGridColor(Color gridColor) Set the color of the gridlines.voidsetGridlines(float[] theta, float[] phi) Set the gridlines for the sphere.voidsetLighted(boolean lighted) Enable or disable Phong-style lighting for this sphere.voidsetResolution(int slices, int stacks) Set the resolution of the sphere.Methods inherited from class edu.cnu.mdi.mdi3D.item3D.Item3D
addChild, defaultProperties, dispose, disposeItem, drawItem, get, getChildren, getColor, getFillAlpha, getFillColor, getFloat, getFont, getFont, getInt, getLineAlpha, getLineColor, getLineWidth, getPanel3D, getParent, getString, getTextColor, isVisible, put, removeChild, setAlphaOfColor, setFillAlpha, setFillColor, setFont, setLineAlpha, setLineColor, setLineWidth, setTextColor, setVisible
-
Constructor Details
-
Sphere
Constructor for a Sphere item in 3D space.- Parameters:
panel3D- The parent 3D panelx- X coordinate of the centery- Y coordinate of the centerz- Z coordinate of the centerradius- Radius of the spherecolor- Color of the sphere
-
-
Method Details
-
setCenter
public void setCenter(float x, float y, float z) Set the center of the sphere.- Parameters:
x- X coordinatey- Y coordinatez- Z coordinate
-
setResolution
public void setResolution(int slices, int stacks) Set the resolution of the sphere. Higher values for slices and stacks result in a smoother sphere.- Parameters:
slices- Number of slices (longitude divisions)stacks- Number of stacks (latitude divisions)
-
setGridlines
public void setGridlines(float[] theta, float[] phi) Set the gridlines for the sphere.- Parameters:
theta- Array of polar angles [0, π]phi- Array of azimuthal angles [-π, π]
-
setGridColor
Set the color of the gridlines.- Parameters:
gridColor- The gridline color
-
setLighted
public void setLighted(boolean lighted) Enable or disable Phong-style lighting for this sphere.When enabled, the sphere is drawn via
Support3D.solidShadedSphere(GLAutoDrawable, float, float, float, float, int, int, Color, boolean)with a fixed directional light, so its shading visibly changes as the sphere (or the scene around it) rotates. Disabled by default, matching the flat-colour appearance existing callers already expect.- Parameters:
lighted-trueto enable lighting;falsefor flat colour
-
isLighted
public boolean isLighted()Whether Phong-style lighting is enabled for this sphere.- Returns:
trueif lighting is enabled
-
draw
public void draw(com.jogamp.opengl.GLAutoDrawable drawable) Description copied from class:Item3DThe custom drawing method -
getSortPoint
public float[] getSortPoint()Description copied from class:Item3DA representative point for transparent sorting, in world coordinates. Default is origin. Override in items with a natural center (Sphere, Cube, Cylinder, etc.).- Overrides:
getSortPointin classItem3D- Returns:
- the sort point as
[x, y, z]
-