Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: org/pqt/autorib/rib/RIBLight.java


1   //AutoRIB
2   // Copyright © 1998 - 2002, P W Quint
3   //
4   // Contact: autorib00@aol.com
5   //
6   // This library is free software; you can redistribute it and/or
7   // modify it under the terms of the GNU General Public
8   // License as published by the Free Software Foundation; either
9   // version 2 of the License, or (at your option) any later version.
10  //
11  // This library is distributed in the hope that it will be useful,
12  // but WITHOUT ANY WARRANTY; without even the implied warranty of
13  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  // General Public License for more details.
15  //
16  // You should have received a copy of the GNU General Public
17  // License along with this library; if not, write to the Free Software
18  // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  
20  package org.pqt.autorib.rib;
21  import java.io.*;
22  import java.util.*;
23  
24  import org.pqt.autorib.tokenizer.*;
25  import org.pqt.autorib.globals.*;
26  import org.pqt.autorib.util.*;
27  
28  /** Class for storing RIB lightsource calls
29   *@version $Header: /home/CVSRepository/autoribnew/org/pqt/autorib/rib/RIBLight.java,v 1.6 2003/11/17 00:10:26 remote Exp $
30   */
31  public class RIBLight extends RIBShader {
32      
33      public int lightHandle;
34      public static final boolean PRINTTRANSFORMS = true;
35      public RIBAttributeRec attributes;
36      public Matrix transform = null;
37      
38      public RIBLight() {
39          lightHandle = -1;
40      }
41      
42      public RIBLight(Tokenizer in)  throws FormatException, IOException {
43          lightHandle = -1;
44          read(in);
45      }
46      
47      public RIBLight(RIBLight l) {
48          super(l);
49          lightHandle = l.lightHandle;
50      }
51      
52      /**Construct a directional light
53       *@param handle the light handle;
54       *@param shader the shader to use
55       *@param from the from parameter for the light
56       *@param to the to parameter for the light*/
57      public RIBLight(int handle, String shader, Point from, Point to) {
58          requestID = RIBGlobals.LIGHTSOURCE;
59          requestName = RIBGlobals.requests[RIBGlobals.LIGHTSOURCE];
60          this.lightHandle = handle;
61          this.shaderName = shader;
62          deleted = false;
63          params = new RIBParams();
64          params.add("from", new Token(from));
65          params.add("to", new Token(to));
66      }
67      
68      /**Construct a directional light
69       *@param handle the light handle;
70       *@param shader the shader to use
71       *@param from the from parameter for the light
72       *@param to the to parameter for the light
73       @param coneAngle the coneangle for spotlight style lights*/
74      public RIBLight(int handle, String shader, Point from, Point to, float coneAngle) {
75          this(handle, shader, from, to);
76          params.add("coneangle", new Token(coneAngle));
77      }
78      
79      
80      public void read(Tokenizer in) throws IOException, FormatException {
81          readRequestName(in);
82          shaderName = in.getString();
83          lightHandle = (int)in.getNumber();
84          params.read(in);
85      }
86      
87      /*The standard write function, overridden to print out associated attributes*/
88      public void write(Writer out) throws IOException {
89          if (!deleted) {
90              if ((attributes != null) && (attributes.name.length() != 0))
91                  Token.write(out,"Attribute \"identifier\" \"name\" \"" + attributes.name + "\"\n");
92              if (attributes != null) 
93                  attributes.write(out);
94              writePreContent(out);
95              Token.write(out,requestName + " \"" + shaderName + "\" ");
96              Token.write(out,Integer.toString(lightHandle) + " ");
97              params.write(out);
98              Token.writeln(out);
99          }
100     }
101    
102     public double getConeAngle() throws FormatException {
103         double coneangle;
104         Token c;
105         c = params.get("coneangle");
106         if (c == null)
107             coneangle = -1;
108         else {
109             Float ca = c.getAsFloat();
110             if (ca != null)
111                 coneangle = ca.doubleValue();
112             else
113                 throw new FormatException(
114                 "Incorrect \"coneangle\" parameter in Light " +
115                 Integer.toString(lightHandle));
116         }
117         return coneangle;
118     }
119     
120     /**Try to locate a light's from or to parameter
121      *@param s is either "from" or "to"
122      *@return the parameter as a Point, or null if not found*/
123     public Point getPoint(String s)  {
124         Point p = null;
125         Token c;
126         c = params.get(s);
127         if (c != null) {
128             try {
129                 p = new Point(c.arrayVal);
130             }
131             catch (Exception e) {
132                 p = null;
133             }
134         }
135         
136         return p;
137     }
138     
139     public Object clone() {
140         return (Object) new RIBLight(this);
141     }
142 
143     public void setAttrs(RIBAttributeRec attrs) {
144         attributes = (RIBAttributeRec) attrs.clone();
145     }
146     
147     public void setTransform(Matrix transform) {
148         this.transform = (Matrix) transform.clone();
149     }
150     
151 }
152