OSDN Git Service

モデルデータ不備の異常系を別パッケージに
[mikutoga/TogaGem.git] / src / main / java / jp / sourceforge / mikutoga / vmd / model / binio / CameraExporter.java
1 /*
2  * camera information exporter
3  *
4  * License : The MIT License
5  * Copyright(c) 2011 MikuToga Partners
6  */
7
8 package jp.sourceforge.mikutoga.vmd.model.binio;
9
10 import java.io.IOException;
11 import java.io.OutputStream;
12 import java.util.List;
13 import jp.sourceforge.mikutoga.binio.BinaryExporter;
14 import jp.sourceforge.mikutoga.math.MkPos3D;
15 import jp.sourceforge.mikutoga.vmd.model.BezierParam;
16 import jp.sourceforge.mikutoga.vmd.model.CameraMotion;
17 import jp.sourceforge.mikutoga.vmd.model.CameraRotation;
18 import jp.sourceforge.mikutoga.vmd.model.PosCurve;
19 import jp.sourceforge.mikutoga.vmd.model.VmdMotion;
20
21 /**
22  * カメラ情報のエクスポーター。
23  */
24 class CameraExporter extends BinaryExporter {
25
26     /**
27      * コンストラクタ。
28      * @param stream 出力ストリーム
29      */
30     CameraExporter(OutputStream stream){
31         super(stream);
32         return;
33     }
34
35
36     /**
37      * カメラモーション情報を出力する。
38      * @param motion モーションデータ
39      * @throws IOException 出力エラー
40      */
41     void dumpCameraMotion(VmdMotion motion) throws IOException{
42         List<CameraMotion> list = motion.getCameraMotionList();
43
44         int count = list.size();
45         dumpInt(count);
46
47         for(CameraMotion cameraMotion : list){
48             int frame = cameraMotion.getFrameNumber();
49             dumpInt(frame);
50
51             float range = cameraMotion.getRange();
52             dumpFloat(range);
53
54             MkPos3D targetPos = cameraMotion.getCameraTarget();
55             dumpFloat((float) targetPos.getXpos());
56             dumpFloat((float) targetPos.getYpos());
57             dumpFloat((float) targetPos.getZpos());
58
59             CameraRotation rotation = cameraMotion.getCameraRotation();
60             dumpFloat(rotation.getLatitude());
61             dumpFloat(rotation.getLongitude());
62             dumpFloat(rotation.getRoll());
63
64             dumpCameraCurve(cameraMotion);
65
66             dumpInt(cameraMotion.getProjectionAngle());
67
68             byte perspectiveSwitch;
69             if(cameraMotion.hasPerspective()) perspectiveSwitch = 0x00;
70             else                              perspectiveSwitch = 0x01;
71             dumpByte(perspectiveSwitch);
72         }
73
74         return;
75     }
76
77     /**
78      * カメラ補間情報を出力する。
79      * @param cameraMotion モーションデータ
80      * @throws IOException 出力エラー
81      */
82     private void dumpCameraCurve(CameraMotion cameraMotion)
83             throws IOException{
84         PosCurve posCurve = cameraMotion.getTargetPosCurve();
85         BezierParam xCurve = posCurve.getIntpltXpos();
86         BezierParam yCurve = posCurve.getIntpltYpos();
87         BezierParam zCurve = posCurve.getIntpltZpos();
88         dumpCameraBezier(xCurve);
89         dumpCameraBezier(yCurve);
90         dumpCameraBezier(zCurve);
91
92         BezierParam rotCurve   = cameraMotion.getIntpltRotation();
93         BezierParam rangeCurve = cameraMotion.getIntpltRange();
94         BezierParam projCurve  = cameraMotion.getIntpltProjection();
95         dumpCameraBezier(rotCurve);
96         dumpCameraBezier(rangeCurve);
97         dumpCameraBezier(projCurve);
98
99         return;
100     }
101
102     /**
103      * ベジェ曲線情報を出力する。
104      * @param bezier ベジェ曲線
105      * @throws IOException 出力エラー
106      */
107     private void dumpCameraBezier(BezierParam bezier) throws IOException{
108         dumpByte(bezier.getP1x());
109         dumpByte(bezier.getP2x());
110         dumpByte(bezier.getP1y());
111         dumpByte(bezier.getP2y());
112
113         return;
114     }
115
116 }