OSDN Git Service

本番スキーマ移行
[mikutoga/Vmd2XML.git] / src / main / java / jp / sfjp / mikutoga / vmd / model / xml / SaxCameraListener.java
1 /*
2  * camera listener from XML
3  *
4  * License : The MIT License
5  * Copyright(c) 2013 MikuToga Partners
6  */
7
8 package jp.sfjp.mikutoga.vmd.model.xml;
9
10 import java.util.List;
11 import jp.sfjp.mikutoga.math.MkPos3D;
12 import jp.sfjp.mikutoga.vmd.model.BezierParam;
13 import jp.sfjp.mikutoga.vmd.model.CameraMotion;
14 import jp.sfjp.mikutoga.vmd.model.CameraRotation;
15 import jp.sfjp.mikutoga.vmd.model.PosCurve;
16 import jp.sfjp.mikutoga.vmd.model.VmdMotion;
17 import jp.sfjp.mikutoga.xml.SaxAttr;
18 import org.xml.sax.Attributes;
19
20 /**
21  * カメラ関連のXML要素出現イベントを受信する。
22  */
23 class SaxCameraListener extends SaxVmdListener{
24
25     private CameraMotion currentCamera = null;
26
27
28     /**
29      * コンストラクタ。
30      */
31     SaxCameraListener(){
32         super();
33         return;
34     }
35
36
37     /**
38      * {@inheritDoc}
39      * @param tag {@inheritDoc}
40      * @param attr {@inheritDoc}
41      */
42     @Override
43     void openTag(VmdTag tag, Attributes attr){
44         switch(tag){
45         case CAMERA_MOTION:
46             openCameraMotion(attr);
47             break;
48         case CAMERA_TARGET:
49             openCameraTarget(attr);
50             break;
51         case CAMERA_ROTATION:
52             openCameraRotation(attr);
53             break;
54         case CAMERA_RANGE:
55             openCameraRange(attr);
56             break;
57         case PROJECTION:
58             openProjection(attr);
59             break;
60
61         default:
62             super.openTag(tag, attr);
63             break;
64         }
65
66         return;
67     }
68
69     /**
70      * {@inheritDoc}
71      * @param tag {@inheritDoc}
72      */
73     @Override
74     void closeTag(VmdTag tag){
75         switch(tag){
76         case CAMERA_MOTION:
77             closeCameraMotion();
78             break;
79         case CAMERA_TARGET:
80             setCurrentPosCurve(null);
81             break;
82         case CAMERA_ROTATION:
83         case CAMERA_RANGE:
84         case PROJECTION:
85             setCurrentBezierParam(null);
86             break;
87         default:
88             super.closeTag(tag);
89             break;
90         }
91
92         return;
93     }
94
95     /**
96      * cameraMotion要素開始の通知。
97      * @param attr 属性群
98      */
99     private void openCameraMotion(Attributes attr){
100         this.currentCamera = new CameraMotion();
101
102         int frameNo = SaxAttr.getIntAttr(attr, XmlAttr.ATTR_FRAME);
103         this.currentCamera.setFrameNumber(frameNo);
104
105         boolean hasPerspective =
106                 SaxAttr.getBooleanAttr(attr,
107                                        XmlAttr.ATTR_HAS_PERSPECTIVE,
108                                        true );
109         this.currentCamera.setPerspectiveMode(hasPerspective);
110
111         return;
112     }
113
114     /**
115      * cameraMotion要素終了の通知。
116      */
117     private void closeCameraMotion(){
118         VmdMotion motion = getVmdMotion();
119         List<CameraMotion> cameraList = motion.getCameraMotionList();
120         cameraList.add(this.currentCamera);
121
122         this.currentCamera = null;
123
124         return;
125     }
126
127     /**
128      * cameraTarget要素開始の通知。
129      * @param attr 属性群
130      */
131     private void openCameraTarget(Attributes attr){
132         MkPos3D targetPos = this.currentCamera.getCameraTarget();
133
134         float xPos = SaxAttr.getFloatAttr(attr, XmlAttr.ATTR_X_POS);
135         float yPos = SaxAttr.getFloatAttr(attr, XmlAttr.ATTR_Y_POS);
136         float zPos = SaxAttr.getFloatAttr(attr, XmlAttr.ATTR_Z_POS);
137
138         targetPos.setPosition(xPos, yPos, zPos);
139
140         PosCurve curve = this.currentCamera.getTargetPosCurve();
141         setCurrentPosCurve(curve);
142
143         return;
144     }
145
146     /**
147      * cameraRotation要素開始の通知。
148      * @param attr 属性群
149      */
150     private void openCameraRotation(Attributes attr){
151         CameraRotation cameraRotation =
152                 this.currentCamera.getCameraRotation();
153
154         float latitude  = SaxAttr.getFloatAttr(attr, XmlAttr.ATTR_X_RAD);
155         float longitude = SaxAttr.getFloatAttr(attr, XmlAttr.ATTR_Y_RAD);
156         float roll      = SaxAttr.getFloatAttr(attr, XmlAttr.ATTR_Z_RAD);
157
158         cameraRotation.setLatitude(latitude);
159         cameraRotation.setLongitude(longitude);
160         cameraRotation.setRoll(roll);
161
162         BezierParam bez = this.currentCamera.getIntpltRotation();
163         setCurrentBezierParam(bez);
164
165         return;
166     }
167
168     /**
169      * cameraRange要素開始の通知。
170      * @param attr 属性群
171      */
172     private void openCameraRange(Attributes attr){
173         float range = SaxAttr.getFloatAttr(attr, XmlAttr.ATTR_RANGE);
174         this.currentCamera.setRange(range);
175
176         BezierParam bez = this.currentCamera.getIntpltRange();
177         setCurrentBezierParam(bez);
178
179         return;
180     }
181
182     /**
183      * projection要素開始の通知。
184      * @param attr 属性群
185      */
186     private void openProjection(Attributes attr){
187         int vertDeg = SaxAttr.getIntAttr(attr, XmlAttr.ATTR_VERT_DEG);
188         this.currentCamera.setProjectionAngle(vertDeg);
189
190         BezierParam bez = this.currentCamera.getIntpltProjection();
191         setCurrentBezierParam(bez);
192
193         return;
194     }
195
196 }