1 /*****************************************************************************
2 * Virtual Mockup for Machine Vision
3 * Copyright (C) 2001-2003 Fabio R. de Miranda, João E. Kogler Jr.,
4 * Carlos S. Santos.
5 * Virtual Mockup for Machine Vision Project funded by SENAC-SP
6 *
7 * Permission is granted to redistribute and/or modify this
8 * software under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * This software is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License (http://www.gnu.org/copyleft/lesser.html)
16 * for more details.
17 *
18 *****************************************************************************/
19
20 package camera3d;
21
22 /***
23 *
24 * @author Fábio Roberto de Miranda e Carlos da Silva dos Santos
25 */
26 import org.jdom.*;
27 import javax.vecmath.*;
28
29 class VcPointLightXMLHandler extends VcLightXMLHandler {
30
31
32 private static final String constAttrib = "ConstantAttenuation";
33 private static final String linearAttrib = "LinearAttenuation";
34 private static final String quadAttrib = "QuadraticAttenuation";
35
36 public VcPointLightXMLHandler() {
37 super();
38 this.type ="VcPointLight";
39 }
40
41 public Element createElement(VcObject obj){
42 if(!(obj instanceof VcPointLight)) return null;
43 Element element = super.createElement(obj);
44 VcPointLight point = (VcPointLight)obj;
45 //element.setName(type);
46 Point3f tempP3f = point.getAttenuation();
47 element.setAttribute(constAttrib,Float.toString(tempP3f.x));
48 element.setAttribute(linearAttrib,Float.toString(tempP3f.y));
49 element.setAttribute(quadAttrib,Float.toString(tempP3f.z));
50
51 return element;
52 }
53
54 public VcObject createObject (Element el){
55 if(!type.equals(el.getName())) return null;
56 VcPointLight light = new VcPointLight();
57 initializeObject(el,light);
58
59 return (VcObject)light;
60 }
61
62 public void initializeObject(Element el,VcObject obj){
63 super.initializeObject(el,obj);
64 if(!(obj instanceof VcPointLight)) return;
65 VcPointLight light = (VcPointLight)obj;
66 Point3f tempP3f= new Point3f(1.0f,0.0f,0.0f);
67 try{
68 tempP3f.x = el.getAttribute(constAttrib).getFloatValue();
69 tempP3f.y = el.getAttribute(linearAttrib).getFloatValue();
70 tempP3f.z = el.getAttribute(quadAttrib).getFloatValue();
71 }catch(org.jdom.DataConversionException dce){
72 dce.printStackTrace();
73 }
74 light.setAttenuation(tempP3f);
75 }
76
77 void addObject(VcObject vcObject, J3DBase base){
78 if(!(vcObject instanceof VcPointLight))return;
79 VcObject obj = base.getByLabel(vcObject.getLabel());
80 if(obj!=null){
81 if(obj instanceof VcPointLight) base.removeVcObject(obj);
82 else obj.setLabel("_"+obj.getLabel());
83 }
84
85 base.addLight((VcLight)vcObject);
86 }
87
88 }
This page was automatically generated by Maven