ambient_occlusion_lightmap::ambient_occlusion_lightmap
            (world& c, const ptree& config)
    : lightmap_generator_i (c, config)
{
    detail_levels_.emplace_back(precalc(10, 10));
    detail_levels_.emplace_back(precalc(30, 40));
    detail_levels_.emplace_back(precalc(60, 100));
}
예제 #2
0
/* precalculate region masks/sets from cp15 register */
void armcp15_t::maskPrecalc()
{
#define precalc(num) {  \
	u32 mask = 0, set = 0xFFFFFFFF ; /* (x & 0) == 0xFF..FF is allways false (disabled) */  \
	if (BIT_N(protectBaseSize[num],0)) /* if region is enabled */ \
	{    /* reason for this define: naming includes var */  \
	mask = CP15_MASKFROMREG(protectBaseSize[num]) ;   \
	set = CP15_SETFROMREG(protectBaseSize[num]) ; \
	if (CP15_SIZEIDENTIFIER(protectBaseSize[num])==0x1F)  \
	{   /* for the 4GB region, u32 suffers wraparound */   \
	mask = 0 ; set = 0 ;   /* (x & 0) == 0  is allways true (enabled) */  \
} \
}  \
	setSingleRegionAccess(num, mask, set) ;  \
}
	precalc(0) ;
	precalc(1) ;
	precalc(2) ;
	precalc(3) ;
	precalc(4) ;
	precalc(5) ;
	precalc(6) ;
	precalc(7) ;
#undef precalc
}
예제 #3
0
파일: dcp.c 프로젝트: bgromov/rawstudio
static void
read_profile(RSDcp *dcp, RSDcpFile *dcp_file)
{
	gint i;
	free_dcp_profile(dcp);
	
	/* ColorMatrix */
	dcp->has_color_matrix1 = rs_dcp_file_get_color_matrix1(dcp_file, &dcp->color_matrix1);
	dcp->has_color_matrix2 = rs_dcp_file_get_color_matrix2(dcp_file, &dcp->color_matrix2);

	/* CalibrationIlluminant */
	dcp->temp1 = rs_dcp_file_get_illuminant1(dcp_file);
	dcp->temp2 = rs_dcp_file_get_illuminant2(dcp_file);
	/* FIXME: If temp1 > temp2, swap them and data*/	

	/* ProfileToneCurve */
	dcp->tone_curve = rs_dcp_file_get_tonecurve(dcp_file);
	if (!dcp->tone_curve)
	{
		gint num_knots = adobe_default_table_size;
		gfloat *knots = g_new0(gfloat, adobe_default_table_size * 2);

		for(i = 0; i < adobe_default_table_size; i++)
		{
			knots[i*2] = (gfloat)i / (gfloat)adobe_default_table_size;
			knots[i*2+1] = adobe_default_table[i];
		}
		dcp->tone_curve = rs_spline_new(knots, num_knots, NATURAL);
		g_free(knots);
	}
	g_assert(0 == posix_memalign((void**)&dcp->tone_curve_lut, 16, sizeof(gfloat)*2*1025));
	gfloat *tc = rs_spline_sample(dcp->tone_curve, NULL, 1024);
	for (i=0; i< 1024; i++)
	{
		if (i>0)
			dcp->tone_curve_lut[i*2-1] = tc[i];
		dcp->tone_curve_lut[i*2] = tc[i];
	}
	dcp->tone_curve_lut[1024*2-1] = dcp->tone_curve_lut[1024*2] = dcp->tone_curve_lut[1024*2+1] = tc[1023];
	g_free(tc);

	/* ForwardMatrix */
	dcp->has_forward_matrix1 = rs_dcp_file_get_forward_matrix1(dcp_file, &dcp->forward_matrix1);
	dcp->has_forward_matrix2 = rs_dcp_file_get_forward_matrix2(dcp_file, &dcp->forward_matrix2);
	if (dcp->has_forward_matrix1)
		normalize_forward_matrix(&dcp->forward_matrix1);
	if (dcp->has_forward_matrix2)
		normalize_forward_matrix(&dcp->forward_matrix2);

	dcp->looktable = rs_dcp_file_get_looktable(dcp_file);

	dcp->huesatmap1 = rs_dcp_file_get_huesatmap1(dcp_file);
	dcp->huesatmap2 = rs_dcp_file_get_huesatmap2(dcp_file);
	dcp->huesatmap = 0;
	dcp->use_profile = TRUE;
	set_white_xy(dcp, &dcp->white_xy);
	precalc(dcp);
}
예제 #4
0
int main()
{
    precalc();
    int n;
    scanf("%d", &n);
    do {
        printf("The %d%s humble number is %d.\n", n, suffix(n), a[n - 1]);
        scanf("%d", &n);
    } while (n != 0);
    return 0;
}
예제 #5
0
파일: dcp.c 프로젝트: bgromov/rawstudio
static void
set_property(GObject *object, guint property_id, const GValue *value, GParamSpec *pspec)
{
	RSDcp *dcp = RS_DCP(object);
	RSFilter *filter = RS_FILTER(dcp);
	gpointer temp;
	gboolean changed = FALSE;

	switch (property_id)
	{
		case PROP_SETTINGS:
			if (dcp->settings && dcp->settings_signal_id)
			{
				if (dcp->settings == g_value_get_object(value))
				{
					settings_changed(dcp->settings, MASK_ALL, dcp);
					break;
				}
				g_signal_handler_disconnect(dcp->settings, dcp->settings_signal_id);
				g_object_weak_unref(G_OBJECT(dcp->settings), settings_weak_notify, dcp);
			}
			dcp->settings = g_value_get_object(value);
			dcp->settings_signal_id = g_signal_connect(dcp->settings, "settings-changed", G_CALLBACK(settings_changed), dcp);
			settings_changed(dcp->settings, MASK_ALL, dcp);
			g_object_weak_ref(G_OBJECT(dcp->settings), settings_weak_notify, dcp);
			break;
		case PROP_PROFILE:
			g_static_rec_mutex_lock(&dcp_mutex);
			read_profile(dcp, g_value_get_object(value));
			changed = TRUE;
			g_static_rec_mutex_unlock(&dcp_mutex);
			break;
		case PROP_READ_OUT_CURVE:
			temp = g_value_get_object(value);
			if (temp != dcp->read_out_curve)
				changed = TRUE;
			dcp->read_out_curve = temp;
			break;
		case PROP_USE_PROFILE:
			g_static_rec_mutex_lock(&dcp_mutex);
			dcp->use_profile = g_value_get_boolean(value);
			if (!dcp->use_profile)
				free_dcp_profile(dcp);
			else
				precalc(dcp);
			g_static_rec_mutex_unlock(&dcp_mutex);
			break;
		default:
			G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
	}

	if (changed)
		rs_filter_changed(filter, RS_FILTER_CHANGED_PIXELDATA);
}
int main() {
	precalc();
	int T;
	scanf("%d", &T);
	for (int t = 0; t < T; ++t) {
		// we read @S and @M as strings
		// since it is convenient to work with them as with strings
		char S[maxL + 1], M[maxL + 1];
		scanf("%s%s", S, M);
		int ans = solve(S, M);
		printf("%d\n", ans);
	}
	return 0;
}
예제 #7
0
파일: GRect.cpp 프로젝트: chenhbzl/BooxApp
void 
GRectMapper::unmap(int &x, int &y)
{
  // precalc 
  if (! (rw.p && rh.p))
    precalc();
  // scale and translate
  int mx = rectFrom.xmin + (x - rectTo.xmin) / rw;
  int my = rectFrom.ymin + (y - rectTo.ymin) / rh;
  //  mirror and swap
  if (code & MIRRORX)
    mx = rectFrom.xmin + rectFrom.xmax - mx;
  if (code & MIRRORY)
    my = rectFrom.ymin + rectFrom.ymax - my;
  if (code & SWAPXY)
    iswap(mx,my);
  x = mx;
  y = my;
}
예제 #8
0
파일: GRect.cpp 프로젝트: chenhbzl/BooxApp
void 
GRectMapper::map(int &x, int &y)
{
  int mx = x;
  int my = y;
  // precalc
  if (! (rw.p && rh.p))
    precalc();
  // swap and mirror
  if (code & SWAPXY)
    iswap(mx,my);
  if (code & MIRRORX)
    mx = rectFrom.xmin + rectFrom.xmax - mx;
  if (code & MIRRORY)
    my = rectFrom.ymin + rectFrom.ymax - my;
  // scale and translate
  x = rectTo.xmin + (mx - rectFrom.xmin) * rw;
  y = rectTo.ymin + (my - rectFrom.ymin) * rh;
}
예제 #9
0
/* precalculate region masks/sets from cp15 register */
static void armcp15_maskPrecalc(armcp15_t *armcp15)
{
#define precalc(num) {  \
	u32 mask = 0, set = 0xFFFFFFFF ; /* (x & 0) == 0xFF..FF is allways false (disabled) */  \
	if (BIT_N(armcp15->protectBaseSize##num,0)) /* if region is enabled */ \
	{    /* reason for this define: naming includes var */  \
	mask = MASKFROMREG(armcp15->protectBaseSize##num) ;   \
	set = SETFROMREG(armcp15->protectBaseSize##num) ; \
	if (SIZEIDENTIFIER(armcp15->protectBaseSize##num)==0x1F)  \
	{   /* for the 4GB region, u32 suffers wraparound */   \
	mask = 0 ; set = 0 ;   /* (x & 0) == 0  is allways true (enabled) */  \
} \
}  \
	armcp15_setSingleRegionAccess(armcp15,armcp15->DaccessPerm,armcp15->IaccessPerm,num,mask,set) ;  \
}
	precalc(0) ;
	precalc(1) ;
	precalc(2) ;
	precalc(3) ;
	precalc(4) ;
	precalc(5) ;
	precalc(6) ;
	precalc(7) ;
}
예제 #10
0
int gmx_velacc(int argc, char *argv[])
{
    const char     *desc[] = {
        "[THISMODULE] computes the velocity autocorrelation function.",
        "When the [TT]-m[tt] option is used, the momentum autocorrelation",
        "function is calculated.[PAR]",
        "With option [TT]-mol[tt] the velocity autocorrelation function of",
        "molecules is calculated. In this case the index group should consist",
        "of molecule numbers instead of atom numbers.[PAR]",
        "Be sure that your trajectory contains frames with velocity information",
        "(i.e. [TT]nstvout[tt] was set in your original [REF].mdp[ref] file),",
        "and that the time interval between data collection points is",
        "much shorter than the time scale of the autocorrelation."
    };

    static gmx_bool bMass = FALSE, bMol = FALSE, bRecip = TRUE;
    t_pargs         pa[]  = {
        { "-m", FALSE, etBOOL, {&bMass},
          "Calculate the momentum autocorrelation function" },
        { "-recip", FALSE, etBOOL, {&bRecip},
          "Use cm^-1 on X-axis instead of 1/ps for spectra." },
        { "-mol", FALSE, etBOOL, {&bMol},
          "Calculate the velocity acf of molecules" }
    };

    t_topology      top;
    int             ePBC = -1;
    t_trxframe      fr;
    matrix          box;
    gmx_bool        bTPS = FALSE, bTop = FALSE;
    int             gnx;
    int            *index;
    char           *grpname;
    /* t0, t1 are the beginning and end time respectively.
     * dt is the time step, mass is temp variable for atomic mass.
     */
    real              t0, t1, dt, mass;
    t_trxstatus      *status;
    int               counter, n_alloc, i, j, counter_dim, k, l;
    rvec              mv_mol;
    /* Array for the correlation function */
    real            **c1;
    real             *normm = NULL;
    gmx_output_env_t *oenv;

#define NHISTO 360

    t_filenm  fnm[] = {
        { efTRN, "-f",    NULL,   ffREAD  },
        { efTPS, NULL,    NULL,   ffOPTRD },
        { efNDX, NULL,    NULL,   ffOPTRD },
        { efXVG, "-o",    "vac",  ffWRITE },
        { efXVG, "-os",   "spectrum", ffOPTWR }
    };
#define NFILE asize(fnm)
    int       npargs;
    t_pargs  *ppa;

    npargs = asize(pa);
    ppa    = add_acf_pargs(&npargs, pa);
    if (!parse_common_args(&argc, argv, PCA_CAN_VIEW | PCA_CAN_TIME,
                           NFILE, fnm, npargs, ppa, asize(desc), desc, 0, NULL, &oenv))
    {
        sfree(ppa);
        return 0;
    }

    if (bMol || bMass)
    {
        bTPS = ftp2bSet(efTPS, NFILE, fnm) || !ftp2bSet(efNDX, NFILE, fnm);
    }

    if (bTPS)
    {
        bTop = read_tps_conf(ftp2fn(efTPS, NFILE, fnm), &top, &ePBC, NULL, NULL, box,
                             TRUE);
        get_index(&top.atoms, ftp2fn_null(efNDX, NFILE, fnm), 1, &gnx, &index, &grpname);
    }
    else
    {
        rd_index(ftp2fn(efNDX, NFILE, fnm), 1, &gnx, &index, &grpname);
    }

    if (bMol)
    {
        if (!bTop)
        {
            gmx_fatal(FARGS, "Need a topology to determine the molecules");
        }
        snew(normm, top.atoms.nr);
        precalc(top, normm);
        index_atom2mol(&gnx, index, &top.mols);
    }

    /* Correlation stuff */
    snew(c1, gnx);
    for (i = 0; (i < gnx); i++)
    {
        c1[i] = NULL;
    }

    read_first_frame(oenv, &status, ftp2fn(efTRN, NFILE, fnm), &fr, TRX_NEED_V);
    t0 = fr.time;

    n_alloc = 0;
    counter = 0;
    do
    {
        if (counter >= n_alloc)
        {
            n_alloc += 100;
            for (i = 0; i < gnx; i++)
            {
                srenew(c1[i], DIM*n_alloc);
            }
        }
        counter_dim = DIM*counter;
        if (bMol)
        {
            for (i = 0; i < gnx; i++)
            {
                clear_rvec(mv_mol);
                k = top.mols.index[index[i]];
                l = top.mols.index[index[i]+1];
                for (j = k; j < l; j++)
                {
                    if (bMass)
                    {
                        mass = top.atoms.atom[j].m;
                    }
                    else
                    {
                        mass = normm[j];
                    }
                    mv_mol[XX] += mass*fr.v[j][XX];
                    mv_mol[YY] += mass*fr.v[j][YY];
                    mv_mol[ZZ] += mass*fr.v[j][ZZ];
                }
                c1[i][counter_dim+XX] = mv_mol[XX];
                c1[i][counter_dim+YY] = mv_mol[YY];
                c1[i][counter_dim+ZZ] = mv_mol[ZZ];
            }
        }
        else
        {
            for (i = 0; i < gnx; i++)
            {
                if (bMass)
                {
                    mass = top.atoms.atom[index[i]].m;
                }
                else
                {
                    mass = 1;
                }
                c1[i][counter_dim+XX] = mass*fr.v[index[i]][XX];
                c1[i][counter_dim+YY] = mass*fr.v[index[i]][YY];
                c1[i][counter_dim+ZZ] = mass*fr.v[index[i]][ZZ];
            }
        }

        t1 = fr.time;

        counter++;
    }
    while (read_next_frame(oenv, status, &fr));

    close_trj(status);

    if (counter >= 4)
    {
        /* Compute time step between frames */
        dt = (t1-t0)/(counter-1);
        do_autocorr(opt2fn("-o", NFILE, fnm), oenv,
                    bMass ?
                    "Momentum Autocorrelation Function" :
                    "Velocity Autocorrelation Function",
                    counter, gnx, c1, dt, eacVector, TRUE);

        do_view(oenv, opt2fn("-o", NFILE, fnm), "-nxy");

        if (opt2bSet("-os", NFILE, fnm))
        {
            calc_spectrum(counter/2, (real *) (c1[0]), (t1-t0)/2, opt2fn("-os", NFILE, fnm),
                          oenv, bRecip);
            do_view(oenv, opt2fn("-os", NFILE, fnm), "-nxy");
        }
    }
    else
    {
        fprintf(stderr, "Not enough frames in trajectory - no output generated.\n");
    }

    return 0;
}
예제 #11
0
int gmx_current(int argc, char *argv[])
{

    static int             nshift  = 1000;
    static real            temp    = 300.0;
    static real            eps_rf  = 0.0;
    static gmx_bool        bNoJump = TRUE;
    static real            bfit    = 100.0;
    static real            bvit    = 0.5;
    static real            efit    = 400.0;
    static real            evit    = 5.0;
    t_pargs                pa[]    = {
        { "-sh", FALSE, etINT, {&nshift},
          "Shift of the frames for averaging the correlation functions and the mean-square displacement."},
        { "-nojump", FALSE, etBOOL, {&bNoJump},
          "Removes jumps of atoms across the box."},
        { "-eps", FALSE, etREAL, {&eps_rf},
          "Dielectric constant of the surrounding medium. The value zero corresponds to infinity (tin-foil boundary conditions)."},
        { "-bfit", FALSE, etREAL, {&bfit},
          "Begin of the fit of the straight line to the MSD of the translational fraction of the dipole moment."},
        { "-efit", FALSE, etREAL, {&efit},
          "End of the fit of the straight line to the MSD of the translational fraction of the dipole moment."},
        { "-bvit", FALSE, etREAL, {&bvit},
          "Begin of the fit of the current autocorrelation function to a*t^b."},
        { "-evit", FALSE, etREAL, {&evit},
          "End of the fit of the current autocorrelation function to a*t^b."},
        { "-temp", FALSE, etREAL, {&temp},
          "Temperature for calculating epsilon."}
    };

    gmx_output_env_t      *oenv;
    t_topology             top;
    char                 **grpname = NULL;
    const char            *indexfn;
    t_trxframe             fr;
    real                  *mass2 = NULL;
    matrix                 box;
    int                   *index0;
    int                   *indexm = NULL;
    int                    isize;
    t_trxstatus           *status;
    int                    flags = 0;
    gmx_bool               bACF;
    gmx_bool               bINT;
    int                    ePBC = -1;
    int                    nmols;
    int                    i;
    real                  *qmol;
    FILE                  *outf   = NULL;
    FILE                  *mcor   = NULL;
    FILE                  *fmj    = NULL;
    FILE                  *fmd    = NULL;
    FILE                  *fmjdsp = NULL;
    FILE                  *fcur   = NULL;
    t_filenm               fnm[]  = {
        { efTPS,  NULL,  NULL, ffREAD }, /* this is for the topology */
        { efNDX, NULL, NULL, ffOPTRD },
        { efTRX, "-f", NULL, ffREAD },   /* and this for the trajectory */
        { efXVG, "-o",   "current", ffWRITE },
        { efXVG, "-caf", "caf",     ffOPTWR },
        { efXVG, "-dsp", "dsp",     ffWRITE },
        { efXVG, "-md",  "md",      ffWRITE },
        { efXVG, "-mj",  "mj",      ffWRITE },
        { efXVG, "-mc",  "mc",      ffOPTWR }
    };

#define NFILE asize(fnm)


    const char *desc[] = {
        "[THISMODULE] is a tool for calculating the current autocorrelation function, the correlation",
        "of the rotational and translational dipole moment of the system, and the resulting static",
        "dielectric constant. To obtain a reasonable result, the index group has to be neutral.",
        "Furthermore, the routine is capable of extracting the static conductivity from the current ",
        "autocorrelation function, if velocities are given. Additionally, an Einstein-Helfand fit ",
        "can be used to obtain the static conductivity."
        "[PAR]",
        "The flag [TT]-caf[tt] is for the output of the current autocorrelation function and [TT]-mc[tt] writes the",
        "correlation of the rotational and translational part of the dipole moment in the corresponding",
        "file. However, this option is only available for trajectories containing velocities.",
        "Options [TT]-sh[tt] and [TT]-tr[tt] are responsible for the averaging and integration of the",
        "autocorrelation functions. Since averaging proceeds by shifting the starting point",
        "through the trajectory, the shift can be modified with [TT]-sh[tt] to enable the choice of uncorrelated",
        "starting points. Towards the end, statistical inaccuracy grows and integrating the",
        "correlation function only yields reliable values until a certain point, depending on",
        "the number of frames. The option [TT]-tr[tt] controls the region of the integral taken into account",
        "for calculating the static dielectric constant.",
        "[PAR]",
        "Option [TT]-temp[tt] sets the temperature required for the computation of the static dielectric constant.",
        "[PAR]",
        "Option [TT]-eps[tt] controls the dielectric constant of the surrounding medium for simulations using",
        "a Reaction Field or dipole corrections of the Ewald summation ([TT]-eps[tt]\\=0 corresponds to",
        "tin-foil boundary conditions).",
        "[PAR]",
        "[TT]-[no]nojump[tt] unfolds the coordinates to allow free diffusion. This is required to get a continuous",
        "translational dipole moment, required for the Einstein-Helfand fit. The results from the fit allow",
        "the determination of the dielectric constant for system of charged molecules. However, it is also possible to extract",
        "the dielectric constant from the fluctuations of the total dipole moment in folded coordinates. But this",
        "option has to be used with care, since only very short time spans fulfill the approximation that the density",
        "of the molecules is approximately constant and the averages are already converged. To be on the safe side,",
        "the dielectric constant should be calculated with the help of the Einstein-Helfand method for",
        "the translational part of the dielectric constant."
    };


    /* At first the arguments will be parsed and the system information processed */
    if (!parse_common_args(&argc, argv, PCA_CAN_TIME | PCA_CAN_VIEW,
                           NFILE, fnm, asize(pa), pa, asize(desc), desc, 0, NULL, &oenv))
    {
        return 0;
    }

    bACF = opt2bSet("-caf", NFILE, fnm);
    bINT = opt2bSet("-mc", NFILE, fnm);

    read_tps_conf(ftp2fn(efTPS, NFILE, fnm), &top, &ePBC, NULL, NULL, box, TRUE);

    indexfn = ftp2fn_null(efNDX, NFILE, fnm);
    snew(grpname, 1);

    get_index(&(top.atoms), indexfn, 1, &isize, &index0, grpname);

    flags = flags | TRX_READ_X | TRX_READ_V;

    read_first_frame(oenv, &status, ftp2fn(efTRX, NFILE, fnm), &fr, flags);

    snew(mass2, top.atoms.nr);
    snew(qmol, top.atoms.nr);

    precalc(top, mass2, qmol);


    snew(indexm, isize);

    for (i = 0; i < isize; i++)
    {
        indexm[i] = index0[i];
    }

    nmols = isize;


    index_atom2mol(&nmols, indexm, &top.mols);

    if (fr.bV)
    {
        if (bACF)
        {
            outf = xvgropen(opt2fn("-caf", NFILE, fnm),
                            "Current autocorrelation function", output_env_get_xvgr_tlabel(oenv),
                            "ACF (e nm/ps)\\S2", oenv);
            fprintf(outf, "# time\t acf\t average \t std.dev\n");
        }
        fcur = xvgropen(opt2fn("-o", NFILE, fnm),
                        "Current", output_env_get_xvgr_tlabel(oenv), "J(t) (e nm/ps)", oenv);
        fprintf(fcur, "# time\t Jx\t Jy \t J_z \n");
        if (bINT)
        {
            mcor = xvgropen(opt2fn("-mc", NFILE, fnm),
                            "M\\sD\\N - current  autocorrelation function",
                            output_env_get_xvgr_tlabel(oenv),
                            "< M\\sD\\N (0)\\c7\\CJ(t) >  (e nm/ps)\\S2", oenv);
            fprintf(mcor, "# time\t M_D(0) J(t) acf \t Integral acf\n");
        }
    }

    fmj = xvgropen(opt2fn("-mj", NFILE, fnm),
                   "Averaged translational part of M", output_env_get_xvgr_tlabel(oenv),
                   "< M\\sJ\\N > (enm)", oenv);
    fprintf(fmj, "# time\t x\t y \t z \t average of M_J^2 \t std.dev\n");
    fmd = xvgropen(opt2fn("-md", NFILE, fnm),
                   "Averaged rotational part of M", output_env_get_xvgr_tlabel(oenv),
                   "< M\\sD\\N > (enm)", oenv);
    fprintf(fmd, "# time\t x\t y \t z \t average of M_D^2 \t std.dev\n");

    fmjdsp = xvgropen(opt2fn("-dsp", NFILE, fnm),
                      "MSD of the squared translational dipole moment M",
                      output_env_get_xvgr_tlabel(oenv),
                      "<|M\\sJ\\N(t)-M\\sJ\\N(0)|\\S2\\N > / 6.0*V*k\\sB\\N*T / Sm\\S-1\\Nps\\S-1\\N",
                      oenv);


    /* System information is read and prepared, dielectric() processes the frames
     * and calculates the requested quantities */

    dielectric(fmj, fmd, outf, fcur, mcor, fmjdsp, bNoJump, bACF, bINT, ePBC, top, fr,
               temp, bfit, efit, bvit, evit, status, isize, nmols, nshift,
               index0, indexm, mass2, qmol, eps_rf, oenv);

    xvgrclose(fmj);
    xvgrclose(fmd);
    xvgrclose(fmjdsp);
    if (fr.bV)
    {
        if (bACF)
        {
            xvgrclose(outf);
        }
        xvgrclose(fcur);
        if (bINT)
        {
            xvgrclose(mcor);
        }
    }

    return 0;
}
예제 #12
0
void loadprojectfile(unsigned char *file)
{
	unsigned char *f=file;
	scenelist=NULL;
	vector3 xpse;
	float phi;
	char floatbytes=readbyte(&file);
	material *pt;
	texture  *t;

	//////////////// TEXTURE LOAD ////////////////////

	unsigned char texnum=readbyte(&file);
	
	int aa;
	for (aa=1; aa<=texnum; aa++)
	{
		texture *t=new texture;
		inittexture(*t);
		t->ID=readbyte(&file); //texture id
		t->next=texturelist;
		texturelist=t;
		char cmdcnt=readbyte(&file); //command count
		
		for (int x=0;x<cmdcnt;x++)
		{
			texturecommand cmd;
			memcpy(&cmd,file,9);
			file+=9; 
			if (cmd.commandnumber==DD_text)
			{				
				byte bb=readbyte(&file);
				memcpy(t->texts[x].text,file,bb);
				file+=bb; //text
			}
			performcommand(*t,cmd);
			//precalc((float)(aa-1)/(float)(texnum-1)+1.0f/float(texnum)*(float)x/(float)cmdcnt);
			precalc((float)(aa-1)/(float)(texnum)+1.0f/(float)(texnum)*(float)x/(float)cmdcnt);
		}		
	}

	/////////////// MATERIAL LOAD ////////////////////

    texnum=readbyte(&file);

	for (aa=1; aa<=texnum; aa++)
	{
		material *m=new material;
		m->next=materiallist;
		materiallist=m;
		m->texture=readbyte(&file);
		m->layer=readbyte(&file);
		m->alphatexture=readbyte(&file);
		m->alphalayer=readbyte(&file);
		m->alphamode=readbyte(&file);
		m->number=readbyte(&file);
		creatematerial(m);
	}

	byte scenenum=readbyte(&file);

	for (int ar=1; ar<=scenenum; ar++)
	{
		scene *Scene=newscene();
		Scene->number=readbyte(&file);

		/////////////////// ENVIRONMENT LOAD ////////////////////

		Scene->fog=readbyte(&file);
		if (Scene->fog)
		{
			Scene->fogcol[0]=(float)readbyte(&file)/255.0f;
			Scene->fogcol[1]=(float)readbyte(&file)/255.0f;
			Scene->fogcol[2]=(float)readbyte(&file)/255.0f;
			Scene->fogdensity=readfloat(&file,floatbytes);
		}

		int lightnum=readbyte(&file);
		for (int x=0; x<lightnum; x++)
		{
			int ID=readbyte(&file);
			int type=readbyte(&file);
			Scene->lights[x].turnedon=true;
			Scene->lights[x].position[3]=0;
			Scene->lights[x].ambient[0]=(float)readbyte(&file)/255.0f;
			Scene->lights[x].ambient[1]=(float)readbyte(&file)/255.0f;
			Scene->lights[x].ambient[2]=(float)readbyte(&file)/255.0f;
			Scene->lights[x].color[0]=(float)readbyte(&file)/255.0f;
			Scene->lights[x].color[1]=(float)readbyte(&file)/255.0f;
			Scene->lights[x].color[2]=(float)readbyte(&file)/255.0f;
			Scene->lights[x].position[0]=readfloat(&file,floatbytes);
			Scene->lights[x].position[1]=readfloat(&file,floatbytes);
			Scene->lights[x].position[2]=readfloat(&file,floatbytes);
			if (type>=1)
			{			
				Scene->lights[x].position[3]=1;
				Scene->lights[x].c_att=readfloat(&file,floatbytes);
				Scene->lights[x].l_att=readfloat(&file,floatbytes);
				Scene->lights[x].q_att=readfloat(&file,floatbytes);
			}
			if (type==2)
			{
				Scene->lights[x].spot_direction[0]=readfloat(&file,floatbytes);
				Scene->lights[x].spot_direction[1]=readfloat(&file,floatbytes);
				Scene->lights[x].spot_direction[2]=readfloat(&file,floatbytes);
				Scene->lights[x].spot_exponent=readfloat(&file,floatbytes);
				Scene->lights[x].spot_cutoff=readfloat(&file,floatbytes);
			}
			else
				Scene->lights[x].spot_cutoff=180.0;
		}

		/////////////////// OBJECT LOAD /////////////////////

		int objnum=readword(&file);

		for (int aa=1;aa<=objnum;aa++)
		{
			addobject(*Scene);
			tminimalobjdata objdata;
			memcpy(&objdata,file,sizeof(objdata));

			int current=Scene->objectnum-1;

			Scene->objects[current].data=objdata;
			file+=4;
			
			Scene->objects[current].number=readword(&file);
			Scene->objects[current].parent=readword(&file);

			if (objdata.textured || objdata.primitive==aDDict_map)     Scene->objects[current].texture=readbyte(&file); 
			if (objdata.red)          Scene->objects[current].color[0]=(float)readbyte(&file)/255.0f;
			if (objdata.green)        Scene->objects[current].color[1]=(float)readbyte(&file)/255.0f;
			if (objdata.blue)         Scene->objects[current].color[2]=(float)readbyte(&file)/255.0f;
			if (objdata.alpha)        Scene->objects[current].color[3]=(float)readbyte(&file)/255.0f;
			if (objdata.alphamap1set) readbyte(&file); 
			if (objdata.material2set) Scene->objects[current].envmap=readbyte(&file); 
			if (objdata.texxset || objdata.primitive==aDDict_map)      Scene->objects[current].texxscale=readbyte(&file); 
			if (objdata.texyset || objdata.primitive==aDDict_map)      Scene->objects[current].texyscale=readbyte(&file); 
			if (objdata.texoffxset || objdata.primitive==aDDict_map)   Scene->objects[current].texxoffset=readbyte(&file); 
			if (objdata.texoffyset || objdata.primitive==aDDict_map)   Scene->objects[current].texyoffset=readbyte(&file); 

			switch (objdata.primitive)
			{
			case aDDict_grid:
			case aDDict_hasab:
			case aDDict_cone:
			case aDDict_sphere:
				{
					Scene->objects[current].params[0]=readbyte(&file);
					Scene->objects[current].params[1]=readbyte(&file);
					break;
				}
			case aDDict_arc: 
				{
					Scene->objects[current].params[0]=readbyte(&file);
					Scene->objects[current].params[1]=readword(&file);
					break;
				}
			case aDDict_line: 
				{
					Scene->objects[current].params[0]=readbyte(&file);
					break;
				}
			case aDDict_loft: 
				{
					Scene->objects[current].params[0]=readword(&file);
					Scene->objects[current].params[1]=readword(&file);
					Scene->objects[current].params[2]=(int)Scene->objects;
					Scene->objects[current].params[3]=Scene->objectnum;
					break;
				}
			case aDDict_map:
				{
					texnum=readbyte(&file);
					Scene->objects[current].envmap=texnum;
					switch (texnum)
					{
					case 0:
						{
							xpse.x=readfloat(&file,floatbytes);
							xpse.y=readfloat(&file,floatbytes);
							xpse.z=readfloat(&file,floatbytes);
							break;
						}
					case 1:
						{
							xpse.x=readfloat(&file,floatbytes);
							xpse.y=readfloat(&file,floatbytes);
							xpse.z=readfloat(&file,floatbytes);
							break;
						}
					case 2:
						{
							xpse.x=readfloat(&file,floatbytes);
							xpse.y=readfloat(&file,floatbytes);
							xpse.z=readfloat(&file,floatbytes);
							phi=readfloat(&file,floatbytes);
							break;
						}
					}
					pt=findmaterial(Scene->objects[current].texture);
					t=findtexture(pt->texture);
					memcpy(maptexture,t->layers[pt->layer],256*256*4);
				}
			case aDDict_blur:
			case aDDict_linearsubdivision:
			case aDDict_butterfly: 
				{
					if (objdata.primitive!=aDDict_map)
						texnum=readbyte(&file);
					
					Scene->objects[current].params[1]=(int)readselection(&file);
					for (selection *s=(selection*)Scene->objects[current].params[1];s;s=s->next)
					{
						switch (Scene->objects[current].data.primitive)
						{
						case aDDict_map:
							{
								object *o=searchobjectbynumber(Scene->objects,Scene->objectnum,s->selected);
								obj_counttexturecoordinates( o,Scene->objects[current].texxscale,Scene->objects[current].texyscale,
									Scene->objects[current].texxoffset,
									Scene->objects[current].texyoffset,
									!Scene->objects[current].data.swaptexturexy,
									Scene->objects[current].data.inverttexx,
									Scene->objects[current].data.inverttexy);

								switch (Scene->objects[current].envmap)
								{
								case 0:
									{
										matrix s;
										for (int a=0; a<o->vertexnum; a++)
										{
											float p=getmappixel(o->vertices[a].t,Scene->objects[current].data.alphachannel,
												Scene->objects[current].data.normalsinverted);
											m_xpose(p*xpse.x,p*xpse.y,p*xpse.z,s);
											m_xformd(s,o->vertices[a].base,o->vertices[a].d);
										}
										break;
									}
								case 1:
									{
										matrix s;
										for (int a=0; a<o->vertexnum; a++)
										{
											float p=getmappixel(o->vertices[a].t,Scene->objects[current].data.alphachannel,
												Scene->objects[current].data.normalsinverted);
											m_scale(p*(xpse.x-1)+1,p*(xpse.y-1)+1,p*(xpse.z-1)+1,s);
											m_xformd(s,o->vertices[a].base,o->vertices[a].d);
										}									
										break;
									}
								case 2:
									{
										matrix s;
										for (int a=0; a<o->vertexnum; a++)
										{
											float p=getmappixel(o->vertices[a].t,Scene->objects[current].data.alphachannel,
												Scene->objects[current].data.normalsinverted);
											m_rotate(xpse.x,xpse.y,xpse.z,p*phi,s);
											m_xformd(s,o->vertices[a].base,o->vertices[a].d);
										}									
										break;
									}
								}
								for (int x=0; x<o->vertexnum; x++)
								{
									o->vertices[x].base=o->vertices[x].d;
									o->vertices[x].t=o->vertices[x].dt;
								}
								obj_counttexturecoordinates(o, o->texxscale, o->texyscale, o->texxoffset, o->texyoffset, o->data.swaptexturexy, o->data.inverttexx, o->data.inverttexy);
								obj_generatenormals(o);
								obj_transform(o,o->xformmatrix);
								break;
							}
						case aDDict_blur:
						case aDDict_linearsubdivision:
						case aDDict_butterfly: 
							{
								for (selection *s=(selection*)Scene->objects[current].params[1];s;s=s->next)
								{
									object *o=searchobjectbynumber(Scene->objects,Scene->objectnum,s->selected);
									for (int x=0; x<texnum; x++)
									{
										if (objdata.primitive==aDDict_blur) meshblur(o);
										else butterflysubdivision(o,objdata.primitive==aDDict_linearsubdivision);
									}
								}
								break;
							}
						}
					}
					
					break;
				}
			case aDDict_boolean: 
				{
					char function=readbyte(&file);
					int baseobj=readword(&file);
					int brush=readword(&file);
					//object *baseobject=searchobjectbynumber(Scene->objects,Scene->objectnum,baseobj);
					//object *brushobject=searchobjectbynumber(Scene->objects,Scene->objectnum,brush);
					matrix difference;//,m;
					readmatrix(&file, floatbytes, difference);

					//memcpy(m,brushobject->xformmatrix,sizeof(matrix));
					//matrix m2;
					//m_mult(baseobject->xformmatrix,difference,m2);
					//obj_transform(brushobject,m2);
					//obj_boolean(baseobject,brushobject,function);
					//memcpy(brushobject->xformmatrix,m,sizeof(matrix));
					//obj_transform(brushobject,brushobject->xformmatrix);
					break;
				}
			}
			
			if (objdata.primitive==aDDict_hasab) Scene->objects[current].params[2]=readbyte(&file);

			switch (objdata.primitive)
			{
			case aDDict_box:
			case aDDict_icosaeder:
			case aDDict_dodecaeder:
			case aDDict_sphere:
			case aDDict_hasab:
			case aDDict_cone:
			case aDDict_arc:
			case aDDict_loft:
			case aDDict_line:
			case aDDict_grid:
			case aDDict_clone:
				{
					readmatrix(&file, floatbytes, Scene->objects[current].xformmatrix);
					
					if (objdata.primitive==aDDict_clone)
					{
						Scene->objects[current].params[0]=(int)readselection(&file);
						Scene->objects[current].params[1]=(int)Scene->objects;
						Scene->objects[current].params[2]=Scene->objectnum;
					}
					
					obj_createprimitive(&Scene->objects[current],Scene->objects[current].data.primitive,Scene->objects[current].params[0],Scene->objects[current].params[1],Scene->objects[current].params[2],Scene->objects[current].params[3]);
					obj_transform(&Scene->objects[current],Scene->objects[current].xformmatrix);
					if (Scene->objects[current].data.primitive!=aDDict_clone)
					obj_counttexturecoordinates(&Scene->objects[current], Scene->objects[current].texxscale, Scene->objects[current].texyscale, Scene->objects[current].texxoffset, Scene->objects[current].texyoffset, Scene->objects[current].data.swaptexturexy, Scene->objects[current].data.inverttexx, Scene->objects[current].data.inverttexy);
					obj_generatenormals(&Scene->objects[current]);

					for (int x=0; x<Scene->objects[current].polygonnum; x++)
					{

						Scene->objects[current].polygons[x].color.x=Scene->objects[current].color[0];
						Scene->objects[current].polygons[x].color.y=Scene->objects[current].color[1];
						Scene->objects[current].polygons[x].color.z=Scene->objects[current].color[2];
						Scene->objects[current].polygons[x].color.w=Scene->objects[current].color[3];
						if (Scene->objects[current].data.shading!=aDDict_default) Scene->objects[current].polygons[x].shading=Scene->objects[current].data.shading;
					}

					if (Scene->objects[current].data.textured && Scene->objects[current].data.primitive!=aDDict_clone)
					{
						material *m=findmaterial(Scene->objects[current].texture);
						if (m!=NULL)
						for (int x=0; x<Scene->objects[current].polygonnum; x++)
						{
							Scene->objects[current].polygons[x].texturehandle=m->handle;
						}
					}

					if (Scene->objects[current].data.material2set && Scene->objects[current].data.primitive!=aDDict_clone)
					{
						material *m=findmaterial(Scene->objects[current].envmap);
						if (m!=NULL)
						for (int x=0; x<Scene->objects[current].polygonnum; x++)
						{
							Scene->objects[current].polygons[x].envmaphandle=m->handle;
						}
					}
					
					break;
				}
			}
		}

		//////////////////////////// CAMERA LOAD ////////////////////////////////
		//MessageBox( 0, "camload", "HelloWorld", MB_OK );
		
		byte camnum=readbyte(&file);
		for (aa=1; aa<=camnum; aa++)
		{
			camera *c=new camera;
			memset(c,0,sizeof(camera));
			c->next=Scene->cameras;
			Scene->cameras=c;
			c->number=readbyte(&file); //camera ID
			c->up.y=-1;
			byte keyframenum=readbyte(&file);
			if (keyframenum)
			{
				//c->eyex.numkey=keyframenum;
				//c->eyex.keys=new KEY[keyframenum];
				c->eyex=new CTrack(keyframenum);
				c->eyey=new CTrack(keyframenum);
				c->eyez=new CTrack(keyframenum);
				c->trgx=new CTrack(keyframenum);
				c->trgy=new CTrack(keyframenum);
				c->trgz=new CTrack(keyframenum);
				c->fovt=new CTrack(keyframenum);
				c->rollt=new CTrack(keyframenum);

				/*c->eyey.numkey=keyframenum;
				c->eyey.keys=new KEY[keyframenum];
				c->eyez.numkey=keyframenum;
				c->eyez.keys=new KEY[keyframenum];
				c->trgx.numkey=keyframenum;
				c->trgx.keys=new KEY[keyframenum];
				c->trgy.numkey=keyframenum;
				c->trgy.keys=new KEY[keyframenum];
				c->trgz.numkey=keyframenum;
				c->trgz.keys=new KEY[keyframenum];
				c->fovt.numkey=keyframenum;
				c->fovt.keys=new KEY[keyframenum];
				c->rollt.numkey=keyframenum;
				c->rollt.keys=new KEY[keyframenum];*/

				int frame=readword(&file); //frame
				int fov=readbyte(&file); //fov
				int roll=readword(&file); //roll
				float eyex=readfloat(&file,floatbytes); //eyex
				float eyey=readfloat(&file,floatbytes); //eyey
				float eyez=readfloat(&file,floatbytes); //eyez
				float trgx=readfloat(&file,floatbytes); //trgx
				float trgy=readfloat(&file,floatbytes); //trgy
				float trgz=readfloat(&file,floatbytes); //trgz
				setkeydata(c->eyex->keys,frame,eyex);
				setkeydata(c->eyey->keys,frame,eyey);
				setkeydata(c->eyez->keys,frame,eyez);
				setkeydata(c->trgx->keys,frame,trgx);
				setkeydata(c->trgy->keys,frame,trgy);
				setkeydata(c->trgz->keys,frame,trgz);
				setkeydata(c->fovt->keys,frame,(float)fov);
				setkeydata(c->rollt->keys,frame,(float)roll);
				/*c->eyex.keys[0].data=eyex;
				c->eyex.keys[0].frame=frame;
				c->eyey.keys[0].data=eyey;
				c->eyey.keys[0].frame=frame;
				c->eyez.keys[0].data=eyez;
				c->eyez.keys[0].frame=frame;
				c->trgx.keys[0].data=trgx;
				c->trgx.keys[0].frame=frame;
				c->trgy.keys[0].data=trgy;
				c->trgy.keys[0].frame=frame;
				c->trgz.keys[0].data=trgz;
				c->trgz.keys[0].frame=frame;
				c->fovt.keys[0].data=(float)fov;
				c->fovt.keys[0].frame=frame;
				c->rollt.keys[0].data=(float)roll;
				c->rollt.keys[0].frame=frame;*/

				for (int x=1; x<keyframenum; x++)
				{
					frame=readword(&file); //frame

					camfield cf;
					memset(&cf,0,sizeof(cf));
					memcpy(&cf,file,1); //mask
					file+=1;

					if (cf.fovwritten) fov=readbyte(&file);
					if (cf.rollwritten) roll=readword(&file);
					if (cf.eyexwritten) eyex=readfloat(&file,floatbytes);
					if (cf.eyeywritten) eyey=readfloat(&file,floatbytes);
					if (cf.eyezwritten) eyez=readfloat(&file,floatbytes);
					if (cf.targetxwritten) trgx=readfloat(&file,floatbytes);
					if (cf.targetywritten) trgy=readfloat(&file,floatbytes);
					if (cf.targetzwritten) trgz=readfloat(&file,floatbytes);

					/*c->eyex.keys[x].data=eyex;
					c->eyex.keys[x].frame=frame;
					c->eyey.keys[x].data=eyey;
					c->eyey.keys[x].frame=frame;
					c->eyez.keys[x].data=eyez;
					c->eyez.keys[x].frame=frame;
					c->trgx.keys[x].data=trgx;
					c->trgx.keys[x].frame=frame;
					c->trgy.keys[x].data=trgy;
					c->trgy.keys[x].frame=frame;
					c->trgz.keys[x].data=trgz;
					c->trgz.keys[x].frame=frame;
					c->fovt.keys[x].data=(float)fov;
					c->fovt.keys[x].frame=frame;
					c->rollt.keys[x].data=(float)roll;
					c->rollt.keys[x].frame=frame;*/
					
					setkeydata(&c->eyex->keys[x],frame,eyex);
					setkeydata(&c->eyey->keys[x],frame,eyey);
					setkeydata(&c->eyez->keys[x],frame,eyez);
					setkeydata(&c->trgx->keys[x],frame,trgx);
					setkeydata(&c->trgy->keys[x],frame,trgy);
					setkeydata(&c->trgz->keys[x],frame,trgz);
					setkeydata(&c->fovt->keys[x],frame,(float)fov);
					setkeydata(&c->rollt->keys[x],frame,(float)roll);

				}
				c->eyex->InitVectors();
				c->eyey->InitVectors();
				c->eyez->InitVectors();
				c->trgx->InitVectors();
				c->trgy->InitVectors();
				c->trgz->InitVectors();
				c->fovt->InitVectors();
				c->rollt->InitVectors();
			}
		}
		//MessageBox( 0, "objload", "HelloWorld", MB_OK );
		///////////////////////// OBJECT ANIM LOAD /////////////////////////////

		byte animnum=readbyte(&file);
		for (aa=1; aa<=animnum; aa++)
		{
			byte animid=readbyte(&file); //anim ID
			int on;
			for (on=0;on<Scene->objectnum;on++)
			{
				objanim *o=new objanim;
				memset(o,0,sizeof(objanim));
				o->next=Scene->objects[on].anims;
				Scene->objects[on].anims=o;
				o->number=animid;
			}
			for (on=0;on<Scene->objectnum;on++)
				if (Scene->objects[on].data.primitive!=9 && 
					Scene->objects[on].data.primitive!=11 &&
					Scene->objects[on].data.primitive<100)
				{
					byte keyframenum=readbyte(&file);
					Scene->objects[on].anims->posx=new CTrack(keyframenum);
					Scene->objects[on].anims->posy=new CTrack(keyframenum);
					Scene->objects[on].anims->posz=new CTrack(keyframenum);
					Scene->objects[on].anims->rotx=new CTrack(keyframenum);
					Scene->objects[on].anims->roty=new CTrack(keyframenum);
					Scene->objects[on].anims->rotz=new CTrack(keyframenum);
					Scene->objects[on].anims->rota=new CTrack(keyframenum);
					Scene->objects[on].anims->strx=new CTrack(keyframenum);
					Scene->objects[on].anims->stry=new CTrack(keyframenum);
					Scene->objects[on].anims->strz=new CTrack(keyframenum);
					Scene->objects[on].anims->colr=new CTrack(keyframenum);
					Scene->objects[on].anims->colg=new CTrack(keyframenum);
					Scene->objects[on].anims->colb=new CTrack(keyframenum);
					Scene->objects[on].anims->cola=new CTrack(keyframenum);
					if (keyframenum)
					{
						int frame=(unsigned short)readword(&file); //frame

						float posx=readfloat(&file,floatbytes); //posx
						float posy=readfloat(&file,floatbytes); //posy
						float posz=readfloat(&file,floatbytes); //posz

						float rotx=readfloat(&file,floatbytes); //rotx
						float roty=readfloat(&file,floatbytes); //roty
						float rotz=readfloat(&file,floatbytes); //rotz
						int rota=readword(&file); //rota

						float strx=readfloat(&file,floatbytes); //strx
						float stry=readfloat(&file,floatbytes); //stry
						float strz=readfloat(&file,floatbytes); //strz

						float colr=(float)readbyte(&file)/255.0f; //colr
						float colg=(float)readbyte(&file)/255.0f; //colg
						float colb=(float)readbyte(&file)/255.0f; //colb
						float cola=(float)readbyte(&file)/255.0f; //cola

						setkeydata(Scene->objects[on].anims->posx->keys,frame,posx);
						setkeydata(Scene->objects[on].anims->posy->keys,frame,posy);
						setkeydata(Scene->objects[on].anims->posz->keys,frame,posz);
						setkeydata(Scene->objects[on].anims->rotx->keys,frame,rotx);
						setkeydata(Scene->objects[on].anims->roty->keys,frame,roty);
						setkeydata(Scene->objects[on].anims->rotz->keys,frame,rotz);
						setkeydata(Scene->objects[on].anims->rota->keys,frame,(float)rota);
						setkeydata(Scene->objects[on].anims->strx->keys,frame,strx);
						setkeydata(Scene->objects[on].anims->stry->keys,frame,stry);
						setkeydata(Scene->objects[on].anims->strz->keys,frame,strz);
						setkeydata(Scene->objects[on].anims->colr->keys,frame,colr);
						setkeydata(Scene->objects[on].anims->colg->keys,frame,colg);
						setkeydata(Scene->objects[on].anims->colb->keys,frame,colb);
						setkeydata(Scene->objects[on].anims->cola->keys,frame,cola);

						/*Scene->objects[on].anims->posx.keys[0].frame=frame;
						Scene->objects[on].anims->posx.keys[0].data=posx;
						Scene->objects[on].anims->posy.keys[0].frame=frame;
						Scene->objects[on].anims->posy.keys[0].data=posy;
						Scene->objects[on].anims->posz.keys[0].frame=frame;
						Scene->objects[on].anims->posz.keys[0].data=posz;
						Scene->objects[on].anims->rotx.keys[0].frame=frame;
						Scene->objects[on].anims->rotx.keys[0].data=rotx;
						Scene->objects[on].anims->roty.keys[0].frame=frame;
						Scene->objects[on].anims->roty.keys[0].data=roty;
						Scene->objects[on].anims->rotz.keys[0].frame=frame;
						Scene->objects[on].anims->rotz.keys[0].data=rotz;
						Scene->objects[on].anims->rota.keys[0].frame=frame;
						Scene->objects[on].anims->rota.keys[0].data=(float)rota;
						Scene->objects[on].anims->strx.keys[0].frame=frame;
						Scene->objects[on].anims->strx.keys[0].data=strx;
						Scene->objects[on].anims->stry.keys[0].frame=frame;
						Scene->objects[on].anims->stry.keys[0].data=stry;
						Scene->objects[on].anims->strz.keys[0].frame=frame;
						Scene->objects[on].anims->strz.keys[0].data=strz;
						Scene->objects[on].anims->colr.keys[0].frame=frame;
						Scene->objects[on].anims->colr.keys[0].data=colr;
						Scene->objects[on].anims->colg.keys[0].frame=frame;
						Scene->objects[on].anims->colg.keys[0].data=colg;
						Scene->objects[on].anims->colb.keys[0].frame=frame;
						Scene->objects[on].anims->colb.keys[0].data=colb;
						Scene->objects[on].anims->cola.keys[0].frame=frame;
						Scene->objects[on].anims->cola.keys[0].data=cola;*/

						for (int x=1; x<keyframenum; x++)
						{
							frame=readword(&file); //frame

							objfield c;
							memset(&c,0,sizeof(c));
							memcpy(&c,file,2); //mask
							file+=2;

							if (c.posx) posx=readfloat(&file,floatbytes);
							if (c.posy) posy=readfloat(&file,floatbytes);
							if (c.posz) posz=readfloat(&file,floatbytes);

							if (c.rotx) rotx=readfloat(&file,floatbytes);
							if (c.roty) roty=readfloat(&file,floatbytes);
							if (c.rotz) rotz=readfloat(&file,floatbytes);
							if (c.rota) rota=readword(&file);

							if (c.strx) strx=readfloat(&file,floatbytes);
							if (c.stry) stry=readfloat(&file,floatbytes);
							if (c.strz) strz=readfloat(&file,floatbytes);

							if (c.colr) colr=(float)readbyte(&file)/255.f;
							if (c.colg) colg=(float)readbyte(&file)/255.f;
							if (c.colb) colb=(float)readbyte(&file)/255.f;
							if (c.cola) cola=(float)readbyte(&file)/255.f;

							/*Scene->objects[on].anims->posx.keys[x].frame=frame;
							Scene->objects[on].anims->posx.keys[x].data=posx;
							Scene->objects[on].anims->posy.keys[x].frame=frame;
							Scene->objects[on].anims->posy.keys[x].data=posy;
							Scene->objects[on].anims->posz.keys[x].frame=frame;
							Scene->objects[on].anims->posz.keys[x].data=posz;
							Scene->objects[on].anims->rotx.keys[x].frame=frame;
							Scene->objects[on].anims->rotx.keys[x].data=rotx;
							Scene->objects[on].anims->roty.keys[x].frame=frame;
							Scene->objects[on].anims->roty.keys[x].data=roty;
							Scene->objects[on].anims->rotz.keys[x].frame=frame;
							Scene->objects[on].anims->rotz.keys[x].data=rotz;
							Scene->objects[on].anims->rota.keys[x].frame=frame;
							Scene->objects[on].anims->rota.keys[x].data=(float)rota;
							Scene->objects[on].anims->strx.keys[x].frame=frame;
							Scene->objects[on].anims->strx.keys[x].data=strx;
							Scene->objects[on].anims->stry.keys[x].frame=frame;
							Scene->objects[on].anims->stry.keys[x].data=stry;
							Scene->objects[on].anims->strz.keys[x].frame=frame;
							Scene->objects[on].anims->strz.keys[x].data=strz;
							Scene->objects[on].anims->colr.keys[x].frame=frame;
							Scene->objects[on].anims->colr.keys[x].data=colr;
							Scene->objects[on].anims->colg.keys[x].frame=frame;
							Scene->objects[on].anims->colg.keys[x].data=colg;
							Scene->objects[on].anims->colb.keys[x].frame=frame;
							Scene->objects[on].anims->colb.keys[x].data=colb;
							Scene->objects[on].anims->cola.keys[x].frame=frame;
							Scene->objects[on].anims->cola.keys[x].data=cola;*/
						
							setkeydata(&Scene->objects[on].anims->posx->keys[x],frame,posx);
							setkeydata(&Scene->objects[on].anims->posy->keys[x],frame,posy);
							setkeydata(&Scene->objects[on].anims->posz->keys[x],frame,posz);
							setkeydata(&Scene->objects[on].anims->rotx->keys[x],frame,rotx);
							setkeydata(&Scene->objects[on].anims->roty->keys[x],frame,roty);
							setkeydata(&Scene->objects[on].anims->rotz->keys[x],frame,rotz);
							setkeydata(&Scene->objects[on].anims->rota->keys[x],frame,(float)rota);
							setkeydata(&Scene->objects[on].anims->strx->keys[x],frame,strx);
							setkeydata(&Scene->objects[on].anims->stry->keys[x],frame,stry);
							setkeydata(&Scene->objects[on].anims->strz->keys[x],frame,strz);
							setkeydata(&Scene->objects[on].anims->colr->keys[x],frame,colr);
							setkeydata(&Scene->objects[on].anims->colg->keys[x],frame,colg);
							setkeydata(&Scene->objects[on].anims->colb->keys[x],frame,colb);
							setkeydata(&Scene->objects[on].anims->cola->keys[x],frame,cola);
						}

						Scene->objects[on].anims->posx->InitVectors();
						Scene->objects[on].anims->posy->InitVectors();
						Scene->objects[on].anims->posz->InitVectors();
						Scene->objects[on].anims->rotx->InitVectors();
						Scene->objects[on].anims->roty->InitVectors();
						Scene->objects[on].anims->rotz->InitVectors();
						Scene->objects[on].anims->rota->InitVectors();
						Scene->objects[on].anims->strx->InitVectors();
						Scene->objects[on].anims->stry->InitVectors();
						Scene->objects[on].anims->strz->InitVectors();
						Scene->objects[on].anims->colr->InitVectors();
						Scene->objects[on].anims->colg->InitVectors();
						Scene->objects[on].anims->colb->InitVectors();
						Scene->objects[on].anims->cola->InitVectors();
					}
				}
		}

		Scene->next=scenelist;
		scenelist=Scene;
	}

	////////////////////////// EVENT LOAD ///////////////////////////////

	int eventnum=readword(&file);
	for (aa=1; aa<=eventnum; aa++)
	{
		event *e=new event;
		memset(e,0,sizeof(event));
		if (eventlist==NULL)
		{
			eventlist=e;
			lastevent=e;
		}
		else
		{
			lastevent->next=e;
			lastevent=e;
		}

		e->eventtype=readbyte(&file);
		e->startframe=(unsigned short)readword(&file)*10; //startframe
		e->endframe=(unsigned short)readword(&file)*10+9; //endframe
		e->pass=readbyte(&file); //pass
		if (e->eventtype==layer2d || e->eventtype==layer3d || e->eventtype==rendertotext || e->eventtype==feedback || e->eventtype==grideffect)
		{
			e->startrectx1=readword(&file);
			e->startrecty1=readword(&file);
			e->startrectx2=readword(&file);
			e->startrecty2=readword(&file);

			e->endrectx1=readword(&file);
			e->endrecty1=readword(&file);
			e->endrectx2=readword(&file);
			e->endrecty2=readword(&file);
		}
		if (e->eventtype==layer2d || e->eventtype==feedback || e->eventtype==grideffect)
		{
			e->startcol[0]=(float)readbyte(&file)/255.0f;
			e->startcol[1]=(float)readbyte(&file)/255.0f;
			e->startcol[2]=(float)readbyte(&file)/255.0f;
			e->startcol[3]=(float)readbyte(&file)/255.0f;

			e->endcol[0]=(float)readbyte(&file)/255.0f;
			e->endcol[1]=(float)readbyte(&file)/255.0f;
			e->endcol[2]=(float)readbyte(&file)/255.0f;
			e->endcol[3]=(float)readbyte(&file)/255.0f;

			switch (readbyte(&file))
			{
				case  0:e->blendfunc1=GL_ZERO; break;
				case  1:e->blendfunc1=GL_ONE; break;
				case  2:e->blendfunc1=GL_SRC_COLOR; break;
				case  3:e->blendfunc1=GL_ONE_MINUS_SRC_COLOR; break;
				case  4:e->blendfunc1=GL_SRC_ALPHA; break;
				case  5:e->blendfunc1=GL_ONE_MINUS_SRC_ALPHA; break;
				case  6:e->blendfunc1=GL_DST_ALPHA; break;
				case  7:e->blendfunc1=GL_ONE_MINUS_DST_ALPHA; break;
				case  8:e->blendfunc1=GL_DST_COLOR; break;
				case  9:e->blendfunc1=GL_ONE_MINUS_DST_COLOR; break;
				case 10:e->blendfunc1=GL_SRC_ALPHA_SATURATE; break;
			}
			switch (readbyte(&file))
			{
				case  0:e->blendfunc2=GL_ZERO; break;
				case  1:e->blendfunc2=GL_ONE; break;
				case  2:e->blendfunc2=GL_SRC_COLOR; break;
				case  3:e->blendfunc2=GL_ONE_MINUS_SRC_COLOR; break;
				case  4:e->blendfunc2=GL_SRC_ALPHA; break;
				case  5:e->blendfunc2=GL_ONE_MINUS_SRC_ALPHA; break;
				case  6:e->blendfunc2=GL_DST_ALPHA; break;
				case  7:e->blendfunc2=GL_ONE_MINUS_DST_ALPHA; break;
				case  8:e->blendfunc2=GL_DST_COLOR; break;
				case  9:e->blendfunc2=GL_ONE_MINUS_DST_COLOR; break;
				case 10:e->blendfunc2=GL_SRC_ALPHA_SATURATE; break;
			}
		}
		
		switch (e->eventtype)
		{
		case layer2d:
			{
				e->textured=readbyte(&file);
				e->texture=readbyte(&file);
				e->mattexture=findmaterial(e->texture)->handle;
				break;
			}
		case layer3d:
			{
				e->sceneid=readbyte(&file);
				e->camid=readbyte(&file);
				e->animid=readbyte(&file);
				e->camstart=readword(&file);
				e->camend=readword(&file);
				e->animstart=readword(&file);
				e->animend=readword(&file);
				e->iscene=findscene(e->sceneid);
				e->icam=findcam(e->iscene,e->camid);
				e->ianim=e->animid;
				break;
			}
		case cleargl:
			{
				e->clearscreen=readbyte(&file);
				e->clearzbuffer=readbyte(&file);
				break;
			}
		case rendertotext:
			{
				e->texture=readbyte(&file);
				break;
			}
		case feedback:
			{
				e->texture=readbyte(&file);
				e->param1=readbyte(&file);
				e->param4=readfloat(&file,floatbytes);
				break;
			}
		case grideffect:
			{
				e->texture=readbyte(&file);
				e->effect=readbyte(&file);
				e->gridstart=readfloat(&file,floatbytes);
				e->gridend=readfloat(&file,floatbytes);
				break;
			}
		}
	}
}
예제 #13
0
const char smallest = 'a';

bool precalc() {
  st[0].resize(N);
  st[0][0] = 1;
  st[1].resize(N);
  st[1][0] = 1;
  for (int i = 1; i < N; i++) {
    for (int j = 0; j < 2; j++) {
      st[j][i] = (1ll * st[j][i - 1] * add[j]) % mod[j];
    }
  }
  return false;
}

bool precalc_crash = precalc();

template<typename T>
struct super_hash {
  vector<int> a[2];
  super_hash() {}
  super_hash(T s) {
    a[0].resize(s.size());
    a[1].resize(s.size());
    a[0][0] = (s[0] - smallest) + 1;
    a[1][0] = (s[0] - smallest) + 1;
    for (int i = 1; i < s.size(); i++) {
      for (int j = 0; j < 2; j++) {
        a[j][i] = a[j][i - 1];
        a[j][i] = (1ll * a[j][i] + 1ll * st[j][i] * (s[i] - smallest + 1)) % mod[j];
      }
예제 #14
0
파일: dcp.c 프로젝트: bgromov/rawstudio
static void
settings_changed(RSSettings *settings, RSSettingsMask mask, RSDcp *dcp)
{
	gboolean changed = FALSE;

	if (mask & MASK_EXPOSURE)
	{
		g_object_get(settings, "exposure", &dcp->exposure, NULL);
		changed = TRUE;
	}

	if (mask & MASK_SATURATION)
	{
		g_object_get(settings, "saturation", &dcp->saturation, NULL);
		changed = TRUE;
	}
	
	if (mask & MASK_CONTRAST)
	{
		g_object_get(settings, "contrast", &dcp->contrast, NULL);
		changed = TRUE;
	}

	if (mask & MASK_HUE)
	{
		g_object_get(settings, "hue", &dcp->hue, NULL);
		dcp->hue /= 60.0;
		changed = TRUE;
	}

	if (mask & MASK_CHANNELMIXER)
	{
		const gfloat channelmixer_red;
		const gfloat channelmixer_green;
		const gfloat channelmixer_blue;
		g_object_get(settings,
			"channelmixer_red", &channelmixer_red,
			"channelmixer_green", &channelmixer_green,
			"channelmixer_blue", &channelmixer_blue,
			NULL);
		dcp->channelmixer_red = channelmixer_red / 100.0f;
		dcp->channelmixer_green = channelmixer_green / 100.0f;
		dcp->channelmixer_blue = channelmixer_blue / 100.0f;
		changed = TRUE;
	}

	if (mask & MASK_WB)
	{
		dcp->warmth = -1.0;
		dcp->tint = -1.0;
		gfloat premul_warmth = -1.0;
		gfloat pre_mul_tint = -1.0;
		gboolean recalc = FALSE;

		g_object_get(settings,
			"dcp-temp", &dcp->warmth,
			"dcp-tint", &dcp->tint,
			"warmth", &premul_warmth,
			"tint", &pre_mul_tint,
			"recalc-temp", &recalc,
			NULL);

		RS_xy_COORD whitepoint;
		RS_VECTOR3 neutral;
		/* This is messy, but we're essentially converting from warmth/tint to cameraneutral */
		dcp->pre_mul.x = (1.0+premul_warmth)*(2.0-pre_mul_tint);
		dcp->pre_mul.y = 1.0;
		dcp->pre_mul.z = (1.0-premul_warmth)*(2.0-pre_mul_tint);

		if (recalc)
		{
			neutral.x = 1.0 / CLAMP(dcp->pre_mul.x, 0.001, 100.00);
			neutral.y = 1.0 / CLAMP(dcp->pre_mul.y, 0.001, 100.00);
			neutral.z = 1.0 / CLAMP(dcp->pre_mul.z, 0.001, 100.00);
			gfloat max = vector3_max(&neutral);
			neutral.x = neutral.x / max;
			neutral.y = neutral.y / max;
			neutral.z = neutral.z / max;
			whitepoint = neutral_to_xy(dcp, &neutral);

			if (dcp->use_profile)
			{
				rs_color_whitepoint_to_temp(&whitepoint, &dcp->warmth, &dcp->tint);
			} else {
				dcp->warmth = 5000;
				dcp->tint = 0;
			}
			dcp->warmth = CLAMP(dcp->warmth, 2000, 12000);
			dcp->tint = CLAMP(dcp->tint, -150, 150);
			g_object_set(settings,
				"dcp-temp", dcp->warmth,
				"dcp-tint", dcp->tint,
				"recalc-temp", FALSE,
				NULL);
			g_signal_emit_by_name(settings, "wb-recalculated");
		}
		if (dcp->use_profile)
		{
			whitepoint = rs_color_temp_to_whitepoint(dcp->warmth, dcp->tint);
			set_white_xy(dcp, &whitepoint);
			precalc(dcp);
		}
		else
		{
			set_prophoto_wb(dcp, dcp->warmth, dcp->tint);
		}
		changed = TRUE;
	}

	if (mask & MASK_CURVE)
	{
		const gint nknots = rs_settings_get_curve_nknots(settings);
		gint i;

		if (nknots > 1)
		{
			gfloat *knots = rs_settings_get_curve_knots(settings);
			if (knots)
			{
				dcp->nknots = nknots;
				dcp->curve_is_flat = FALSE;
				if (nknots == 2)
					if (ABS(knots[0]) < 0.0001 && ABS(knots[1]) < 0.0001)
						if (ABS(1.0 - knots[2]) < 0.0001 && ABS(1.0 - knots[3]) < 0.0001)
							dcp->curve_is_flat = TRUE;

				if (!dcp->curve_is_flat)
				{
					gfloat sampled[65537];
					RSSpline *spline = rs_spline_new(knots, dcp->nknots, NATURAL);
					rs_spline_sample(spline, sampled, sizeof(sampled) / sizeof(gfloat));
					g_object_unref(spline);
					/* Create extra entry */
					sampled[65536] = sampled[65535];
					for (i = 0; i < 256; i++)
					{
						gfloat value = (gfloat)i * (1.0 / 255.0f);
						/* Gamma correct value */
						value = powf(value, 1.0f / 2.0f);
						
						/* Lookup curve corrected value */
						gfloat lookup = (int)(value * 65535.0f);
						gfloat v0 = sampled[(int)lookup];
						gfloat v1 = sampled[(int)lookup+1];
						lookup -= (gfloat)(gint)lookup;
						value = v0 * (1.0f-lookup) + v1 * lookup;

						/* Convert from gamma 2.0 back to linear */
						value = powf(value, 2.0f);

						/* Store in table */
						if (i>0)
							dcp->curve_samples[i*2-1] = value;
						dcp->curve_samples[i*2] = value;
					}
					dcp->curve_samples[256*2-1] = dcp->curve_samples[256*2] = dcp->curve_samples[256*2+1] = dcp->curve_samples[255*2];
				}
			}
			if (knots)
				g_free(knots);
		}
		else
			dcp->curve_is_flat = TRUE;

		for(i=0;i<257*2;i++)
			dcp->curve_samples[i] = MIN(1.0f, MAX(0.0f, dcp->curve_samples[i]));

		changed = TRUE;
	}

	if (changed)
	{
		rs_filter_changed(RS_FILTER(dcp), RS_FILTER_CHANGED_PIXELDATA);
	}
}