diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 61e462d..ff8963d 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -55,6 +55,18 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/tests/SampleActivity.java b/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/tests/SampleActivity.java index 6e0ecc9..6c0c69d 100644 --- a/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/tests/SampleActivity.java +++ b/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/tests/SampleActivity.java @@ -4,6 +4,8 @@ import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; +import android.view.View.OnTouchListener; +import android.widget.FrameLayout; import org.ntlab.radishforandroidstudio.R; import org.ntlab.radishforandroidstudio.framework.gameMain.RealTime3DFragment; @@ -14,6 +16,16 @@ protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_sample); +//touch event用 +// frameLayout01 = (FrameLayout)findViewById(R.id.framelayout_sample); +// frameLayout01.setOnTouchListener((SampleGameFragment)samplgem); +// +//// +//// SampleGameFragment samplegamefragment = new SampleGameFragment(); +//// +//// View view1 =(View)findViewById(R.id.framelayout_sample); +//// view1.setOnTouchListener((SampleGameFragment)samplegamefragment); + } @@ -29,7 +41,7 @@ } if(view == findViewById(R.id.button2)){ - fragment = new RealTime3DFragment(); + fragment = new SampleGameFragment(); getSupportFragmentManager() .beginTransaction() .replace(R.id.fragment_field, fragment) diff --git a/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/tests/SampleGameFragment.java b/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/tests/SampleGameFragment.java new file mode 100644 index 0000000..10ceb8b --- /dev/null +++ b/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/tests/SampleGameFragment.java @@ -0,0 +1,144 @@ +package org.ntlab.radishforandroidstudio.cactusClient.tests; + + +import android.os.Bundle; +import android.support.annotation.NonNull; +import android.support.annotation.Nullable; +import android.util.Log; +import android.view.LayoutInflater; +import android.view.Menu; +import android.view.MenuInflater; +import android.view.MenuItem; +import android.view.MotionEvent; +import android.view.View; +import android.view.ViewGroup; + +import org.ntlab.radishforandroidstudio.framework.RWT.RWTSurfaceView; +import org.ntlab.radishforandroidstudio.framework.gameMain.OvergroundActor; +import org.ntlab.radishforandroidstudio.framework.gameMain.RealTime3DFragment; +import org.ntlab.radishforandroidstudio.framework.gameMain.RealTimeActivity; +import org.ntlab.radishforandroidstudio.framework.model3D.BaseObject3D; +import org.ntlab.radishforandroidstudio.framework.model3D.Object3D; +import org.ntlab.radishforandroidstudio.framework.model3D.Position3D; +import org.ntlab.radishforandroidstudio.framework.model3D.Universe; +import org.ntlab.radishforandroidstudio.framework.physics.AngularVelocity3D; +import org.ntlab.radishforandroidstudio.framework.physics.Force3D; +import org.ntlab.radishforandroidstudio.framework.physics.Ground; +import org.ntlab.radishforandroidstudio.framework.physics.PhysicalSystem; +import org.ntlab.radishforandroidstudio.framework.physics.Solid3D; +import org.ntlab.radishforandroidstudio.framework.physics.Velocity3D; +import org.ntlab.radishforandroidstudio.framework.view3D.Camera3D; +import org.ntlab.radishforandroidstudio.java3d.Appearance; +import org.ntlab.radishforandroidstudio.java3d.Box; +import org.ntlab.radishforandroidstudio.java3d.IndexedTriangleArray; +import org.ntlab.radishforandroidstudio.java3d.Material; +import org.ntlab.radishforandroidstudio.java3d.Point3d; +import org.ntlab.radishforandroidstudio.java3d.TextureCubeMap; +import org.ntlab.radishforandroidstudio.java3d.TextureLoader; +import org.ntlab.radishforandroidstudio.java3d.Transform3D; +import org.ntlab.radishforandroidstudio.R; +import org.ntlab.radishforandroidstudio.java3d.Vector3f; + +public class SampleGameFragment extends RealTime3DFragment { + + + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + // 3Dモデルの作成 + + // サイコロの作成 + Appearance ap1 = new Appearance(); + Material m = new Material(); + m.setDiffuseColor(1.0f, 1.0f, 1.0f); + ap1.setMaterial(m); + TextureCubeMap tex1 = new TextureCubeMap(TextureCubeMap.BASE_LEVEL, TextureCubeMap.RGB, 0); + TextureLoader loader = new TextureLoader(getResources(), R.drawable.dice_1, TextureLoader.BY_REFERENCE | TextureLoader.Y_UP); + tex1.setImage(0, TextureCubeMap.POSITIVE_Z, loader.getImage()); + loader = new TextureLoader(getResources(), R.drawable.dice_6, TextureLoader.BY_REFERENCE | TextureLoader.Y_UP); + tex1.setImage(0, TextureCubeMap.NEGATIVE_Z, loader.getImage()); + loader = new TextureLoader(getResources(), R.drawable.dice_4, TextureLoader.BY_REFERENCE | TextureLoader.Y_UP); + tex1.setImage(0, TextureCubeMap.POSITIVE_X, loader.getImage()); + loader = new TextureLoader(getResources(), R.drawable.dice_3, TextureLoader.BY_REFERENCE | TextureLoader.Y_UP); + tex1.setImage(0, TextureCubeMap.NEGATIVE_X, loader.getImage()); + loader = new TextureLoader(getResources(), R.drawable.dice_5, TextureLoader.BY_REFERENCE | TextureLoader.Y_UP); + tex1.setImage(0, TextureCubeMap.POSITIVE_Y, loader.getImage()); + loader = new TextureLoader(getResources(), R.drawable.dice_2, TextureLoader.BY_REFERENCE | TextureLoader.Y_UP); + tex1.setImage(0, TextureCubeMap.NEGATIVE_Y, loader.getImage()); + ap1.setTexture(tex1); + Box b1 = new Box(1.0f, 1.0f, 1.0f, ap1); + final Object3D obj1 = new Object3D("box", b1); + obj1.scale(2.0, 2.0, 2.0); + obj1.apply(new Position3D(0.0 , 30.0, 0.0), false); + OvergroundActor actor = new OvergroundActor(obj1, null); + universe.place(actor); + + // 地面の作成 + IndexedTriangleArray groundGeometry = new IndexedTriangleArray(4, + IndexedTriangleArray.COORDINATES | IndexedTriangleArray.NORMALS, 6); + groundGeometry.setCoordinate(0, new Point3d(-20.0, 0.0, -20.0)); + groundGeometry.setCoordinate(1, new Point3d(20.0, 0.0, -20.0)); + groundGeometry.setCoordinate(2, new Point3d(20.0, 0.0, 20.0)); + groundGeometry.setCoordinate(3, new Point3d(-20.0, 0.0, 20.0)); + groundGeometry.setNormal(0, new Vector3f(0.0f, 1.0f, 0.0f)); + groundGeometry.setNormal(1, new Vector3f(0.0f, 1.0f, 0.0f)); + groundGeometry.setNormal(2, new Vector3f(0.0f, 1.0f, 0.0f)); + groundGeometry.setNormal(3, new Vector3f(0.0f, 1.0f, 0.0f)); + groundGeometry.setCoordinateIndices(0, new int[]{0, 3, 2}); + groundGeometry.setCoordinateIndices(3, new int[]{0, 2, 1}); + Appearance ap2 = new Appearance(); + Material m2 = new Material(); + m2.setDiffuseColor(0.5f, 1.0f, 0.2f); + ap2.setMaterial(m2); + Ground ground = new Ground(new BaseObject3D(groundGeometry, ap2)); + universe.place(ground); + +// final OvergroundActor oga = new OvergroundActor(obj1, null) { +// @Override +// public Force3D getGravity() { +// return new Force3D(0.0,0.0,0.0); +// } +// }; +// universe.place(oga); + + // カメラの設定 + camera.setViewPoint(new Position3D(0.0, 10.0, -20.0)); + camera.addTarget(actor); + + // フレームの間隔(ms) + start(20); + + //onCreateOptionMenuの呼び出し + setHasOptionsMenu(true); + } + + @Nullable + @Override + public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { + return inflater.inflate(R.layout.fragment_sample_game, container, false); + } + + @Override + public void onDestroy() { + super.onDestroy(); + } + + + @Override + public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { + inflater.inflate(R.menu.main,menu); + super.onCreateOptionsMenu(menu, inflater); + } + + public boolean onOptionsItemSelected(MenuItem item){ + int id = item.getItemId(); + + if(id == R.id.action_settings){ + return true; + + } + return super.onOptionsItemSelected(item); + } +} \ No newline at end of file diff --git a/app/src/main/java/org/ntlab/radishforandroidstudio/framework/gameMain/RealTime3DFragment.java b/app/src/main/java/org/ntlab/radishforandroidstudio/framework/gameMain/RealTime3DFragment.java index a01b25a..41477be 100644 --- a/app/src/main/java/org/ntlab/radishforandroidstudio/framework/gameMain/RealTime3DFragment.java +++ b/app/src/main/java/org/ntlab/radishforandroidstudio/framework/gameMain/RealTime3DFragment.java @@ -3,20 +3,59 @@ import android.content.Context; import android.net.Uri; import android.os.Bundle; +import android.support.annotation.NonNull; +import android.support.annotation.Nullable; import android.support.v4.app.Fragment; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import org.ntlab.radishforandroidstudio.R; +import org.ntlab.radishforandroidstudio.framework.RWT.RWTSurfaceView; +import org.ntlab.radishforandroidstudio.framework.model3D.Universe; +import org.ntlab.radishforandroidstudio.framework.view3D.Camera3D; -public class RealTime3DFragment extends RealTimeFragment { +public class RealTime3DFragment extends RealTimeFragment{ + protected Universe universe; + protected Camera3D camera; + protected RWTSurfaceView view; @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, - Bundle savedInstanceState) { - // Inflate the layout for this fragment - return inflater.inflate(R.layout.fragment_real_time_3d, container, false); + public void onCreate(@Nullable Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + universe = new Universe(); + + camera = new Camera3D(universe); + + view = new RWTSurfaceView(this.getActivity()); + view.setRenderMode(RWTSurfaceView.RENDERMODE_WHEN_DIRTY); + view.attachCamera(camera); + + getActivity().setContentView(view); + + } + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + return inflater.inflate(R.layout.fragment_real_time_3d, container, false); + +// return new RWTSurfaceView(getActivity()); + + + } + + @Override + protected void update(long interval) { + progress(interval); + universe.update(interval); + camera.adjust(interval); + view.requestRender(); + + } + + protected void progress(long interval) { + + } } + diff --git a/app/src/main/java/org/ntlab/radishforandroidstudio/framework/gameMain/RealTimeActivity.java b/app/src/main/java/org/ntlab/radishforandroidstudio/framework/gameMain/RealTimeActivity.java index 29025ca..417cb4f 100644 --- a/app/src/main/java/org/ntlab/radishforandroidstudio/framework/gameMain/RealTimeActivity.java +++ b/app/src/main/java/org/ntlab/radishforandroidstudio/framework/gameMain/RealTimeActivity.java @@ -10,16 +10,16 @@ //インターバル確認用変数 private long interval = 15L; private long prevTime = 0L; - + private ScheduledThreadPoolExecutor schedule = new ScheduledThreadPoolExecutor(1); private boolean fixedInterval; - + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - } - + } + protected void start(long interval){ this.interval = interval; this.fixedInterval = false; diff --git a/app/src/main/java/org/ntlab/radishforandroidstudio/framework/gameMain/RealTimeFragment.java b/app/src/main/java/org/ntlab/radishforandroidstudio/framework/gameMain/RealTimeFragment.java index a8f2723..6fa410f 100644 --- a/app/src/main/java/org/ntlab/radishforandroidstudio/framework/gameMain/RealTimeFragment.java +++ b/app/src/main/java/org/ntlab/radishforandroidstudio/framework/gameMain/RealTimeFragment.java @@ -1,8 +1,8 @@ package org.ntlab.radishforandroidstudio.framework.gameMain; -import android.content.Context; -import android.net.Uri; import android.os.Bundle; +import android.support.annotation.NonNull; +import android.support.annotation.Nullable; import android.support.v4.app.Fragment; import android.view.LayoutInflater; import android.view.View; @@ -10,13 +10,65 @@ import org.ntlab.radishforandroidstudio.R; -public class RealTimeFragment extends Fragment { +import java.util.concurrent.ScheduledThreadPoolExecutor; +import java.util.concurrent.TimeUnit; + +public abstract class RealTimeFragment extends Fragment implements Runnable{ + //インターバル確認用変数 + private long interval = 15L; + private long prevTime = 0L; + + private ScheduledThreadPoolExecutor schedule = new ScheduledThreadPoolExecutor(1); + private boolean fixedInterval; @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, - Bundle savedInstanceState) { - // Inflate the layout for this fragment + public void onCreate(@Nullable Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + } + + @Nullable + @Override + public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { return inflater.inflate(R.layout.fragment_real_time, container, false); } + protected void start(long interval){ + this.interval = interval; + this.fixedInterval = false; + schedule.scheduleWithFixedDelay(this, interval, interval, TimeUnit.MILLISECONDS); + } + + protected void start(long delay, long interval){ + this.interval = interval; + this.fixedInterval = false; + schedule.scheduleWithFixedDelay(this, delay, interval, TimeUnit.MILLISECONDS); + } + + protected void start(long delay, long interval, boolean fixedInterval){ + this.interval = interval; + this.fixedInterval = fixedInterval; + schedule.scheduleWithFixedDelay(this, delay, interval, TimeUnit.MILLISECONDS); + } + + + protected void stop() { + schedule.shutdown(); + } + + //繰り返し実行される部分 + public void run(){ + long interval; + if (prevTime == 0L || fixedInterval) { + interval = this.interval; + prevTime = System.currentTimeMillis(); + } else { + long curTime = System.currentTimeMillis(); + interval = curTime - prevTime; + prevTime = curTime; + } + update(interval); + } + //intervalミリ秒のインターバルをおいて定期実行 + protected abstract void update(long interval); + } diff --git a/app/src/main/res/layout/activity_sample.xml b/app/src/main/res/layout/activity_sample.xml index 5103856..0a9ec10 100644 --- a/app/src/main/res/layout/activity_sample.xml +++ b/app/src/main/res/layout/activity_sample.xml @@ -2,6 +2,7 @@ @@ -24,9 +25,9 @@ + app:layout_constraintTop_toBottomOf="@+id/button" + tools:layout="@layout/fragment_sample_game" />