Newer
Older
CarrotServer / src / game / StageStandard.java
t-nakanishi on 18 Jul 2017 9 KB [add] project
package game;

import framework.model3D.BaseObject3D;
import framework.model3D.Object3D;
import framework.model3D.Position3D;
import framework.model3D.Quaternion3D;
import framework.physics.Ground;
import framework.physics.Solid3D;
import java3d.Appearance;
import java3d.Box;
import java3d.IndexedTriangleArray;
import java3d.Material;
import java3d.Point3d;
import java3d.Shape3D;
import java3d.Texture;
import java3d.Vector3f;

public class StageStandard extends Stage {

	public StageStandard() {
		super();
		
		
		// TODO Auto-generated constructor stub
		
		//頂点の数、頂点の使用回数の宣言
		//立方体作成のためのジオメトリ
		IndexedTriangleArray cubeGeometry = new IndexedTriangleArray(24,
				IndexedTriangleArray.COORDINATES | IndexedTriangleArray.NORMALS, 36);
		
		
		//二面生成 頂点座標を決定
		//0面(立方体の面の名前)
		cubeGeometry.setCoordinate(0, new Point3d(0.0, 0.0, 0.0));
		cubeGeometry.setCoordinate(1, new Point3d(1.0, 0.0, 0.0));
		cubeGeometry.setCoordinate(2, new Point3d(1.0, 1.0, 0.0));
		cubeGeometry.setCoordinate(3, new Point3d(0.0, 1.0, 0.0));
		//1面
		cubeGeometry.setCoordinate(4, new Point3d(1.0, 0.0, 0.0));
		cubeGeometry.setCoordinate(5, new Point3d(1.0, 0.0, 1.0));
		cubeGeometry.setCoordinate(6, new Point3d(1.0, 1.0, 1.0));
		cubeGeometry.setCoordinate(7, new Point3d(1.0, 1.0, 0.0));
		//2面
		cubeGeometry.setCoordinate(8, new Point3d(1.0, 0.0, 1.0));
		cubeGeometry.setCoordinate(9, new Point3d(1.0, 1.0, 1.0));
		cubeGeometry.setCoordinate(10, new Point3d(0.0, 1.0, 1.0));
		cubeGeometry.setCoordinate(11, new Point3d(0.0, 0.0, 1.0));
		//3面
		cubeGeometry.setCoordinate(12, new Point3d(0.0, 0.0, 1.0));
		cubeGeometry.setCoordinate(13, new Point3d(0.0, 1.0, 1.0));
		cubeGeometry.setCoordinate(14, new Point3d(0.0, 1.0, 0.0));
		cubeGeometry.setCoordinate(15, new Point3d(0.0, 0.0, 0.0));
		//上面
		cubeGeometry.setCoordinate(16, new Point3d(0.0, 1.0, 0.0));
		cubeGeometry.setCoordinate(17, new Point3d(1.0, 1.0, 0.0));
		cubeGeometry.setCoordinate(18, new Point3d(1.0, 1.0, 1.0));
		cubeGeometry.setCoordinate(19, new Point3d(0.0, 1.0, 1.0));
		//底面
		cubeGeometry.setCoordinate(20, new Point3d(0.0, 0.0, 0.0));
		cubeGeometry.setCoordinate(21, new Point3d(1.0, 0.0, 0.0));
		cubeGeometry.setCoordinate(22, new Point3d(1.0, 0.0, 1.0));
		cubeGeometry.setCoordinate(23, new Point3d(0.0, 0.0, 1.0));
		//法線ベクトルを決定
		//0面
		cubeGeometry.setNormal(0, new Vector3f(0.0f, 0.0f, -1.0f));
		cubeGeometry.setNormal(1, new Vector3f(0.0f, 0.0f, -1.0f));
		cubeGeometry.setNormal(2, new Vector3f(0.0f, 0.0f, -1.0f));
		cubeGeometry.setNormal(3, new Vector3f(0.0f, 0.0f, -1.0f));
		//1面
		cubeGeometry.setNormal(4, new Vector3f(1.0f, 0.0f, 0.0f));
		cubeGeometry.setNormal(5, new Vector3f(1.0f, 0.0f, 0.0f));
		cubeGeometry.setNormal(6, new Vector3f(1.0f, 0.0f, 0.0f));
		cubeGeometry.setNormal(7, new Vector3f(1.0f, 0.0f, 0.0f));
		//2面
		cubeGeometry.setNormal(8, new Vector3f(0.0f, 0.0f, 1.0f));
		cubeGeometry.setNormal(9, new Vector3f(0.0f, 0.0f, 1.0f));
		cubeGeometry.setNormal(10, new Vector3f(0.0f, 0.0f, 1.0f));
		cubeGeometry.setNormal(11, new Vector3f(0.0f, 0.0f, 1.0f));
		//3面
		cubeGeometry.setNormal(12, new Vector3f(-1.0f, 0.0f, 0.0f));
		cubeGeometry.setNormal(13, new Vector3f(-1.0f, 0.0f, 0.0f));
		cubeGeometry.setNormal(14, new Vector3f(-1.0f, 0.0f, 0.0f));
		cubeGeometry.setNormal(15, new Vector3f(-1.0f, 0.0f, 0.0f));
		//上面
		cubeGeometry.setNormal(16, new Vector3f(0.0f, 1.0f, 0.0f));
		cubeGeometry.setNormal(17, new Vector3f(0.0f, 1.0f, 0.0f));
		cubeGeometry.setNormal(18, new Vector3f(0.0f, 1.0f, 0.0f));
		cubeGeometry.setNormal(19, new Vector3f(0.0f, 1.0f, 0.0f));
		//低面
		cubeGeometry.setNormal(20, new Vector3f(0.0f, -1.0f, 0.0f));
		cubeGeometry.setNormal(21, new Vector3f(0.0f, -1.0f, 0.0f));
		cubeGeometry.setNormal(22, new Vector3f(0.0f, -1.0f, 0.0f));
		cubeGeometry.setNormal(23, new Vector3f(0.0f, -1.0f, 0.0f));
		//頂点を指定して三角形作成
		//0面作成
		cubeGeometry.setCoordinateIndices(0, new int[]{1, 0, 3});
		cubeGeometry.setCoordinateIndices(3, new int[]{1, 3, 2});
		//1面作成
		cubeGeometry.setCoordinateIndices(6, new int[]{5, 4, 7});
		cubeGeometry.setCoordinateIndices(9, new int[]{5, 7, 6});
		//2面作成
		cubeGeometry.setCoordinateIndices(12, new int[]{11, 8, 9});
		cubeGeometry.setCoordinateIndices(15, new int[]{11, 9, 10});
		//3面作成
		cubeGeometry.setCoordinateIndices(18, new int[]{12, 13, 14});
		cubeGeometry.setCoordinateIndices(21, new int[]{12, 14, 15});
		//上面作成
		cubeGeometry.setCoordinateIndices(24, new int[]{16, 18, 17});
		cubeGeometry.setCoordinateIndices(27, new int[]{16, 19, 18});
		//底面作成
		cubeGeometry.setCoordinateIndices(30, new int[]{20, 22, 21});
		cubeGeometry.setCoordinateIndices(33, new int[]{20, 23, 22});
		//
		
		
		//パーツの色の設定
		//床
		Appearance groundApp = new Appearance();
		Material groundMa =new Material();
		groundMa.setDiffuseColor(0.8f,0.2f,0.0f);
		groundApp.setMaterial(groundMa); 
		
		//壁	
		Appearance wallApp = new Appearance();
		Material wallMa =new Material();
		wallMa.setDiffuseColor(0.0f, 1.0f, 1.0f);
		wallApp.setMaterial(wallMa);
		
		//障害物(Obstacle)
		Appearance ObstacleApp = new Appearance();
		Material ObstacleMa =new Material();
		ObstacleMa.setDiffuseColor(0.0f, 10.0f, 0.0f);
		ObstacleApp.setMaterial(ObstacleMa);
		
		//パーツの命名、色の設定
		Shape3D groundShape = new Shape3D(cubeGeometry, groundApp);
		Shape3D wallShape = new Shape3D(cubeGeometry,wallApp);
		Shape3D ObstacleShape =new Shape3D(cubeGeometry,ObstacleApp);
		
		//立方体を利用しステージのパーツ(地面。壁。障害物など)をObject3Dとして扱えるように設定
		//床
		Object3D ground = new Object3D("ground", groundShape);
		//壁(横長 zがマイナス側)
		Object3D wallM = new Object3D("wallM",wallShape);
		//壁(横長zがプラス側)
	    Object3D wallP = new Object3D("wallP",wallShape);
	    //壁(xがマイナス側)
	    Object3D wall_lM = new Object3D("wall_lM",wallShape);		
	    //壁(xがプラス側)
	    Object3D wall_lP = new Object3D("wall_lP",wallShape);		
        //障害物(obstacle)
	    Object3D Obstacle0=new Object3D("Obstacle0",ObstacleShape);
	    //障害物(obstacle)
	    Object3D Obstacle1=new Object3D("Obstacle1",ObstacleShape);
	    //障害物(obstacle)
	    Object3D Obstacle2=new Object3D("Obstacle2",ObstacleShape);
	    
	    //障害物(obstacle)
	    Object3D Obstacle3=new Object3D("Obstacle3",ObstacleShape);
	    //障害物(obstacle)
	    Object3D Obstacle4=new Object3D("Obstacle4",ObstacleShape);
	    
	    //障害物(obstacle)
	    Object3D Obstacle5=new Object3D("Obstacle5",ObstacleShape);
	    //障害物(obstacle)
	    Object3D Obstacle6=new Object3D("Obstacle6",ObstacleShape);

	   
	    //各ステージのパーツのサイズの設定
		//床
		ground.scale(320.0, 1.0, 160.0);
		//壁(横長マイナス側)Mは-の意味
		wallM.scale(320.0,100.0,10.0);
		//壁(横長プラス側)
		wallP.scale(320.0,100.0,10.0);
		//壁(マイナス側)
		wall_lM.scale(10.0,100.0,160.0);
		//壁(プラス側)
		wall_lP.scale(10.0,100.0,160.0);
		//障害物0
		Obstacle0.scale(50.0, 50.0, 20.0);
		
		//障害物1
		Obstacle1.scale(50.0, 50.0, 20.0);
		//障害物2
		Obstacle2.scale(50.0, 50.0, 20.0);
		
		//障害物3
		Obstacle3.scale(20.0, 20.0, 20.0);
		//障害物4
		Obstacle4.scale(20.0, 20.0, 20.0);
		
		//障害物5
		Obstacle5.scale(30.0, 20.0, 30.0);
		//障害物6
		Obstacle6.scale(30.0, 20.0, 30.0);
						
				

		//各ステージのパーツの移動&回転
		//床
	    Position3D groundpoint = new Position3D(-160.0,0.0,-80.0);
	    ground.setPosition( groundpoint);
		//壁(横長 zがマイナス側)
	    Position3D wallpointM = new Position3D(-160.0,0.0,-80.0);
	    wallM.setPosition(wallpointM);
	    //壁(横長 zがプラス側)
	    Position3D wallpointP = new Position3D(-160.0,0.0,80.0);
	    wallP.setPosition(wallpointP);
	    //壁(xがプラス側)
	    Position3D wallpoint_lM = new Position3D(-160.0,0.0,-80.0);
	    wall_lM.setPosition(wallpoint_lM);
	    //壁(xがプラス側)
	    Position3D wallpoint_lP = new Position3D(160.0,0.0,-80.0);
	    wall_lP.setPosition(wallpoint_lP);
		
	    //障害物0右下の横長の壁
	    Position3D Obstacle_0 = new Position3D(60.0,0.0,30.0);
	    Obstacle0.setPosition(Obstacle_0);
	    //障害物1左上の横長の壁
	    Position3D Obstacle_1 = new Position3D(-100.0,0.0,-50.0);
	    Obstacle1.setPosition(Obstacle_1);
	    //障害物2真ん中の壁
	    Position3D Obstacle_2 = new Position3D(10.0,0.0,30.0);
	    Obstacle2.setPosition(Obstacle_2);
	    //障害物2回転
	    Obstacle2.apply(new Quaternion3D(0.0,1.0,0.0,3*Math.PI/4), false);
	    
	    //障害物3
	    Position3D Obstacle_3 = new Position3D(90.0,0.0,-40.0);
	    Obstacle3.setPosition(Obstacle_3);
	    //障害物4
	    Position3D Obstacle_4 = new Position3D(-90.0,0.0,40.0);
	    Obstacle4.setPosition(Obstacle_4);
	    
	    //障害物5
	    Position3D Obstacle_5 = new Position3D(50.0,0.0,-70.0);
	    Obstacle5.setPosition(Obstacle_5);
	    //障害物6
	    Position3D Obstacle_6 = new Position3D(-50.0,0.0,60.0);
	    Obstacle6.setPosition(Obstacle_6);

	    
	    
	    groundObj = new Object3D("stage", new Object3D[]{ground,wallM,wallP,wall_lM,wall_lP,Obstacle0,Obstacle1,Obstacle2,Obstacle3,Obstacle4,Obstacle5,Obstacle6});

	
	
		
		
		
		
		
		
		
	
	}
	
	
}