Example #1
0
    virtual void calc()
    {
        if( fn_bind() )  // Check bind state, to avoid GPF "Global Protection Fault" on next steps
        {
            if( fn_calc() )
            {
                // GetProjectionMatrix()
                glm::mat4 camera_projection_matrix;
                
                float w = ( mp_size->data[0] > 1 ) ? mp_size->data[0] : 1;
                float h = ( mp_size->data[1] > 1 ) ? mp_size->data[1] : 1;
                float aspect = w / h;

                camera_projection_matrix = glm::perspective
                    ( mp_fov->data.at(0)    // 45.f   <= fov
                    , aspect                // width / height
                    , mp_near->data.at(0)   // 0.1f   <= near clip plane
                    , mp_far->data.at(0)    // 100.0f <= far clip plane
                    );
                
                // save camera_projection_matrix to gdom "proj"
                set_m4_from_glm_mat4( mp_proj, camera_projection_matrix );

                return gx::fn::calc_success();
            }
            return fn_calc_failed();
        }
        return fn_bind_failed();
    }
Example #2
0
    virtual void calc()
    {
        // Calc a GetViewProjectionMatrix()
        // MVP = GetProjectionMatrix() * GetViewMatrix() * GetModelMatrix();
        // MVP = GetViewProjectionMatrix() * GetModelMatrix();
        if( fn_bind() ) // avoid GPF!
        {
            if( fn_calc() ) // calculate self input values, before self output
            {
                glm::mat4 view, proj, view_proj;

                // load calculated input from gdom:
                set_glm_mat4_from_m4(view, mp_view);  // load from gdom 'view'
                set_glm_mat4_from_m4(proj, mp_proj);  // load from gdom 'proj'

                // at last can calc output value!
                view_proj = proj * view;              // use temp var visible at debug time

                // save calculated output to gdom
                set_m4_from_glm_mat4( mp_view_proj, view_proj ); // save in gdom 'view_proj'

                // chande self DG state to GOOD, and invalidate:
                return calc_success();
            }
            return fn_calc_failed();
        }
        return fn_bind_failed();
    }
Example #3
0
    virtual void calc()
    {
        if( fn_bind() )          // avoid GPF!
        {
            if( fn_calc() )      // check or recalc input
            {

                glm::mat4 camera_world_position(1.f);                 // camera world position
                glm::mat4 camera_view(1.f);                           // camera view transformation

                // load camera world position from gdom "wpos"
                set_glm_mat4_from_m4(camera_world_position, mp_wpos); // init glm-variable from gx-gdom-field

                // GetViewMatrix() const
                float* cwp = glm::value_ptr(camera_world_position);   // used as float[16]
                glm::vec3 camera_position(cwp[12], cwp[13], cwp[14]); // cwp translation;
                glm::vec3 z(cwp[ 2], cwp[ 6], cwp[10]);               // cwp z-vector;
                glm::vec3 look_at_point = camera_position + z;
                glm::vec3 up_vector      (cwp[ 1], cwp[ 5], cwp[ 9]); // cwp y-vector;

                camera_view = glm::lookAt(camera_position, look_at_point, up_vector);

                // save camera_view to gdom "view"
                set_m4_from_glm_mat4(mp_view, camera_view);

                // reset state to GOOD
                return gx::fn::calc_success();
            }
            else
            {
                return gx::fn::fn_calc_failed();
            }
        }
        else
        {
            return gx::fn::fn_bind_failed();
        }
    }
Example #4
0
void FnExpr::bind(NameSema& sema) const { fn_bind(sema); }
Example #5
0
void FnDecl::bind(NameSema& sema) const {
    fn_bind(sema);
}
Example #6
0
int
main(int argc, char **argv)
{
    FILE *fin, *fout;
    char line[4096], *p, *tok, **args;
    char tmp[128];
    struct binding *b;
    int i, j, off, argoff;
    int maxkey;

    prg = argv[0];
    rc_inrc = 1;
    maxkey = max_fnkey + 256;

    if (argc == 2 && strcmp(argv[1], ".") != 0)
	srcdir = argv[1];
    else
	srcdir = NULL;

    initnames();

    for (i=0; i<maxkey; i++) {
	binding[i].next = NULL;
	binding[i].state = bs_none;
	binding[i].fn = -1;
	binding[i].args = NULL;
    }
    off = 0;


    /* processing ``bindings.desc'' */

    if ((fin=vpath_open(FNAME ".desc")) == NULL)
	exit(1);

    rc_lineno = 0;
    while (fgets(line, 4096, fin) != NULL) {
	rc_lineno++;
	p = line;
	if ((tok=rc_token(&p)) == NULL || tok[0] == '#')
	    continue;
	if (strcasecmp(tok, "bind") != 0) {
	    rc_error("non-bind command ignored: %s", tok);
	    continue;
	}
	
	args = rc_list(p);

	fn_bind(args);
    }
    
    if (ferror(fin)) {
	fprintf(stderr, "%s: read error in `%s': %s.\n",
		prg, rc_filename, strerror(errno));
	fclose(fin);
	exit(1);
    }
    fclose(fin);
    free(rc_filename);
    rc_filename = NULL;


    /* writing ``bindings.c'' in temp file */

    sprintf(tmp, FNAME ".c.%d", getpid());

    if ((fout=fopen(tmp, "w")) == NULL) {
	fprintf(stderr, "%s: can't open output file `%s': %s.\n",
		prg, tmp, strerror(errno));
	exit(1);
    }

    fprintf(fout, "%s", header);


    /* output: bindings */

    off = argoff = 0;
    fprintf(fout, "struct binding " NAME "[] = {\n");
    for (i=0; i<maxkey; i++) {
	fprintf(fout, "    { ");
	if (binding[i].next) {
	    fprintf(fout, "binding_pool+%3d, ", off);
	    for (b=binding[i].next; b; b=b->next)
		off++;
	}
	else
	    fprintf(fout, "NULL            , ");
	if (binding[i].state+1 < nstates)
	    fprintf(fout, "%s, ", states[binding[i].state+1]);
	else
	    fprintf(fout, "%d, ", binding[i].state);
	fprintf(fout, "%3d, ", binding[i].fn);
	if (binding[i].args) {
	    fprintf(fout, "binding_argpool+%d },\n", argoff);
	    for (j=0; binding[i].args[j]; j++)
		;
		argoff += j+1;
	}
	else
	    fprintf(fout, "NULL },\n");
    }
    fprintf(fout, "};\n\n");

    if (ferror(fout)) {
	fprintf(stderr, "%s: write error on `%s': %s.\n",
		prg, FNAME ".c", strerror(errno));
	exit(1);
	fclose(fout);
    }

    /* output: bindings_pool */

    off = 1;
    fprintf(fout, "struct binding " NAME "_" POOL "[] = {\n");
    for (i=0; i<maxkey; i++)
	if (binding[i].next) {
	    for (b=binding[i].next; b; b=b->next) {
		fprintf(fout, "    { ");
		if (b->next)
		    fprintf(fout, "binding_pool+%3d, ", off);
		else
		    fprintf(fout, "NULL            , ");
		if (b->state+1 < nstates)
		    fprintf(fout, "%s, ", states[b->state+1]);
		else
		    fprintf(fout, "%d, ", b->state);
		fprintf(fout, "%3d, ", b->fn);
		if (b->args) {
		    fprintf(fout, "binding_argpool+%d },\n", argoff);
		    for (j=0; b->args[j]; j++)
			;
		    argoff += j+1;
		}
		else
		    fprintf(fout, "NULL },\n");

		off++;
	    }
	}
    fprintf(fout, "};\n\n");
    fprintf(fout, "int " NAME "_n" POOL " = sizeof(" NAME "_" POOL ")"
	    " / sizeof(" NAME "_" POOL "[0]);\n\n");
    
    if (ferror(fout)) {
	fprintf(stderr, "%s: write error on `%s': %s.\n",
		prg, FNAME ".c", strerror(errno));
	exit(1);
	fclose(fout);
    }

    
    /* output: binding_argpool */

    fprintf(fout, "char *" NAME "_" ARGS "[] = {\n   ");
    for (i=0; i<maxkey; i++)
	if (binding[i].args)
	    print_args(fout, binding[i].args);
    for (i=0; i<maxkey; i++)
	if (binding[i].next)
	    for (b=binding[i].next; b; b=b->next)
		if (b->args)
		    print_args(fout, b->args);
    fprintf(fout, "\n};\n\n");

    fprintf(fout, "int " NAME "_n" ARGS " = sizeof(" NAME "_" ARGS ")"
	    " / sizeof(" NAME "_" ARGS "[0]);\n");

    if (ferror(fout)) {
	fprintf(stderr, "%s: write error on `%s': %s.\n",
		prg, FNAME ".c", strerror(errno));
	fclose(fout);
	exit(1);
    }

    fclose(fout);

    /* rename tmp file to ``bindings.c'' */

    if (rename(tmp, FNAME ".c") < 0) {
	fprintf(stderr, "%s: cannot rename `%s' to `%s': %s\n",
		prg, tmp, FNAME ".c", strerror(errno));
	exit(1);
    }

    exit(0);
}