diff --git a/.settings/org.eclipse.core.resources.prefs b/.settings/org.eclipse.core.resources.prefs index 5f2b8dc..65854de 100644 --- a/.settings/org.eclipse.core.resources.prefs +++ b/.settings/org.eclipse.core.resources.prefs @@ -1,2 +1,4 @@ eclipse.preferences.version=1 encoding//src/main/java/org/ntlab/radishforandroidstudio/framework/model3D/ModelFactory.java=UTF-8 +encoding//src/main/java/org/ntlab/radishforandroidstudio/framework/model3D/Universe.java=UTF-8 +encoding//src/main/java/org/ntlab/radishforandroidstudio/java3d/Box.java=UTF-8 diff --git a/src/main/java/org/ntlab/radishforandroidstudio/framework/model3D/IViewer3D.java b/src/main/java/org/ntlab/radishforandroidstudio/framework/model3D/IViewer3D.java deleted file mode 100644 index d77cd00..0000000 --- a/src/main/java/org/ntlab/radishforandroidstudio/framework/model3D/IViewer3D.java +++ /dev/null @@ -1,18 +0,0 @@ -package org.ntlab.radishforandroidstudio.framework.model3D; - -import org.ntlab.radishforandroidstudio.java3d.GraphicsContext3D; -import org.ntlab.radishforandroidstudio.java3d.Light; -import org.ntlab.radishforandroidstudio.java3d.Node; -import org.ntlab.radishforandroidstudio.java3d.Transform3D; - -import java.util.ArrayList; - -public interface IViewer3D { - public abstract void setGraphicsContext3D(GraphicsContext3D gc3D); - public abstract void surfaceChanged(int width, int height); - public abstract void onDrawFrame(); - public abstract void update(ArrayList lights, BackgroundBox skyBox); - public abstract void pushTransform(Transform3D t); - public abstract void popTransform(); - public abstract void draw(Node obj); -} diff --git a/src/main/java/org/ntlab/radishforandroidstudio/framework/model3D/ModelFactory.java b/src/main/java/org/ntlab/radishforandroidstudio/framework/model3D/ModelFactory.java index d1d815a..4e1e440 100644 --- a/src/main/java/org/ntlab/radishforandroidstudio/framework/model3D/ModelFactory.java +++ b/src/main/java/org/ntlab/radishforandroidstudio/framework/model3D/ModelFactory.java @@ -17,7 +17,6 @@ import org.ntlab.radishforandroidstudio.java3d.IndexedGeometryArray; import org.ntlab.radishforandroidstudio.java3d.IndexedTriangleArray; import org.ntlab.radishforandroidstudio.java3d.Material; -import org.ntlab.radishforandroidstudio.java3d.TextureLoader; import org.ntlab.radishforandroidstudio.java3d.TriangleArray; import org.ntlab.radishforandroidstudio.java3d.Vector2f; import org.ntlab.radishforandroidstudio.java3d.Vector3f; @@ -849,8 +848,8 @@ String texFileName = line.substring(line.indexOf(" ") + 1); String texFilePath = new File(dir, texFileName).getPath(); InputStream inTex = new FileInputStream(new File(texFilePath)); - TextureLoader texLoader = new TextureLoader(inTex, TextureLoader.BY_REFERENCE | TextureLoader.Y_UP); - ap.setTexture(texLoader.getTexture()); +// TextureLoader texLoader = new TextureLoader(inTex, TextureLoader.BY_REFERENCE | TextureLoader.Y_UP); +// ap.setTexture(texLoader.getTexture()); inTex.close(); } catch (IOException e) { System.out.println("Not exist texture file: " + line.substring(line.indexOf(" ") + 1)); diff --git a/src/main/java/org/ntlab/radishforandroidstudio/framework/model3D/Universe.java b/src/main/java/org/ntlab/radishforandroidstudio/framework/model3D/Universe.java index 258e7dd..2bcc0da 100644 --- a/src/main/java/org/ntlab/radishforandroidstudio/framework/model3D/Universe.java +++ b/src/main/java/org/ntlab/radishforandroidstudio/framework/model3D/Universe.java @@ -22,44 +22,7 @@ public Universe() { root = new BranchGroup(); } - - public void render(IViewer3D viewer) { - viewer.update(lights, skyBox); - render(viewer, root); - } - - private void render(IViewer3D viewer, Node node) { - if (node instanceof Group) { - if (node instanceof Primitive) { - viewer.draw((Primitive) node); - } else { - if (node instanceof TransformGroup) { - Transform3D transform = new Transform3D(); - ((TransformGroup) node).getTransform(transform); - // -// Vector3d vec = new Vector3d(1.0, 1.1, 1.0); -// transform.setScale(vec); -// AxisAngle4d aa = new AxisAngle4d(0.0, 0.0, 1.0, 1.0); -// transform.setRotation(aa); - // - viewer.pushTransform(transform); - for (int i = 0; i < ((Group) node).numChildren(); i++) { - Node node2 = ((Group) node).getChild(i); - render(viewer, node2); - } - viewer.popTransform(); - } else { - for (int i = 0; i < ((Group) node).numChildren(); i++) { - Node node2 = ((Group) node).getChild(i); - render(viewer, node2); - } - } - } - } else if (node instanceof Leaf) { - viewer.draw(node); - } - } - + public void update(long interval){ for(int i = 0; i < movableList.size(); i++){ Movable movable = movableList.get(i); @@ -68,10 +31,10 @@ } /** - * オブジェクトを配置する + * 繧ェ繝悶ず繧ァ繧ッ繝医r驟咲スョ縺吶k * * @param obj - * 配置するオブジェクト + * 驟咲スョ縺吶k繧ェ繝悶ず繧ァ繧ッ繝� */ public void place(Placeable obj) { if(obj instanceof Ground){ @@ -88,10 +51,10 @@ } /** - * 後で取り除けるようにオブジェクトを配置する + * 蠕後〒蜿悶j髯、縺代k繧医≧縺ォ繧ェ繝悶ず繧ァ繧ッ繝医r驟咲スョ縺吶k * * @param obj - * 配置するオブジェクト + * 驟咲スョ縺吶k繧ェ繝悶ず繧ァ繧ッ繝� */ public void placeDisplacable(Placeable obj) { placeDisplacable(obj.getTransformGroupToPlace()); @@ -102,10 +65,10 @@ } /** - * 光源の追加 + * 蜈画コ舌�ョ霑ス蜉� * * @param light - * 追加する光源 + * 霑ス蜉�縺吶k蜈画コ� */ public void placeLight(Light light) { root.addChild(light); @@ -113,8 +76,8 @@ } /** - * スカイボックスの追加 - * @param skyBox 追加するスカイボックス + * 繧ケ繧ォ繧、繝懊ャ繧ッ繧ケ縺ョ霑ス蜉� + * @param skyBox 霑ス蜉�縺吶k繧ケ繧ォ繧、繝懊ャ繧ッ繧ケ */ public void placeSkyBox(BackgroundBox skyBox) { root.addChild(skyBox); @@ -122,10 +85,10 @@ } /** - * オブジェクトを可能ならば取り除く + * 繧ェ繝悶ず繧ァ繧ッ繝医r蜿ッ閭ス縺ェ繧峨�ー蜿悶j髯、縺� * * @param obj - * 取り除くオブジェクト + * 蜿悶j髯、縺上が繝悶ず繧ァ繧ッ繝� */ public void displace(Placeable obj) { displace(obj.getTransformGroupToPlace()); diff --git a/src/main/java/org/ntlab/radishforandroidstudio/framework/view3D/Camera3D.java b/src/main/java/org/ntlab/radishforandroidstudio/framework/view3D/Camera3D.java deleted file mode 100644 index ba415e9..0000000 --- a/src/main/java/org/ntlab/radishforandroidstudio/framework/view3D/Camera3D.java +++ /dev/null @@ -1,459 +0,0 @@ -package org.ntlab.radishforandroidstudio.framework.view3D; - -import java.util.ArrayList; - -import org.ntlab.radishforandroidstudio.framework.model3D.GeometryUtility; -import org.ntlab.radishforandroidstudio.framework.model3D.Object3D; -import org.ntlab.radishforandroidstudio.framework.model3D.Placeable; -import org.ntlab.radishforandroidstudio.framework.model3D.Position3D; -import org.ntlab.radishforandroidstudio.framework.model3D.Universe; -import org.ntlab.radishforandroidstudio.java3d.Transform3D; -import org.ntlab.radishforandroidstudio.java3d.TransformGroup; -import org.ntlab.radishforandroidstudio.java3d.Vector3d; - -/** - * 画角調整機能が付いたカメラ
- * 視点、注視対象、視線のうち2つを指定して使う。 - * @author 新田直也 - * - */ -public class Camera3D { - private static final double NEAREST = 3.0; - private static final Vector3d VIEW_FORWARD = new Vector3d(0.0, 0.0, -1.0); - private static final Vector3d VIEW_DOWN = new Vector3d(0.0, -1.0, 0.0); - - private Universe universe = null; - - private double frontClipDistance = 0.5; // デプスバッファが小さいためあまり小さい値にできない - private double backClipDistance = 1000.0; // デプスバッファが小さいためあまり大きい値にできない - private double fieldOfView = Math.PI / 2.0; - - private TransformGroup viewPlatformTransform = null; - protected ArrayList targetObjList = null; - protected ArrayList targetList = null; - protected Position3D viewPoint = null; - protected Object3D viewPointObj = null; - private Vector3d viewLine = null; - private Vector3d cameraBack = null; - private Vector3d viewUp = null; - private boolean fParallel = false; - - // 以下の変数は省メモリ化のため導入 - private Transform3D worldToView = new Transform3D(); - private double matrix[] = new double[]{1.0, 0.0, 0.0, 0.0, - 0.0, 1.0, 0.0, 0.0, - 0.0, 0.0, 1.0, 0.0, - 0.0, 0.0, 0.0, 1.0}; - - private Transform3D cameraTransform = new Transform3D(); - - public Camera3D(Universe universe) { - this.universe = universe; - } - - public Universe getUniverse() { - return universe; - } - - /** - * カメラの注視点を追加する - * - * @param target - * 注視点 - */ - public void addTarget(Position3D target) { - if (targetList == null) targetList = new ArrayList(); - targetList.add(target); - } - - /** - * カメラの注視対象を追加する - * - * @param target - * 注視対象 - */ - public void addTarget(Object3D target) { - if (targetObjList == null) targetObjList = new ArrayList(); - targetObjList.add(target); - } - - /** - * カメラの注視対象を追加する - * - * @param target - * 注視対象 - */ - public void addTarget(Placeable target) { - if (targetObjList == null) targetObjList = new ArrayList(); - if (target.getBody() instanceof Object3D) { - targetObjList.add((Object3D)target.getBody()); - } - } - - /** - * カメラの視点を設定する - * - * @param viewPoint - * 視点 - */ - public void setViewPoint(Position3D viewPoint) { - this.viewPoint = viewPoint; - } - - /** - * カメラの視点を設定する - * - * @param viewPoint - * 視点となるオブジェクト - */ - public void setViewPoint(Object3D viewPointObj) { - this.viewPointObj = viewPointObj; - } - - /** - * カメラの視点を設定する - * - * @param viewPoint - * 視点となる登場物 - */ - public void setViewPoint(Placeable viewPointActor) { - if (viewPointActor.getBody() instanceof Object3D) { - viewPointObj = (Object3D)viewPointActor.getBody(); - } - } - - /** - * 手前からの視線に設定する - */ - public void setSideView() { - viewLine = VIEW_FORWARD; - } - - /** - * 上から見下ろした視線に設定する - */ - public void setTopView() { - viewLine = VIEW_DOWN; - } - - /** - * 視線を設定する - */ - public void setViewLine(Vector3d viewLine) { - this.viewLine = viewLine; - } - - - /** - * 視野角を設定する - * @param a 視野角 - */ - public void setFieldOfView(double a) { - fieldOfView = a; - } - - /** - * 視野角を取得する - * @return 視野角 - */ - public double getFieldOfView() { - return fieldOfView; - } - - /** - * フロントクリップ距離を設定する - * @param d - */ - public void setFrontClipDistance(double d) { - frontClipDistance = d; - } - - /** - * フロントクリップ距離を取得する - * @return フロントクリップ距離 - */ - public double getFrontClipDistance() { - return frontClipDistance; - } - - /** - * バッククリップ距離を設定する - * @param d - */ - public void setBackClipDistance(double d) { - backClipDistance = d; - } - - /** - * バッククリップ距離を取得する - * @return バッククリップ距離 - */ - public double getBackClipDistance() { - return backClipDistance; - } - - public void setViewUp(Vector3d viewUp) { - this.viewUp = viewUp; - } - - public Position3D getViewPoint() { - if (viewPoint != null) return viewPoint; - if (viewPointObj != null) return viewPointObj.getPosition3D(); - // 視点が設定されていない場合 - Vector3d center = getTargetCenter(); - if (center != null) { - Vector3d vz = new Vector3d(); - if (viewLine != null) { - // 注視対象と視線が設定されている場合 - vz.negate(viewLine); - } else { - // 注視対象のみが設定されている場合 - vz.negate(VIEW_FORWARD); - } - Vector3d vx = new Vector3d(); - Vector3d vy = new Vector3d(); - vx.cross(vz, VIEW_DOWN); - if (vx.length() > GeometryUtility.TOLERANCE) { - vx.normalize(); - } else { - vx = new Vector3d(1.0, 0.0, 0.0); - } - vy.cross(vz, vx); - - // 注視対象から下がる距離 - if (cameraBack != null) { - vx.scale(cameraBack.x); - vy.scale(cameraBack.y); - vz.scale(cameraBack.z); - center.add(vz); - center.add(vy); - center.add(vz); - } else { - double z = getStandBackDistance(vx, vy); - vz.scale(z); - center.add(vz); - } - return new Position3D(center); - } - // 視点も注視点も設定されていない場合 - return new Position3D(); - } - - public Vector3d getViewLine() { - if (viewLine != null) { - // 視線が設定されている場合 - return viewLine; - } - Vector3d center = getTargetCenter(); - if (center != null) { - if (viewPoint != null) { - center.sub(viewPoint.getVector3d()); - } else if (viewPointObj != null) { - center.sub(viewPointObj.getPosition3D().getVector3d()); - } else { - center.set(VIEW_FORWARD); - } - } else { - center = new Vector3d(VIEW_FORWARD); - } - center.normalize(); - return center; - } - - public Vector3d getViewUp() { - if (viewUp != null) { - return viewUp; - } else { - Vector3d vy = new Vector3d(0.0, 1.0, 0.0); - Vector3d vv = (Vector3d) getViewLine().clone(); - vv.cross(vy, vv); - vv.cross(getViewLine(), vv); - return vv; - } - } - - public Vector3d getTargetCenter() { - Vector3d center = new Vector3d(); - if (targetObjList != null && targetObjList.size() != 0) { - for (int i = 0; i < targetObjList.size(); i++) { - Position3D position = targetObjList.get(i).getPosition3D(); - center.add(position.getVector3d()); - } - center.scale(1.0 / targetObjList.size()); - } else if (targetList != null && targetList.size() != 0) { - for (int i = 0; i < targetList.size(); i++) { - Position3D position = targetList.get(i); - center.add(position.getVector3d()); - } - center.scale(1.0 / targetList.size()); - } else { - return null; - } - return center; - } - - /** - * 注視対象や視点の移動、視線の変化に伴う画角調整 - */ - public void adjust(long interval) { - // カメラ座標系(vx, vy, vz)を計算する - Vector3d vx = new Vector3d(), vy = new Vector3d(), vz = new Vector3d(); - if (viewLine == null) { - // 視線が設定されていない場合 - if ((viewPoint == null && viewPointObj == null) - || ((targetObjList == null || targetObjList.size() == 0) - && (targetList == null || targetList.size() == 0))) { - // 視点または注視対象が設定されていない場合、手前からの視線にする - vz.negate(VIEW_FORWARD); - } else { - // 注視対象の重心を注視点とする - Vector3d center = getTargetCenter(); - if (center == null) center = new Vector3d(); - if (viewPoint != null) { - center.sub(viewPoint.getVector3d()); - } else { - center.sub(viewPointObj.getPosition3D().getVector3d()); - } - center.normalize(); - vz.negate(center); - } - } else { - // 視線が設定されている場合 vz を視線方向 と逆向きに設定する - viewLine.normalize(); - vz.negate(viewLine); - } - vx.cross(vz, VIEW_DOWN); - if (vx.length() > GeometryUtility.TOLERANCE) { - vx.normalize(); - } else { - vx = new Vector3d(1.0, 0.0, 0.0); - } - vy.cross(vz, vx); - - // 世界座標からカメラ座標への変換を計算する - if (viewPoint != null || viewPointObj != null) { - // 視点が設定されている場合 - Vector3d vp; - if (viewPoint != null) { - vp = viewPoint.getVector3d(); - } else { - vp = viewPointObj.getPosition3D().getVector3d(); - } - matrix[0] = vx.x; matrix[1] = vx.y; matrix[2] = vx.z; matrix[3] = 0.0; - matrix[4] = vy.x; matrix[5] = vy.y; matrix[6] = vy.z; matrix[7] = 0.0; - matrix[8] = vz.x; matrix[9] = vz.y; matrix[10] = vz.z; matrix[11] = 0.0; - matrix[12] = 0.0; matrix[13] = 0.0; matrix[14] = 0.0; matrix[15] = 1.0; - worldToView.set(matrix); - worldToView.invert(); - worldToView.setTranslation(vp); - } else { - // 視点が設定されていない場合、注視対象と視線から(カメラ座標系上での)視点を逆計算する - if ((targetObjList == null || targetObjList.size() == 0) - && (targetList == null || targetList.size() == 0)) return; // 視点も注視対象も設定されていない - - // 注視対象の中心 - Vector3d center = getTargetCenter(); - - // カメラ座標上での注視点の座標 - Vector3d eye = new Vector3d(center.dot(vx), center.dot(vy), center.dot(vz)); - if (cameraBack != null) { - // カメラの引き - eye.add(cameraBack); - } else { - // 注視対象が入るようにカメラを引く - double z = getStandBackDistance(vx, vy); - eye.z += z; - } - - matrix[0] = vx.x; matrix[1] = vx.y; matrix[2] = vx.z; matrix[3] = -eye.x; - matrix[4] = vy.x; matrix[5] = vy.y; matrix[6] = vy.z; matrix[7] = -eye.y; - matrix[8] = vz.x; matrix[9] = vz.y; matrix[10] = vz.z; matrix[11] = -eye.z; - matrix[12] = 0.0; matrix[13] = 0.0; matrix[14] = 0.0; matrix[15] = 1.0; - worldToView.set(matrix); - worldToView.invert(); - } - if (viewPlatformTransform != null) viewPlatformTransform.setTransform(worldToView); - } - - public double getStandBackDistance(Vector3d vx, Vector3d vy) { - double xmax = 0; - double xmin = 0; - double ymax = 0; - double ymin = 0; - if (targetObjList != null && targetObjList.size() != 0) { - for (int i = 0; i < targetObjList.size(); i++) { - Position3D position = targetObjList.get(i).getPosition3D(); - double px = position.getVector3d().dot(vx); - double py = position.getVector3d().dot(vy); - if (i == 0) { - xmax = xmin = px; - ymax = ymin = py; - } else { - if (xmax < px) - xmax = px; - if (xmin > px) - xmin = px; - if (ymax < py) - ymax = py; - if (ymin > py) - ymin = py; - } - } - } else if (targetList != null && targetList.size() != 0) { - for (int i = 0; i < targetList.size(); i++) { - Position3D position = targetList.get(i); - double px = position.getVector3d().dot(vx); - double py = position.getVector3d().dot(vy); - if (i == 0) { - xmax = xmin = px; - ymax = ymin = py; - } else { - if (xmax < px) - xmax = px; - if (xmin > px) - xmin = px; - if (ymax < py) - ymax = py; - if (ymin > py) - ymin = py; - } - } - } - - double x = (xmax + xmin) / 2; - double y = (ymax + ymin) / 2; - double x_diff = Math.abs(xmax - x); - double y_diff = Math.abs(ymax - y); - if (x_diff < NEAREST) - x_diff = NEAREST; - if (y_diff < NEAREST) - y_diff = NEAREST; - double z; - if (x_diff < y_diff) { - z = y_diff / Math.tan(Math.PI / 18.0); - } else { - z = x_diff / Math.tan(Math.PI / 18.0); - } - return z; - } - - public void setWorldToView(Position3D vp, Vector3d vl) { - setViewPoint(vp); - setViewLine(vl); - //上方向のベクトル計算 - Vector3d vy = new Vector3d(0, 1, 0); - Vector3d vv = (Vector3d) vl.clone(); - vv.cross(vy, vv); - vv.cross(vv, vl); -// activity.setCamera(vp, vl, vv); - } - - public void setParallel(){ - this.fParallel = true; - } - - public boolean isParallel(){ - return this.fParallel; - } - -} diff --git a/src/main/java/org/ntlab/radishforandroidstudio/framework/view3D/Viewer3D.java b/src/main/java/org/ntlab/radishforandroidstudio/framework/view3D/Viewer3D.java deleted file mode 100644 index c4c535f..0000000 --- a/src/main/java/org/ntlab/radishforandroidstudio/framework/view3D/Viewer3D.java +++ /dev/null @@ -1,97 +0,0 @@ -package org.ntlab.radishforandroidstudio.framework.view3D; - -import org.ntlab.radishforandroidstudio.framework.model3D.BackgroundBox; -import org.ntlab.radishforandroidstudio.framework.model3D.IViewer3D; -import org.ntlab.radishforandroidstudio.framework.model3D.Position3D; -import org.ntlab.radishforandroidstudio.java3d.Box; -import org.ntlab.radishforandroidstudio.java3d.Cone; -import org.ntlab.radishforandroidstudio.java3d.Cylinder; -import org.ntlab.radishforandroidstudio.java3d.GraphicsContext3D; -import org.ntlab.radishforandroidstudio.java3d.Light; -import org.ntlab.radishforandroidstudio.java3d.Node; -import org.ntlab.radishforandroidstudio.java3d.Shape3D; -import org.ntlab.radishforandroidstudio.java3d.Sphere; -import org.ntlab.radishforandroidstudio.java3d.Transform3D; -import org.ntlab.radishforandroidstudio.java3d.Vector3d; - -import java.util.ArrayList; - -public class Viewer3D implements IViewer3D { - private GraphicsContext3D gc3D = null; - private ArrayList lights = null; - private BackgroundBox skyBox = null; - private Camera3D camera = null; - - public Viewer3D(Camera3D camera) { - this.camera = camera; - } - - @Override - public void setGraphicsContext3D(GraphicsContext3D gc3D) { - if (this.gc3D != gc3D) { - this.gc3D = gc3D; - } - } - - @Override - public void surfaceChanged(int width, int height) { - gc3D.update(width, height, (float)camera.getFieldOfView(), (float)camera.getFrontClipDistance(), (float)camera.getBackClipDistance(), camera.isParallel()); - } - - @Override - public void onDrawFrame() { - Position3D eye = camera.getViewPoint(); - Position3D center = eye.clone().add(camera.getViewLine()); - Vector3d up = camera.getViewUp(); - gc3D.update((float)camera.getFieldOfView(), (float)camera.getFrontClipDistance(), (float)camera.getBackClipDistance(), eye, center, up, camera.isParallel()); - } - - @Override - public void update(ArrayList lights, BackgroundBox skyBox) { - // 光源の更新 - if (this.lights != lights) { - this.lights = lights; - } - - // スカイボックスの更新 - if (this.skyBox != skyBox) { - this.skyBox = skyBox; - } - } - - @Override - public void draw(Node node) { - if (node instanceof Box) { - gc3D.draw(((Box)node).getShape(Box.FRONT)); - gc3D.draw(((Box)node).getShape(Box.BACK)); - gc3D.draw(((Box)node).getShape(Box.LEFT)); - gc3D.draw(((Box)node).getShape(Box.RIGHT)); - gc3D.draw(((Box)node).getShape(Box.TOP)); - gc3D.draw(((Box)node).getShape(Box.BOTTOM)); - } else if (node instanceof Cone) { - gc3D.draw(((Cone)node).getShape(Cone.BODY)); - gc3D.draw(((Cone)node).getShape(Cone.CAP)); - } else if (node instanceof Cylinder) { - gc3D.draw(((Cylinder)node).getShape(Cylinder.BODY)); - gc3D.draw(((Cylinder)node).getShape(Cylinder.TOP)); - gc3D.draw(((Cylinder)node).getShape(Cylinder.BOTTOM)); - } else if (node instanceof Sphere) { - gc3D.draw(((Sphere)node).getShape(Sphere.BODY)); - } else if (node instanceof Shape3D) { - gc3D.draw((Shape3D)node); - } else if (node instanceof Light){ - gc3D.updateLightState((Light)node); - } - } - - @Override - public void pushTransform(Transform3D transform) { - gc3D.pushMatrix(); - gc3D.multMatrix(transform); - } - - @Override - public void popTransform() { - gc3D.popMatrix(); - } -} diff --git a/src/main/java/org/ntlab/radishforandroidstudio/java3d/Box.java b/src/main/java/org/ntlab/radishforandroidstudio/java3d/Box.java index 374cb01..52c3371 100644 --- a/src/main/java/org/ntlab/radishforandroidstudio/java3d/Box.java +++ b/src/main/java/org/ntlab/radishforandroidstudio/java3d/Box.java @@ -39,7 +39,7 @@ 0, 0, 1, 0, 1, 1 , 0, 1, }; - // 各面のジオメトリを作成 + // 蜷�髱「縺ョ繧ク繧ェ繝。繝医Μ繧剃ス懈�� TriangleFanArray frontGeom = new TriangleFanArray(4, TriangleFanArray.COORDINATES | TriangleFanArray.NORMALS | TriangleFanArray.TEXTURE_COORDINATE_2, new int[]{4}); @@ -59,7 +59,7 @@ TriangleFanArray.COORDINATES | TriangleFanArray.NORMALS | TriangleFanArray.TEXTURE_COORDINATE_2, new int[]{4}); - // 頂点座標の設定 + // 鬆らせ蠎ァ讓吶�ョ險ュ螳� frontGeom.setCoordinate(0, coordinates[0]); frontGeom.setCoordinate(1, coordinates[1]); frontGeom.setCoordinate(2, coordinates[2]); @@ -90,7 +90,7 @@ bottomGeom.setCoordinate(2, coordinates[1]); bottomGeom.setCoordinate(3, coordinates[0]); - // テクスチャ座標の設定 + // 繝�繧ッ繧ケ繝√Ε蠎ァ讓吶�ョ險ュ螳� frontGeom.setTextureCoordinates(0, uv); backGeom.setTextureCoordinates(0, uv); rightGeom.setTextureCoordinates(0, uv); @@ -98,7 +98,7 @@ topGeom.setTextureCoordinates(0, uv); bottomGeom.setTextureCoordinates(0, uv); - // 法線の設定 + // 豕慕キ壹�ョ險ュ螳� float[] frontNorm = new float[]{0.0f, 0.0f, 1.0f}; frontGeom.setNormal(0, frontNorm); frontGeom.setNormal(1, frontNorm); @@ -135,7 +135,7 @@ bottomGeom.setNormal(2, bottomNorm); bottomGeom.setNormal(3, bottomNorm); - // 表面属性の作成 + // 陦ィ髱「螻樊�ァ縺ョ菴懈�� if (ap == null) { ap = new Appearance(); } @@ -147,43 +147,43 @@ Appearance ap5; Appearance ap6; Texture tex = ap.getTexture(); - if (tex != null && tex instanceof TextureCubeMap) { - // GL10 では GL_TEXTURE_CUBE_MAP が使えないので、TextureCubeMap の場合は Texture2D に分解する +// if (tex != null && tex instanceof TextureCubeMap) { +// // GL10 縺ァ縺ッ GL_TEXTURE_CUBE_MAP 縺御スソ縺医↑縺�縺ョ縺ァ縲ゝextureCubeMap 縺ョ蝣エ蜷医�ッ Texture2D 縺ォ蛻�隗」縺吶k ap1 = (Appearance)ap.cloneNodeComponent(); ap2 = (Appearance)ap.cloneNodeComponent(); ap3 = (Appearance)ap.cloneNodeComponent(); ap4 = (Appearance)ap.cloneNodeComponent(); ap5 = (Appearance)ap.cloneNodeComponent(); ap6 = (Appearance)ap.cloneNodeComponent(); - ImageComponent ic1 = tex.getImage(TextureCubeMap.POSITIVE_Z); - Texture2D tex1 = new Texture2D(Texture2D.BASE_LEVEL, Texture2D.RGB, ic1.width, ic1.height); - tex1.setImage(0, ic1); - ap1.setTexture(tex1); - ImageComponent ic2 = tex.getImage(TextureCubeMap.NEGATIVE_Z); - Texture2D tex2 = new Texture2D(Texture2D.BASE_LEVEL, Texture2D.RGB, ic2.width, ic2.height); - tex2.setImage(0, ic2); - ap2.setTexture(tex2); - ImageComponent ic3 = tex.getImage(TextureCubeMap.POSITIVE_X); - Texture2D tex3 = new Texture2D(Texture2D.BASE_LEVEL, Texture2D.RGB, ic3.width, ic3.height); - tex3.setImage(0, ic3); - ap3.setTexture(tex3); - ImageComponent ic4 = tex.getImage(TextureCubeMap.NEGATIVE_X); - Texture2D tex4 = new Texture2D(Texture2D.BASE_LEVEL, Texture2D.RGB, ic4.width, ic4.height); - tex4.setImage(0, ic4); - ap4.setTexture(tex4); - ImageComponent ic5 = tex.getImage(TextureCubeMap.POSITIVE_Y); - Texture2D tex5 = new Texture2D(Texture2D.BASE_LEVEL, Texture2D.RGB, ic5.width, ic5.height); - tex5.setImage(0, ic5); - ap5.setTexture(tex5); - ImageComponent ic6 = tex.getImage(TextureCubeMap.NEGATIVE_Y); - Texture2D tex6 = new Texture2D(Texture2D.BASE_LEVEL, Texture2D.RGB, ic6.width, ic6.height); - tex6.setImage(0, ic6); - ap6.setTexture(tex6); - } else { - ap1 = ap2 = ap3 = ap4 = ap5 = ap6 = ap; - } +// ImageComponent ic1 = tex.getImage(TextureCubeMap.POSITIVE_Z); +// Texture2D tex1 = new Texture2D(Texture2D.BASE_LEVEL, Texture2D.RGB, ic1.width, ic1.height); +// tex1.setImage(0, ic1); +// ap1.setTexture(tex1); +// ImageComponent ic2 = tex.getImage(TextureCubeMap.NEGATIVE_Z); +// Texture2D tex2 = new Texture2D(Texture2D.BASE_LEVEL, Texture2D.RGB, ic2.width, ic2.height); +// tex2.setImage(0, ic2); +// ap2.setTexture(tex2); +// ImageComponent ic3 = tex.getImage(TextureCubeMap.POSITIVE_X); +// Texture2D tex3 = new Texture2D(Texture2D.BASE_LEVEL, Texture2D.RGB, ic3.width, ic3.height); +// tex3.setImage(0, ic3); +// ap3.setTexture(tex3); +// ImageComponent ic4 = tex.getImage(TextureCubeMap.NEGATIVE_X); +// Texture2D tex4 = new Texture2D(Texture2D.BASE_LEVEL, Texture2D.RGB, ic4.width, ic4.height); +// tex4.setImage(0, ic4); +// ap4.setTexture(tex4); +// ImageComponent ic5 = tex.getImage(TextureCubeMap.POSITIVE_Y); +// Texture2D tex5 = new Texture2D(Texture2D.BASE_LEVEL, Texture2D.RGB, ic5.width, ic5.height); +// tex5.setImage(0, ic5); +// ap5.setTexture(tex5); +// ImageComponent ic6 = tex.getImage(TextureCubeMap.NEGATIVE_Y); +// Texture2D tex6 = new Texture2D(Texture2D.BASE_LEVEL, Texture2D.RGB, ic6.width, ic6.height); +// tex6.setImage(0, ic6); +// ap6.setTexture(tex6); +// } else { +// ap1 = ap2 = ap3 = ap4 = ap5 = ap6 = ap; +// } - // 各面の作成 + // 蜷�髱「縺ョ菴懈�� frontShape = new Shape3D(frontGeom, ap1); backShape = new Shape3D(backGeom, ap2); rightShape = new Shape3D(rightGeom, ap3); diff --git a/src/main/java/org/ntlab/radishforandroidstudio/java3d/GraphicsContext3D.java b/src/main/java/org/ntlab/radishforandroidstudio/java3d/GraphicsContext3D.java deleted file mode 100644 index cb0fe2e..0000000 --- a/src/main/java/org/ntlab/radishforandroidstudio/java3d/GraphicsContext3D.java +++ /dev/null @@ -1,378 +0,0 @@ -package org.ntlab.radishforandroidstudio.java3d; - -import android.opengl.GLU; -import android.opengl.GLUtils; - -import org.ntlab.radishforandroidstudio.framework.model3D.Position3D; - -import java.nio.FloatBuffer; -import java.nio.ShortBuffer; -import java.util.HashMap; - -import javax.microedition.khronos.opengles.GL10; - -public class GraphicsContext3D { - private GL10 gl; - private Appearance appearance = null; - private boolean bFixAspect = false; - private float aspect; - private HashMap textureRegistry = new HashMap(); - private HashMap lightRegistry = new HashMap(); - - public GraphicsContext3D(GL10 gl) { - init(gl); - } - - public GraphicsContext3D setGL10(GL10 gl) { - if (this.gl != gl) { - init(gl); - } - return this; - } - - public void fixAspect(float aspect) { - this.bFixAspect = true; - this.aspect = aspect; - } - - public void init(GL10 gl) { - this.gl = gl; - // デプスバッファのテスト機能を有効にする - gl.glEnable(GL10.GL_DEPTH_TEST); - // 陰面消去の動作を設定 - gl.glDepthFunc(GL10.GL_LEQUAL); - gl.glDepthMask(true); - - // ライトを有効にする - gl.glEnable(GL10.GL_LIGHTING); - // どの光源を使用するか指定 - gl.glEnable(GL10.GL_LIGHT0); - - gl.glClearColor(0.0f,0.0f,0.0f,0.0f); - gl.glClearDepthf(1.0f); - } - - public void update(int width, int height, float fovx, float zNear, float zFar,boolean fParallel) { - setGL10(gl); - if (!bFixAspect) { - aspect = (float)width / (float)height; - } - // ビューポートの設定 - gl.glViewport(0, 0, width, height); - - // カメラの設定 - gl.glMatrixMode(GL10.GL_PROJECTION); // 射影変換 - gl.glLoadIdentity(); // 座標の初期化 - // 画角の設定 - float fovy = (float)(Math.atan(Math.tan(fovx / 2.0) / aspect) / Math.PI * 360.0f); - if(!fParallel){ - GLU.gluPerspective(gl, - fovy, //Y方向の画角 - aspect, //アスペクト比 - zNear, //ニアクリップ - zFar);//ファークリップ - }else{ - float top = zNear * (float) Math.tan(fovy * (Math.PI / 360.0)); - float bottom = -top; - float left = bottom * aspect; - float right = top * aspect; - gl.glOrthof(left, right, bottom, top, zNear, zFar); - } - } - - public void update(float fovx, float zNear, float zFar, Position3D eye, Position3D center, Vector3d up, boolean fParallel) { - // 表示画面とデプスバッファのクリア - gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT); - - // カメラの設定 - gl.glMatrixMode(GL10.GL_PROJECTION); // 射影変換 - gl.glLoadIdentity(); // 座標の初期化 - // 画角の設定 - float fovy = (float)(Math.atan(Math.tan(fovx / 2.0) / aspect) / Math.PI * 360.0f); - if (!fParallel) { - GLU.gluPerspective(gl, - fovy, //Y方向の画角 - aspect, //アスペクト比 - zNear, //ニアクリップ - zFar);//ファークリップ - } else { - float top = zNear * (float) Math.tan(fovy * (Math.PI / 360.0)); - float bottom = -top; - float left = bottom * aspect; - float right = top * aspect; - gl.glOrthof(left, right, bottom, top, zNear, zFar); - } - // モデルビュー行列の指定 - gl.glMatrixMode(GL10.GL_MODELVIEW); - // 座標の初期化 - gl.glLoadIdentity(); - - // カメラ外部パラメータの設定 - GLU.gluLookAt(gl, - (float)eye.getX(), (float)eye.getY(), (float)eye.getZ(), - (float)center.getX(), (float)center.getY(), (float)center.getZ(), - (float)up.getX(), (float)up.getY(), (float)up.getZ()); - } - - public void setLight(Light l, int i) { - lightRegistry.put(l, i); - Color3f c = l.getColor(); - float color[] = {c.r, c.g, c.b, 1.0f}; - gl.glEnable(GL10.GL_LIGHT0 + i); - if (l instanceof AmbientLight) { - gl.glLightfv(GL10.GL_LIGHT0 + i, GL10.GL_AMBIENT, color, 0); - gl.glLightfv(GL10.GL_LIGHT0 + i, GL10.GL_DIFFUSE, new float[]{0.0f, 0.0f, 0.0f, 1.0f}, 0); - gl.glLightfv(GL10.GL_LIGHT0 + i, GL10.GL_SPECULAR, new float[]{0.0f, 0.0f, 0.0f, 1.0f}, 0); - } else { - gl.glLightfv(GL10.GL_LIGHT0 + i, GL10.GL_AMBIENT, new float[]{0.0f, 0.0f, 0.0f, 1.0f}, 0); - gl.glLightfv(GL10.GL_LIGHT0 + i, GL10.GL_DIFFUSE, color, 0); - gl.glLightfv(GL10.GL_LIGHT0 + i, GL10.GL_SPECULAR, new float[]{1.0f, 1.0f, 1.0f, 1.0f}, 0); - } - } - - public void updateLightState(Light l) { - Integer i = lightRegistry.get(l); - if (i == null) { - // Object3D内部に配置されている光源に対しては、初期化時にsetLight()が呼ばれないため - i = lightRegistry.size(); - setLight(l, i); - } - if (l instanceof DirectionalLight) { - Vector3f v = ((DirectionalLight)l).getDirection(); - float direction[] = {-v.x, -v.y, -v.z, 0.0f}; - gl.glLightfv(GL10.GL_LIGHT0 + i, GL10.GL_POSITION, direction, 0); - } else if (l instanceof PointLight) { - Point3f p = ((PointLight)l).getPosition(); - float position[] = {p.x, p.y, p.z, 1.0f}; - gl.glLightfv(GL10.GL_LIGHT0 + i, GL10.GL_POSITION, position, 0); - } - } - - public void pushMatrix() { - gl.glPushMatrix(); - } - - public void popMatrix() { - gl.glPopMatrix(); - } - - public void multMatrix(Transform3D transform) { - float m[] = transform.getMatrix(); - gl.glMultMatrixf(m, 0); - } - - public void setAppearance(Appearance appearance) { - this.appearance = appearance; - Material material = appearance.getMaterial(); - if (material != null) { - // 表面属性の設定 - gl.glMaterialfv(GL10.GL_FRONT, GL10.GL_DIFFUSE, material.diffuse, 0); - gl.glMaterialfv(GL10.GL_FRONT, GL10.GL_AMBIENT, material.ambient, 0); - gl.glMaterialfv(GL10.GL_FRONT, GL10.GL_SPECULAR, material.specular, 0); - gl.glMaterialfv(GL10.GL_FRONT, GL10.GL_EMISSION, material.emissive, 0); - gl.glMaterialf(GL10.GL_FRONT, GL10.GL_SHININESS, material.shininess); - } - if (appearance.getTextureUnitCount() == 0) { - // テクスチャユニットを使っていない場合(通常のテクスチャの場合) - Texture tex = appearance.getTexture(); - if (tex != null) registerTexture(tex); - } else { - // テクスチャユニットを使っている場合 - for (int n = 0; n < appearance.getTextureUnitCount(); n++) { - TextureUnitState tus = appearance.getTextureUnitState(n); - Texture tex = tus.getTexture(); - if (tex != null) { - gl.glActiveTexture(GL10.GL_TEXTURE1 + n); - registerTexture(tex); - } - } - } - } - - private void registerTexture(Texture tex) { - if (textureRegistry.get(tex) == null) { - // テクスチャの登録 - int[] textureId = new int[1]; - gl.glGenTextures(1, textureId, 0); - if (tex instanceof TextureCubeMap) { - // 立方体マップの場合(GL10では対応していない) - } else { - // 通常の場合 - gl.glBindTexture(GL10.GL_TEXTURE_2D, textureId[0]); - ImageComponent[] imageComponents = tex.getImages(); - for (int level = 0; level < imageComponents.length; level++) { - GLUtils.texImage2D(GL10.GL_TEXTURE_2D, level, ((ImageComponent2D)imageComponents[level]).getBitmap(), 0); -// ((ImageComponent2D)imageComponents[i]).getBitmap().recycle(); - gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_NEAREST); - gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_NEAREST); - } - } - textureRegistry.put(tex, textureId[0]); - } - } - - public void draw(Shape3D node) { - if (node == null) return; - setAppearance(node.getAppearance()); - draw(node.getGeometry()); - } - - public void draw(Geometry g) { - if (g == null) return; - if (appearance.getTextureUnitCount() == 0) { - // テクスチャユニットを使っていない場合(通常のテクスチャの場合) - Texture tex = appearance.getTexture(); - if (tex != null) { - gl.glEnable(GL10.GL_TEXTURE_2D); - gl.glBindTexture(GL10.GL_TEXTURE_2D, textureRegistry.get(tex)); // テクスチャが登録されていることを前提 - TextureAttributes ta = appearance.getTextureAttributes(); - if (ta != null) setTextureAttributes(ta); - } - } else { - // テクスチャユニットを使っている場合 - for (int n = 0; n < appearance.getTextureUnitCount(); n++) { - TextureUnitState tus = appearance.getTextureUnitState(n); - Texture tex = tus.getTexture(); - if (tex != null) { - gl.glActiveTexture(GL10.GL_TEXTURE0 + n); - gl.glEnable(GL10.GL_TEXTURE_2D); - gl.glBindTexture(GL10.GL_TEXTURE_2D, textureRegistry.get(tex)); // テクスチャが登録されていることを前提 - TextureAttributes ta = tus.getTextureAttributes(); - if (ta != null) setTextureAttributes(ta); - } - } - } - if (g instanceof GeometryArray) { - // バッファの設定 - gl.glEnableClientState(GL10.GL_VERTEX_ARRAY); - FloatBuffer vertexBuffer = ((GeometryArray)g).getVertexBuffer(); - gl.glVertexPointer(3, GL10.GL_FLOAT, 0, vertexBuffer); - if ((((GeometryArray) g).getVertexFormat() & GeometryArray.NORMALS) != 0) { - gl.glEnableClientState(GL10.GL_NORMAL_ARRAY); - FloatBuffer normalBuffer = ((GeometryArray)g).getNormalBuffer(); - gl.glNormalPointer(GL10.GL_FLOAT, 0, normalBuffer); - } - if ((((GeometryArray) g).getVertexFormat() & GeometryArray.TEXTURE_COORDINATE_2) != 0) { - gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY); - FloatBuffer uvBuffer = ((GeometryArray)g).getUVBuffer(); - gl.glTexCoordPointer(2, GL10.GL_FLOAT, 0, uvBuffer); - } else if ((((GeometryArray) g).getVertexFormat() & GeometryArray.TEXTURE_COORDINATE_3) != 0) { - gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY); - FloatBuffer uvBuffer = ((GeometryArray)g).getUVBuffer(); - gl.glTexCoordPointer(3, GL10.GL_FLOAT, 0, uvBuffer); - } else if ((((GeometryArray) g).getVertexFormat() & GeometryArray.TEXTURE_COORDINATE_4) != 0) { - gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY); - FloatBuffer uvBuffer = ((GeometryArray)g).getUVBuffer(); - gl.glTexCoordPointer(4, GL10.GL_FLOAT, 0, uvBuffer); - } - - // ジオメトリの描画 - if (g instanceof TriangleArray) { - TriangleArray ta = (TriangleArray)g; - int vertexCount = ta.getVertexCount(); - gl.glDrawArrays(GL10.GL_TRIANGLES, 0, vertexCount); - } else if (g instanceof TriangleFanArray) { - TriangleFanArray ta = (TriangleFanArray)g; - int start = 0; - int[] stripVertexCounts = new int[ta.getNumStrips()]; - ta.getStripVertexCounts(stripVertexCounts); - for (int n = 0; n < ta.getNumStrips(); n++) { - int vertexCount = stripVertexCounts[n]; - gl.glDrawArrays(GL10.GL_TRIANGLE_FAN, start, vertexCount); - start += vertexCount; - } - } else if (g instanceof TriangleStripArray) { - TriangleStripArray ta = (TriangleStripArray)g; - int start = 0; - int[] stripVertexCounts = new int[ta.getNumStrips()]; - ta.getStripVertexCounts(stripVertexCounts); - for (int n = 0; n < ta.getNumStrips(); n++) { - int vertexCount = stripVertexCounts[n]; - gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, start, vertexCount); - start += vertexCount; - } - } else if (g instanceof IndexedTriangleArray) { - IndexedTriangleArray ita = (IndexedTriangleArray)g; - int vertexCount = ((IndexedTriangleArray)g).getIndexCount(); - gl.glDrawElements(GL10.GL_TRIANGLES, vertexCount, GL10.GL_UNSIGNED_SHORT, ita.getCoordinateIndexBuffer()); - } else if (g instanceof IndexedTriangleFanArray) { - IndexedGeometryStripArray igsa = (IndexedGeometryStripArray)g; - ShortBuffer indexBuffer = igsa.getCoordinateIndexBuffer(); - int start = 0; - int[] stripIndexCounts = new int[igsa.getNumStrips()]; - igsa.getStripIndexCounts(stripIndexCounts); - for (int n = 0; n < igsa.getNumStrips(); n++) { - int vertexCount = stripIndexCounts[n]; - indexBuffer.position(start); - gl.glDrawElements(GL10.GL_TRIANGLE_FAN, vertexCount, GL10.GL_UNSIGNED_SHORT, indexBuffer); - start += vertexCount; - } - } else if (g instanceof IndexedTriangleStripArray) { - IndexedGeometryStripArray igsa = (IndexedGeometryStripArray)g; - ShortBuffer indexBuffer = igsa.getCoordinateIndexBuffer(); - int start = 0; - int[] stripIndexCounts = new int[igsa.getNumStrips()]; - igsa.getStripIndexCounts(stripIndexCounts); - for (int n = 0; n < igsa.getNumStrips(); n++) { - int vertexCount = stripIndexCounts[n]; - indexBuffer.position(start); - gl.glDrawElements(GL10.GL_TRIANGLE_STRIP, vertexCount, GL10.GL_UNSIGNED_SHORT, indexBuffer); - start += vertexCount; - } - } - - if ((((GeometryArray) g).getVertexFormat() & GeometryArray.TEXTURE_COORDINATE_2) != 0) { - gl.glDisableClientState(GL10.GL_TEXTURE_COORD_ARRAY); - } else if ((((GeometryArray) g).getVertexFormat() & GeometryArray.TEXTURE_COORDINATE_3) != 0) { - gl.glDisableClientState(GL10.GL_TEXTURE_COORD_ARRAY); - } else if ((((GeometryArray) g).getVertexFormat() & GeometryArray.TEXTURE_COORDINATE_4) != 0) { - gl.glDisableClientState(GL10.GL_TEXTURE_COORD_ARRAY); - } - if ((((GeometryArray) g).getVertexFormat() & GeometryArray.NORMALS) != 0) { - gl.glDisableClientState(GL10.GL_NORMAL_ARRAY); - } - gl.glDisableClientState(GL10.GL_VERTEX_ARRAY); - } - if (appearance.getTextureUnitCount() == 0) { - // テクスチャユニットを使っていない場合(通常のテクスチャの場合) - if (appearance.getTexture() != null) { - gl.glDisable(GL10.GL_TEXTURE_2D); - } - } else { - // テクスチャユニットを使っている場合 - for (int n = 0; n < appearance.getTextureUnitCount(); n++) { - gl.glActiveTexture(GL10.GL_TEXTURE0 + n); - gl.glDisable(GL10.GL_TEXTURE_2D); - } - gl.glActiveTexture(GL10.GL_TEXTURE0); - } - } - - private void setTextureAttributes(TextureAttributes ta) { - int textureMode = ta.getTextureMode(); - switch (textureMode) { - case TextureAttributes.REPLACE: - gl.glTexEnvx(GL10.GL_TEXTURE_ENV, GL10.GL_TEXTURE_ENV_MODE, GL10.GL_REPLACE); - break; - case TextureAttributes.BLEND: - gl.glTexEnvx(GL10.GL_TEXTURE_ENV, GL10.GL_TEXTURE_ENV_MODE, GL10.GL_BLEND); - break; -// case TextureAttributes.COMBINE: -// gl.glTexEnvx(GL10.GL_TEXTURE_ENV, GL10.GL_TEXTURE_ENV_MODE, GL10.GL_COMBINE); -// break; - case TextureAttributes.MODULATE: - gl.glTexEnvx(GL10.GL_TEXTURE_ENV, GL10.GL_TEXTURE_ENV_MODE, GL10.GL_MODULATE); - break; - case TextureAttributes.DECAL: - gl.glTexEnvx(GL10.GL_TEXTURE_ENV, GL10.GL_TEXTURE_ENV_MODE, GL10.GL_DECAL); - break; - } -// int perspCorrectionMode = ta.getPerspectiveCorrectionMode(); -// switch (perspCorrectionMode) { -// case TextureAttributes.NICEST: -// break; -// case TextureAttributes.FASTEST: -// break; -// } - } -} diff --git a/src/main/java/org/ntlab/radishforandroidstudio/java3d/ImageComponent2D.java b/src/main/java/org/ntlab/radishforandroidstudio/java3d/ImageComponent2D.java deleted file mode 100644 index f760c4c..0000000 --- a/src/main/java/org/ntlab/radishforandroidstudio/java3d/ImageComponent2D.java +++ /dev/null @@ -1,23 +0,0 @@ -package org.ntlab.radishforandroidstudio.java3d; - -import android.graphics.Bitmap; - -public class ImageComponent2D extends ImageComponent { - private Bitmap image = null; - - public ImageComponent2D(int format, Bitmap image) { - super(format, image.getWidth(), image.getHeight()); - this.image = image; - } - - public Bitmap getBitmap() { - return image; - } - - @Override - public NodeComponent cloneNodeComponent() { - ImageComponent2D newOne = new ImageComponent2D(format, image); - return newOne; - } - -} diff --git a/src/main/java/org/ntlab/radishforandroidstudio/java3d/TextureCubeMap.java b/src/main/java/org/ntlab/radishforandroidstudio/java3d/TextureCubeMap.java deleted file mode 100644 index 20d96c4..0000000 --- a/src/main/java/org/ntlab/radishforandroidstudio/java3d/TextureCubeMap.java +++ /dev/null @@ -1,29 +0,0 @@ -package org.ntlab.radishforandroidstudio.java3d; - -public class TextureCubeMap extends Texture { - public static final int POSITIVE_X = 0; - public static final int NEGATIVE_X = 1; - public static final int POSITIVE_Y = 2; - public static final int NEGATIVE_Y = 3; - public static final int POSITIVE_Z = 4; - public static final int NEGATIVE_Z = 5; - - public TextureCubeMap(int mipmapMode, int format, int width) { - super(mipmapMode, format, width, 0); - imageComponents = new ImageComponent[6]; - } - - - public void setImage(int level, int face, ImageComponent2D image) { - imageComponents[face] = image; - width = image.getBitmap().getWidth(); - } - - @Override - public NodeComponent cloneNodeComponent() { - TextureCubeMap texCubeMap = new TextureCubeMap(mipmapMode, format, width); - texCubeMap.imageComponents = imageComponents.clone(); - return texCubeMap; - } - -} diff --git a/src/main/java/org/ntlab/radishforandroidstudio/java3d/TextureLoader.java b/src/main/java/org/ntlab/radishforandroidstudio/java3d/TextureLoader.java deleted file mode 100644 index dbd250b..0000000 --- a/src/main/java/org/ntlab/radishforandroidstudio/java3d/TextureLoader.java +++ /dev/null @@ -1,43 +0,0 @@ -package org.ntlab.radishforandroidstudio.java3d; - -import android.content.res.Resources; -import android.graphics.Bitmap; -import android.graphics.BitmapFactory; - -import java.io.InputStream; - -public class TextureLoader { - - public static final int BY_REFERENCE = 2; - public static final int Y_UP = 4; - private InputStream in = null; - private Resources res = null; - private int id = 0; - private Bitmap bitmap; - - public TextureLoader(InputStream in, int flags) { - this.in = in; - } - - public TextureLoader(Resources res, int id, int flags) { - this.res = res; - this.id = id; - } - - public ImageComponent2D getImage() { - if (in != null) { - bitmap = BitmapFactory.decodeStream(in); - } else if (res != null) { - bitmap = BitmapFactory.decodeResource(res, id); - } - return new ImageComponent2D(ImageComponent2D.FORMAT_RGB, bitmap); - } - - public Texture getTexture() { - ImageComponent2D ic2 = getImage(); - Texture tex = new Texture2D(Texture.BASE_LEVEL, Texture.RGB, bitmap.getWidth(), bitmap.getHeight()); - tex.setImage(0, ic2); - return tex; - } - -}