Would you like to make this site your homepage? It's fast and easy...
Yes, Please make this my home page!
sdi_obj.lua
1 -- SDI_HellCreator
2 -- Salomatine Dmitry.
3 -- sdihellcreator@bezeqint.net
4 -- Israel
5 -- original sdi_obj.lua
6 -- revision 13.04.2003
7 -- start obj definition
8 require("sdi_class");
9
10 Obj = {}
11
12 local Obj_mt = Class(Obj)
13
14 -- via new function must provide arguments
15 function Obj:new(name,px,py,pz,dx,dy,dz,sx,sy,sz)
16 return setmetatable({objname=name,pos={x=px, y=py,z=pz},
17 dir={x=dx, y=dy,z=dz},
18 sf={x=sx, y=sy,z=sz}}, Obj_mt)
19 end
20
21 --default constructor for objject but its just duplicate of new:)
22 --function Obj:Obj()
23 --return setmetatable({objname="NoName",pos={x=0, y=0,z=0},
24 --dir={x=0, y=0,z=0},
25 --sf={x=0, y=0,z=0}}, Obj_mt)
26 --end
27
28 --default constructor for objject via new
29 function Obj:Obj()
30 return Obj:new("NoName",0,0,0,0,0,0,0,0,0);
31 end
32 -- set/get name of object(1=set)
33 function Obj:Name(sg,name)
34 if sg==1 then -- set
35 self.objname=name;
36 else -- get
37 return self.objname;
38 end
39 end
40 -- set/get position
41 function Obj:Pos(sg,x,y,z)
42 if sg==1 then -- set
43 self.pos.x=x;
44 self.pos.y=y;
45 self.pos.z=z;
46 else -- get
47 return self.pos.x,self.pos.y,self.pos.z;
48 end
49 end
50 -- set/get direction
51 function Obj:Dir(sg,x,y,z)
52 if sg==1 then --set
53 self.dir.x=x;
54 self.dir.y=y;
55 self.dir.z=z;
56 else -- get
57 return self.dir.x,self.dir.y,self.dir.z;
58 end
59 end
60 -- set/get Scale Factor
61 function Obj:ScaleF(sg,x,y,z)
62 if sg==1 then --set
63 self.sf.x=x;
64 self.sf.y=y;
65 self.sf.z=z;
66 else -- get
67 return self.sf.x,self.sf.y,self.sf.z;
68 end
69 end
70 -- prints all information
71 function Obj:Pinfo()
72 print("Obj's name is"..self:Name());
73 print("Obj's position is",self:Pos());
74 print("Obj's direction is",self:Dir());
75 print("Obj's scale is",self:ScaleF());
76 end
77
78 --test objects creation and copyng and default constructor
79
80 ob1=Obj:new("Cube",0,0,0,0,1,0,1,1,1);
81 ob2=Obj:new("Cilinder",10,10,10,0,1,0,1,1,1);
82 ob1:Pinfo();
83 ob2:Pinfo();
84 ob3=ob1:copy();-- create ob3 and copy ob1 to ob3
85 ob3:Name(1,"NewName");-- set new name
86 ob3:Pinfo();
87 ob4=Obj:Obj();
88 ob4:Pinfo();