OSDN Git Service

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