Revision 1025,
1.4 KB
checked in by gumbau, 18 years ago
(diff) |
namespace simplif
|
Line | |
---|
1 | //#include <iostream.h>
|
---|
2 | #include <string.h>
|
---|
3 |
|
---|
4 | #include <gfx/std.h>
|
---|
5 | #include <gfx/SMF/smf.h>
|
---|
6 | #include <gfx/SMF/smfstate.h>
|
---|
7 |
|
---|
8 | inline int streq(const char *a,const char *b) { return strcmp(a,b)==0; }
|
---|
9 |
|
---|
10 | using namespace simplif;
|
---|
11 |
|
---|
12 | SMF_State::SMF_State(const SMF_ivars& ivar, SMF_State *link)
|
---|
13 | {
|
---|
14 | next = link;
|
---|
15 | first_vertex = ivar.next_vertex;
|
---|
16 | if( next )
|
---|
17 | {
|
---|
18 | vertex_correction = next->vertex_correction;
|
---|
19 | xform = next->xform;
|
---|
20 | }
|
---|
21 | else
|
---|
22 | {
|
---|
23 | vertex_correction = 0;
|
---|
24 | xform = Mat4::identity;
|
---|
25 | }
|
---|
26 |
|
---|
27 | }
|
---|
28 |
|
---|
29 | void SMF_State::vertex(Vec3& v)
|
---|
30 | {
|
---|
31 | Vec4 v2 = xform * Vec4(v,1);
|
---|
32 |
|
---|
33 | v[X] = v2[X]/v2[W];
|
---|
34 | v[Y] = v2[Y]/v2[W];
|
---|
35 | v[Z] = v2[Z]/v2[W];
|
---|
36 | }
|
---|
37 |
|
---|
38 | void SMF_State::normal(Vec3& v)
|
---|
39 | {
|
---|
40 | Vec4 v2 = xform * Vec4(v,0);
|
---|
41 |
|
---|
42 | // v[X] = v2[X]/v2[W];
|
---|
43 | // v[Y] = v2[Y]/v2[W];
|
---|
44 | // v[Z] = v2[Z]/v2[W];
|
---|
45 |
|
---|
46 | v[X] = v2[X];
|
---|
47 | v[Y] = v2[Y];
|
---|
48 | v[Z] = v2[Z];
|
---|
49 | }
|
---|
50 |
|
---|
51 | void SMF_State::face(buffer<int>& verts, const SMF_ivars& ivar)
|
---|
52 | {
|
---|
53 | for(int i=0; i<verts.length(); i++)
|
---|
54 | {
|
---|
55 | if( verts(i) < 0 )
|
---|
56 | verts(i) += ivar.next_vertex;
|
---|
57 | else
|
---|
58 | verts(i) += vertex_correction + (first_vertex - 1);
|
---|
59 | }
|
---|
60 | }
|
---|
61 |
|
---|
62 | void SMF_State::set(string_buffer& argv)
|
---|
63 | {
|
---|
64 | char *cmd = argv(0);
|
---|
65 |
|
---|
66 | if( streq(cmd, "vertex_correction") )
|
---|
67 | vertex_correction = atoi(argv(1));
|
---|
68 | }
|
---|
69 |
|
---|
70 | void SMF_State::mmult(const Mat4& M)
|
---|
71 | {
|
---|
72 | xform = xform * M;
|
---|
73 | }
|
---|
74 |
|
---|
75 | void SMF_State::mload(const Mat4& M)
|
---|
76 | {
|
---|
77 | xform = M;
|
---|
78 | }
|
---|
Note: See
TracBrowser
for help on using the repository browser.