OSDN Git Service

1193af29ef5876b422fd6020e3d313548a21261f
[mikutoga/TogaGem.git] / src / main / java / jp / sourceforge / mikutoga / vmd / model / binio / CameraLoader.java
1 /*
2  * camera information builder
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.util.List;
11 import jp.sourceforge.mikutoga.parser.MmdFormatException;
12 import jp.sourceforge.mikutoga.parser.ParseStage;
13 import jp.sourceforge.mikutoga.vmd.model.BezierParam;
14 import jp.sourceforge.mikutoga.vmd.model.CameraMotion;
15 import jp.sourceforge.mikutoga.vmd.model.CameraRotation;
16 import jp.sourceforge.mikutoga.vmd.model.PosCurve;
17 import jp.sourceforge.mikutoga.vmd.model.VmdMotion;
18 import jp.sourceforge.mikutoga.vmd.parser.VmdCameraHandler;
19
20 /**
21  * カメラ情報のビルダ。
22  */
23 class CameraLoader implements VmdCameraHandler {
24
25     private final List<CameraMotion> cameraMotionList;
26
27     private CameraMotion currentCameraMotion;
28
29
30     /**
31      * コンストラクタ。
32      * @param vmdMotion モーションデータ。
33      */
34     CameraLoader(VmdMotion vmdMotion){
35         super();
36         this.cameraMotionList = vmdMotion.getCameraMotionList();
37         this.currentCameraMotion = null;
38         return;
39     }
40
41
42     /**
43      * {@inheritDoc}
44      * @param stage {@inheritDoc}
45      * @param loops {@inheritDoc}
46      * @throws MmdFormatException {@inheritDoc}
47      */
48     @Override
49     public void loopStart(ParseStage stage, int loops)
50             throws MmdFormatException{
51         this.currentCameraMotion = new CameraMotion();
52         return;
53     }
54
55     /**
56      * {@inheritDoc}
57      * @param stage {@inheritDoc}
58      * @throws MmdFormatException {@inheritDoc}
59      */
60     @Override
61     public void loopNext(ParseStage stage)
62             throws MmdFormatException{
63         this.cameraMotionList.add(this.currentCameraMotion);
64         this.currentCameraMotion = new CameraMotion();
65         return;
66     }
67
68     /**
69      * {@inheritDoc}
70      * @param stage {@inheritDoc}
71      * @throws MmdFormatException {@inheritDoc}
72      */
73     @Override
74     public void loopEnd(ParseStage stage)
75             throws MmdFormatException{
76         this.currentCameraMotion = null;
77         return;
78     }
79
80     /**
81      * {@inheritDoc}
82      * @param keyFrameNo {@inheritDoc}
83      * @throws MmdFormatException {@inheritDoc}
84      */
85     @Override
86     public void vmdCameraMotion(int keyFrameNo) throws MmdFormatException{
87         this.currentCameraMotion.setFrameNumber(keyFrameNo);
88         return;
89     }
90
91     /**
92      * {@inheritDoc}
93      * @param xPos {@inheritDoc}
94      * @param yPos {@inheritDoc}
95      * @param zPos {@inheritDoc}
96      * @throws MmdFormatException {@inheritDoc}
97      */
98     @Override
99     public void vmdCameraPosition(float xPos, float yPos, float zPos)
100             throws MmdFormatException{
101         this.currentCameraMotion.getCameraTarget()
102                 .setPosition(xPos, yPos, zPos);
103         return;
104     }
105
106     /**
107      * {@inheritDoc}
108      * @param latitude {@inheritDoc}
109      * @param longitude {@inheritDoc}
110      * @param roll {@inheritDoc}
111      * @throws MmdFormatException {@inheritDoc}
112      */
113     @Override
114     public void vmdCameraRotation(float latitude,
115                                     float longitude,
116                                     float roll )
117             throws MmdFormatException{
118         CameraRotation rotation =
119                 this.currentCameraMotion.getCameraRotation();
120         rotation.setLatitude(latitude);
121         rotation.setLongitude(longitude);
122         rotation.setRoll(roll);
123         return;
124     }
125
126     /**
127      * {@inheritDoc}
128      * @param range {@inheritDoc}
129      * @throws MmdFormatException {@inheritDoc}
130      */
131     @Override
132     public void vmdCameraRange(float range) throws MmdFormatException{
133         this.currentCameraMotion.setRange(range);
134         return;
135     }
136
137     /**
138      * {@inheritDoc}
139      * @param angle {@inheritDoc}
140      * @param hasPerspective {@inheritDoc}
141      * @throws MmdFormatException {@inheritDoc}
142      */
143     @Override
144     public void vmdCameraProjection(int angle, boolean hasPerspective)
145             throws MmdFormatException{
146         this.currentCameraMotion.setProjectionAngle(angle);
147         this.currentCameraMotion.setPerspectiveMode(hasPerspective);
148         return;
149     }
150
151     /**
152      * {@inheritDoc}
153      * @param p1x {@inheritDoc}
154      * @param p1y {@inheritDoc}
155      * @param p2x {@inheritDoc}
156      * @param p2y {@inheritDoc}
157      * @throws MmdFormatException {@inheritDoc}
158      */
159     @Override
160     public void vmdCameraIntpltXpos(byte p1x, byte p1y, byte p2x, byte p2y)
161             throws MmdFormatException{
162         PosCurve posCurve = this.currentCameraMotion.getTargetPosCurve();
163         BezierParam bezier = posCurve.getIntpltXpos();
164         bezier.setP1(p1x, p1y);
165         bezier.setP2(p2x, p2y);
166         return;
167     }
168
169     /**
170      * {@inheritDoc}
171      * @param p1x {@inheritDoc}
172      * @param p1y {@inheritDoc}
173      * @param p2x {@inheritDoc}
174      * @param p2y {@inheritDoc}
175      * @throws MmdFormatException {@inheritDoc}
176      */
177     @Override
178     public void vmdCameraIntpltYpos(byte p1x, byte p1y, byte p2x, byte p2y)
179             throws MmdFormatException{
180         PosCurve posCurve = this.currentCameraMotion.getTargetPosCurve();
181         BezierParam bezier = posCurve.getIntpltYpos();
182         bezier.setP1(p1x, p1y);
183         bezier.setP2(p2x, p2y);
184         return;
185     }
186
187     /**
188      * {@inheritDoc}
189      * @param p1x {@inheritDoc}
190      * @param p1y {@inheritDoc}
191      * @param p2x {@inheritDoc}
192      * @param p2y {@inheritDoc}
193      * @throws MmdFormatException {@inheritDoc}
194      */
195     @Override
196     public void vmdCameraIntpltZpos(byte p1x, byte p1y, byte p2x, byte p2y)
197             throws MmdFormatException{
198         PosCurve posCurve = this.currentCameraMotion.getTargetPosCurve();
199         BezierParam bezier = posCurve.getIntpltZpos();
200         bezier.setP1(p1x, p1y);
201         bezier.setP2(p2x, p2y);
202         return;
203     }
204
205     /**
206      * {@inheritDoc}
207      * @param p1x {@inheritDoc}
208      * @param p1y {@inheritDoc}
209      * @param p2x {@inheritDoc}
210      * @param p2y {@inheritDoc}
211      * @throws MmdFormatException {@inheritDoc}
212      */
213     @Override
214     public void vmdCameraIntpltRotation(byte p1x, byte p1y,
215                                            byte p2x, byte p2y )
216             throws MmdFormatException{
217         BezierParam bezier = this.currentCameraMotion.getIntpltRotation();
218         bezier.setP1(p1x, p1y);
219         bezier.setP2(p2x, p2y);
220         return;
221     }
222
223     /**
224      * {@inheritDoc}
225      * @param p1x {@inheritDoc}
226      * @param p1y {@inheritDoc}
227      * @param p2x {@inheritDoc}
228      * @param p2y {@inheritDoc}
229      * @throws MmdFormatException {@inheritDoc}
230      */
231     @Override
232     public void vmdCameraIntpltRange(byte p1x, byte p1y, byte p2x, byte p2y)
233             throws MmdFormatException{
234         BezierParam bezier = this.currentCameraMotion.getIntpltRange();
235         bezier.setP1(p1x, p1y);
236         bezier.setP2(p2x, p2y);
237         return;
238     }
239
240     /**
241      * {@inheritDoc}
242      * @param p1x {@inheritDoc}
243      * @param p1y {@inheritDoc}
244      * @param p2x {@inheritDoc}
245      * @param p2y {@inheritDoc}
246      * @throws MmdFormatException {@inheritDoc}
247      */
248     @Override
249     public void vmdCameraIntpltProjection(byte p1x, byte p1y,
250                                               byte p2x, byte p2y )
251             throws MmdFormatException{
252         BezierParam bezier = this.currentCameraMotion.getIntpltProjection();
253         bezier.setP1(p1x, p1y);
254         bezier.setP2(p2x, p2y);
255         return;
256     }
257
258 }