CGAugmentedRealityProject is an open source project powered by Assembla

Assembla offers free public and private SVN/Git repositories and project hosting with bug/issue tracking and collaboration tools.

CGAugmentedRealityProject

/projetocg
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
/*
** ARToolKit object parsing function
**   - reads in object data from object file in Data/object_data
**
** Format:
** <obj_num>
**
** <obj_name>
** <obj_pattern filename>
** <marker_width>
** <centerX centerY>
**
** ...
**
**    eg
**
**    #pattern 1
**    Hiro
**    Data/hiroPatt
**    80.0
**    0.0 0.0
**
*/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <AR/ar.h>
#include "object.h"

static char *get_buff( char *buf, int n, FILE *fp );

int colidiu( ObjectData_T obj1, ObjectData_T obj2)
{
    float x1,y1,z1;
    float x2,y2,z2;
    float dist;
    float minima = 15000.0;

    x1 = obj1.trans[0][3];
    y1 = obj1.trans[1][3];
    z1 = obj1.trans[2][3];

    x2 = obj2.trans[0][3];
    y2 = obj2.trans[1][3];
    z2 = obj2.trans[2][3];

    dist = (x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)+(z1-z2)*(z1-z2);

    if(dist < minima)
        return 1;
    else
        return 0;
}


ObjectData_T *read_ObjData( const char *name, int *objectnum )
{
    FILE          *fp;
    ObjectData_T  *object;
    char           buf[256], buf1[256];
    int            i;
    int c = 0;
    printf("Opening Data File %s\n",name);

    if( (fp=fopen(name, "r")) == NULL ) {
        printf("Can't find the file - quitting \n");
        return(0);
    }

    get_buff(buf, 256, fp);
    if( sscanf(buf, "%d", objectnum) != 1 ) {fclose(fp); return(0);}

    printf("About to load %d Models\n",*objectnum);

    object = (ObjectData_T *)malloc( sizeof(ObjectData_T) * *objectnum );
    if( object == NULL ) return(0);

    for( i = 0; i < *objectnum; i++ ) {
        object[i].visible = 0;

        get_buff(buf, 256, fp);
        if( sscanf(buf, "%s", object[i].name) != 1 ) {
            fclose(fp); free(object); return(0);
        }

        printf("Read in No.%d \n", i+1);

        get_buff(buf, 256, fp);
    c++;
    printf("%d\n", c);
        if( sscanf(buf, "%s", buf1) != 1 ) {
          fclose(fp); free(object); return(0);
    }
    c++;
    printf("%d\n", c);

        if( (object[i].id = arLoadPatt(buf1)) < 0 )
            {fclose(fp); free(object); return(0);}
    c++;
    printf("%d\n", c);

        get_buff(buf, 256, fp);
        if( sscanf(buf, "%lf", &object[i].marker_width) != 1 ) {
            fclose(fp); free(object); return(0);
        }

    c++;
    printf("%d\n", c);

        get_buff(buf, 256, fp);
        /*if( sscanf(buf, "%lf %lf", &object[i].marker_center[0],
            &object[i].marker_center[1]) != 2 ) {
            fclose(fp); free(object); return(0);
        }*/
    c++;
    printf("%d\n", c);

    }

    fclose(fp);
    c++;
    printf("%d\n", c);
    return( object );
}

static char *get_buff( char *buf, int n, FILE *fp )
{
    char *ret;

    for(;;) {
        ret = fgets( buf, n, fp );
        if( ret == NULL ) return(NULL);
        if( buf[0] != '\n' && buf[0] != '#' ) return(ret);
    }
}
Ajax-loader Loading, please wait...