コード例 #1
0
ファイル: Warp.cpp プロジェクト: UIKit0/Cinder-Warping
WarpList Warp::readSettings( const DataSourceRef &source )
{
	XmlTree  doc;
	WarpList warps;

	// try to load the specified xml file
	try {
		doc = XmlTree( source );
	}
	catch( ... ) {
		return warps;
	}

	// check if this is a valid file
	bool isWarp = doc.hasChild( "warpconfig" );
	if( !isWarp ) return warps;

	//
	if( isWarp ) {
		// get first profile
		XmlTree profileXml = doc.getChild( "warpconfig/profile" );

		// iterate maps
		for( XmlTree::ConstIter child = profileXml.begin( "map" ); child != profileXml.end(); ++child ) {
			XmlTree warpXml = child->getChild( "warp" );

			// create warp of the correct type
			std::string method = warpXml.getAttributeValue<std::string>( "method", "unknown" );
			if( method == "bilinear" ) {
				WarpBilinearRef warp( new WarpBilinear() );
				warp->fromXml( warpXml );
				warps.push_back( warp );
			}
			else if( method == "perspective" ) {
				WarpPerspectiveRef warp( new WarpPerspective() );
				warp->fromXml( warpXml );
				warps.push_back( warp );
			}
			else if( method == "perspectivebilinear" ) {
				WarpPerspectiveBilinearRef warp( new WarpPerspectiveBilinear() );
				warp->fromXml( warpXml );
				warps.push_back( warp );
			}
		}
	}

	return warps;
}
コード例 #2
0
ファイル: main.c プロジェクト: qsyousef/dsp
int main (int argc, char *argv[])
{
	unsigned char *rawpic = NULL;
	unsigned char *warpedpic = NULL;
	size_t width, height;
	int num_components, color_space;

	/* Get raw data */
	rawpic = read_jpeg ("shrek_cat_eyes.jpg", &width, &height, &num_components, &color_space);
	if (!rawpic)
		goto out;
	warpedpic = calloc(1, width*height*num_components);
	if (!warpedpic) 
		goto out;
	
	/* do some processing here */
	warp(rawpic, warpedpic, width, height, num_components);
	//thresholding(rawpic, warpedpic, width, height, num_components);
	//shift(rawpic, warpedpic, width, height, num_components);

	/* write it back as jpeg */
	write_jpeg ("out.jpg", warpedpic, width, height, num_components, color_space);
	printf("Done :)\n");
out:
	if (rawpic)
		free(rawpic);
	if (warpedpic)
		free(warpedpic);
	return 0;
}
コード例 #3
0
void Level::createTiledObjects()
{
	//Create Warps
	//Read tiled info: lua level script, warp destiny, etc.
	//The collider checks when there is a interaction with the warp and triggers the teleportation

	for (unsigned int i = 0; i < map->object_group.warp_rects.size(); ++i)
	{
	
		std::unique_ptr<Warp> warp(new Warp(sf::RectangleShape(sf::Vector2f(map->object_group.warp_rects[i].width * map->getScale().x, map->object_group.warp_rects[i].height * map->getScale().y))));
		float x_corrected = map->object_group.warp_rects[i].left * map->getScale().x ;
		float y_corrected = map->object_group.warp_rects[i].top * map->getScale().y ;
		float x_destiny_corrected = map->object_group.warp_destinies[i].x  * 2.f ;
		float y_destiny_corrected = map->object_group.warp_destinies[i].y  * 2.f;
		std::string level_script_name = map->object_group.warp_level_scripts[i];
		int first_animation = map->object_group.warp_directions[i];

		warp->setPosition(sf::Vector2f(x_corrected, y_corrected));
		warp->setDestiny(sf::Vector2f(x_destiny_corrected, y_destiny_corrected));
		warp->setLevelScriptName(level_script_name);
		warp->setFirstAnimation(first_animation);
		node_vector.push_back(warp.get());
		layers[0]->addChild(std::move(warp));
	}
}
コード例 #4
0
ファイル: affine.cpp プロジェクト: xgdgsc/Media
void affine::showWarp()
{
  warp(mtx,&mtx_warp,ui->horizontalSlider_4->value());
  IplImage* img=new IplImage(mtx_warp);
  QImage qmtx=IplImage2QImage(img);
  ui->label->clear();
  ui->label->setPixmap(QPixmap::fromImage(qmtx));
  repaint();
}
コード例 #5
0
	void moving(ground& earth, square& another)
	{
		move_left();
		move_right();		
		gravity(earth);
		warp(another);
		collision_check(another);
		set_square_posit();
		move_shots();
	}
コード例 #6
0
ファイル: TimeTrack.cpp プロジェクト: Kirushanr/audacity
void TimeTrack::testMe()
{
   GetEnvelope()->SetDefaultValue(0.5);
   GetEnvelope()->Flatten(0.0);
   GetEnvelope()->Insert( 0.0, 0.0 );
   GetEnvelope()->Insert( 5.0, 1.0 );
   GetEnvelope()->Insert( 10.0, 0.0 );

   double reqt0 = 10.0 - .1;
   double reqt1 = 10.0 + .1;
   double t0 = warp( reqt0 );
   double t1 = warp( reqt1 );
   if( t0 > t1 )
     {
       printf( "TimeTrack:  Warping reverses an interval! [%.2f,%.2f] -> [%.2f,%.2f]\n",
	       reqt0, reqt1,
	       t0, t1 );
     }
}
コード例 #7
0
ファイル: warp.c プロジェクト: AhmadTux/DragonFlyBSD
/*
 * dowarp() is used in a struct cvntab to call warp().  Since it is always ram
 * or move, fl is never < 0, so ask the user for course and distance, then pass
 * that to warp().
 */
void
dowarp(int fl)
{
	int	c;
	double	d;

	if (getcodi(&c, &d))
		return;
	warp(fl, c, d);
}
コード例 #8
0
void SphereCapLight::getIrradianceSamples(Vec3f point, const Scene* scene, vector<LightRay>& result, float time) {
	// Calculate cap heigth
	float connectionSq = (point - location).length2();
	float connection = sqrt(connectionSq);
	float tangentSq = connectionSq - radius*radius;
	float heightToPoint = tangentSq / connection;
	auto sphereWarping = std::unique_ptr<Warping>(new UniformSphereCapWarping((radius - (connection-heightToPoint)) / radius));

	// Calculate rotation
	Vec3f dir = (point - location).normalized();
	Mat44f rotation = Mat44f(1);
	rotation.rotateTo(Vec3f(0,0,1), dir);

	// Draw new samples
	std::vector<Vec2f> drawnPoints(nSamples);
	randomSampler->generateSamples(nSamplesSqrt, drawnPoints);
	
	Color3f sum = Color3f(0);
	for (unsigned int i = 0; i < nSamples; i++) {
		// Warp and rotate samples
		if (point.x < 0 && point.y > 0)
			int a = 0;
		Vec3f warpedPoint = rotation * sphereWarping->warp(drawnPoints[i]);
		Vec3f spherePoint = warpedPoint * radius;

		Vec3f difference = point - (spherePoint + location);
		float distance = difference.length();

		LightRay lr;
		Ray r;
		lr.direction = difference / distance;
		r.d = lr.direction;
		r.o = spherePoint + location;
		r.tMax = distance - r.tMin;
		r.time = time;

		// Check for intersection
		for (unsigned int k = 0; k < scene->shapes.size(); k++) {
			scene->shapes[k]->intersect(&r);
		}

		//if ray hit something then it does not contribute
		if (r.hit.shape == 0) {
			float pdf = sphereWarping->pdf(drawnPoints[i]);
			//lr.radiance = power * dot(lr.direction, warpedPoint) / (sphereWarping->pdf(drawnPoints[i]) * 4*PI * pow(distance+radius, 2));
			float a = 1/(sphereWarping->pdf(drawnPoints[i]) * 4*PI);
			lr.radiance = radiance * 4 * pow(radius,2) * std::max(0.f,dot(lr.direction, warpedPoint)) / (sphereWarping->pdf(drawnPoints[i]) * 4*PI * pow(distance, 2));
		}
		else {
			lr.radiance = Color3f(0);
		}
		result.push_back(lr);
	}
}
コード例 #9
0
bool Asteroid::onCollision(GameObjectType got){
  switch(got){
  case GameObjectType::Boundary:
    warp(2.0);
    return false;
  case GameObjectType::Asteroid:
    return true;
  default:
    split();
    World::getWorld().lock()->deregisterGameObject(this);
    return false;
  }
}
コード例 #10
0
ファイル: state.cpp プロジェクト: hanwujunlc/manaserv
void GameState::enqueueWarp(Character *ptr, MapComposite *m, int x, int y)
{
    // When the player has just disconnected, better not wait for the pointer
    // to become invalid.
    if (!ptr->isConnected())
    {
        warp(ptr, m, x, y);
        return;
    }

    DelayedEvent e = { EVENT_WARP, x, y, m };
    enqueueEvent(ptr, e);
}
コード例 #11
0
Mat StereoImageWarper::warpImage(StereoImage* img, Size &destSize, Mesh &deformedLeft, Mesh &deformedRight, Mesh &linearScaledLeft, Mesh &linearScaledRight)
{
	cout << "\nStart stereo image warping" << endl;

	newSize = destSize;
	Mat src = img->getBoth_eye();

	Size destLeftSize(newSize.width / 2, newSize.height);
	Mat destLeft = Mat::zeros(destLeftSize, CV_32FC3);
	Mat destRight = Mat::zeros(destLeftSize, CV_32FC3);

	Mat linearLeft, linearRight;
	Mat leftEye = img->getLeft_eye();
	Mat rightEye = img->getRight_eye();

	// scale down left and right for reference during the image warping
	resize(leftEye, linearLeft, destLeftSize);
	resize(rightEye, linearRight, destLeftSize);

	linearLeft.convertTo(linearLeft, CV_32FC3);
	linearRight.convertTo(linearRight, CV_32FC3);

	// warp left and right view
	warp(linearScaledLeft, deformedLeft, linearLeft, destLeft);
	warp(linearScaledRight, deformedRight, linearRight, destRight);

	destLeft.convertTo(destLeft, src.type());
	destRight.convertTo(destRight, src.type());

	// merge left and right warped image
	Mat dest = Mat::zeros(Size(destLeft.size().width * 2, destLeft.size().height), src.type());
	Mat roi = dest(Rect(0, 0, destLeft.size().width, destLeft.size().height));
	destLeft.copyTo(roi);
	roi = dest(Rect(destLeft.size().width, 0, destLeft.size().width, destLeft.size().height));
	destRight.copyTo(roi);

	return dest;
}
コード例 #12
0
ファイル: match.cpp プロジェクト: Sebu/sprs
cv::Mat Transform::reconstruct(cv::Mat &src, unsigned int s) {
    cv::Mat warped = warp(src, s);

    // color scale
    //*/
    std::vector<cv::Mat> planes;
    split(warped, planes);
    for(unsigned int i=0; i<planes.size(); i++) {
        planes[i] *= colorScale_.val[i];
    }
    merge(planes, warped);
    //*/

    return warped;
}
コード例 #13
0
//! from json
void WarpPerspectiveBilinear::fromJson(const JsonTree &json)
{
	Warp::fromJson(json);
	if (json.hasChild("warp")) {
		JsonTree warp(json.getChild("warp"));
		// get corners
		JsonTree corners(warp.getChild("corners"));
		for (size_t i = 0; i < corners.getNumChildren(); i++) {
			JsonTree child = corners.getChild(i);
			float x = (child.hasChild("x")) ? child.getValueForKey<float>("x") : 0.0f;
			float y = (child.hasChild("y")) ? child.getValueForKey<float>("y") : 0.0f;
			mWarp->setControlPoint(i, vec2(x, y));
			CI_LOG_V("corner:" + toString(x) + " " + toString(y));
		}
	}
}
コード例 #14
0
ファイル: xs.c プロジェクト: npe9/harvey
void
pause(int t)
{
    int s;
    Alt alts[NALT+1];

    alts[TIMER].c = timerc;
    alts[TIMER].v = nil;
    alts[TIMER].op = CHANRCV;
    alts[SUSPEND].c = suspc;
    alts[SUSPEND].v = &s;
    alts[SUSPEND].op = CHANRCV;
    alts[RESHAPE].c = mousectl->resizec;
    alts[RESHAPE].v = nil;
    alts[RESHAPE].op = CHANRCV;
    // avoid hanging up those writing ong mousec and kbdc
    // so just accept it all and keep mouse up-to-date
    alts[MOUSE].c = mousec;
    alts[MOUSE].v = &mouse;
    alts[MOUSE].op = CHANRCV;
    alts[KBD].c = kbdc;
    alts[KBD].v = nil;
    alts[KBD].op = CHANRCV;
    alts[NALT].op = CHANEND;

    flushimage(display, 1);
    for(;;)
        switch(alt(alts)) {
        case SUSPEND:
            if (!suspended && s) {
                suspend(1);
            } else if (suspended && !s) {
                suspend(0);
                lastmx = warp(mouse.xy, lastmx);
            }
            break;
        case TIMER:
            if(suspended)
                break;
            if((t -= tsleep) < 0)
                return;
            break;
        case RESHAPE:
            redraw(1);
            break;
        }
}
コード例 #15
0
ファイル: xs.c プロジェクト: aahud/harvey
int
drop(int f)
{
	if(f){
		score(5L*(rboard.max.y-pos.y)/pcsz);
		do; while(movepiece());
	}
	fusst = 0;
	rest();
	if(pos.y==rboard.min.y && !horiz())
		return 1;
	horiz();
	setpiece(0);
	pause(1500);
	choosepiece();
	lastmx = warp(mouse.xy, lastmx);
	return 0;
}
コード例 #16
0
ファイル: state.cpp プロジェクト: BornHunter/CGSF
void GameState::enqueueWarp(Entity *ptr,
                            MapComposite *map,
                            const Point &point)
{
    // When the player has just disconnected, better not wait for the pointer
    // to become invalid.
    if (!ptr->getComponent<CharacterComponent>()->isConnected())
    {
        warp(ptr, map, point);
        return;
    }

    DelayedEvent event;
    event.type = EVENT_WARP;
    event.point = point;
    event.map = map;
    enqueueEvent(ptr, event);
}
コード例 #17
0
// Fix some edge crossings by warping vertices if it's admissible
static void
warp_vertices(const float threshold,
              TetMesh& mesh,
              std::vector<float>& vphi)
{
    assert(threshold>=0 && threshold<=0.5);
    std::vector<float> warp(mesh.vSize(), FLT_MAX);
    std::vector<int> warp_nbr(mesh.vSize(), -1);
    std::vector<Vec3f> d(mesh.vSize(), Vec3f(0,0,0));
    // it's wasteful to iterate through tets just to look at edges; oh well
    for (size_t t=0; t<mesh.tSize(); ++t) {
        for (int u=0; u<3; ++u) {
            int i = mesh.T(t)[u];
            for (int v=u+1; v<4; ++v) {
                int j = mesh.T(t)[v];
                if ((vphi[i]<0 && vphi[j]>0) || (vphi[i]>0 && vphi[j]<0)) {
                    float alpha = vphi[i]/(vphi[i]-vphi[j]);
                    if (alpha < threshold) { // warp i?
                        float d2 = alpha*dist2(mesh.V(i), mesh.V(j));
                        if (d2 < warp[i]) {
                            warp[i] = d2;
                            warp_nbr[i] = j;
                            d[i] = alpha*(mesh.V(j)-mesh.V(i));
                        }
                    } else if (alpha > 1-threshold) { // warp j?
                        float d2 = (1-alpha)*dist2(mesh.V(i), mesh.V(j));
                        if (d2 < warp[j]) {
                            warp[j] = d2;
                            warp_nbr[j] = i;
                            d[j] = (1-alpha)*(mesh.V(i)-mesh.V(j));
                        }
                    }
                }
            }
        }
    }
    // do the warps (also wasteful to loop over all vertices; oh well)
    for (size_t i=0; i<mesh.vSize(); ++i) if(warp_nbr[i]>=0) {
        mesh.V(i) += d[i];
        vphi[i] = 0; 
    }
}
コード例 #18
0
autover()
{
	double			dist;
	register int		course;

	printf("\07RED ALERT:  The %s is in a supernova quadrant\n", Ship.shipname);
	printf("***  Emergency override attempts to hurl %s to safety\n", Ship.shipname);
	/* let's get our ass out of here */
	Ship.warp = 6.0 + 2.0 * franf();
	Ship.warp2 = Ship.warp * Ship.warp;
	Ship.warp3 = Ship.warp2 * Ship.warp;
	dist = 0.75 * Ship.energy / (Ship.warp3 * (Ship.shldup + 1));
	if (dist > 1.4142)
		dist = 1.4142;
	course = ranf(360);
	Etc.nkling = -1;
	Ship.cond = RED;
	warp(-1, course, dist);
	attack(0);
}
コード例 #19
0
float bassin(vec3 p)
{
	//sol avec un trou
 	float v = cylindre(p, vec3(0,-5,0), vec3(0,-3,0), 10.0,1.0,1.0);
    v = Difference(v, cylindre(p, vec3(0,-4,0), vec3(0,-3,0), 5.0,1.0,1.0));
    
	//vague dans le trou
	v = Blend(v, vague(warp(vec3(p)), vec3(0,-3.5,0), 5.5, 0.15, 0.15,1.0,1.0));
    
	//piliers
    v = Union(v, colonne(p, vec3(8,-1.8,0), vec3(8,3.0,0), 0.5, 1.0, 0.6)); 
    v = Union(v, colonne(p, vec3(0,-1.8,8), vec3(0,3.0,8), 0.5, 1.0, 0.6)); 
    v = Union(v, colonne(p, vec3(-8,-1.8,0), vec3(-8,3.0,0), 0.5, 1.0, 0.6)); 
    v = Union(v, colonne(p, vec3(0,-1.8,-8), vec3(0,3.0,-8), 0.5, 1.0, 0.6));
	
	//toit
    v = Union(v, cylindre(p, vec3(0,4.2,0), vec3(0,5,0), 10.0,1.0,1.0));
    
    return v;
}
コード例 #20
0
ファイル: MeshWarpWidget.cpp プロジェクト: jcxz/ZPO
void MeshWarpWidget::mouseReleaseEvent(QMouseEvent *event)
{
  if (m_has_active_cp)
  {
    if (m_show_warped)
    {
      m_img = warp(m_orig_img, m_orig_mesh, m_mesh);
    }

    update();
  }
  else if (m_panning)
  {
    m_vect_x += (event->x() - m_origin_x);
    m_vect_y += (event->y() - m_origin_y);
    m_panning = false;
    DBGM("Panning DISabled");
  }

  return QWidget::mouseReleaseEvent(event);
}
コード例 #21
0
//! to json
JsonTree	WarpPerspectiveBilinear::toJson() const
{
	JsonTree		json = WarpBilinear::toJson();
	if (json.hasChild("warp")) {
		JsonTree warp(json.getChild("warp"));
		// set corners
		JsonTree	corners = JsonTree::makeArray("corners");
		for (unsigned i = 0; i < 4; ++i) {
			vec2 corner = mWarp->getControlPoint(i);
			JsonTree	cr;
			cr.addChild(ci::JsonTree("corner", i));
			cr.addChild(ci::JsonTree("x", corner.x));
			cr.addChild(ci::JsonTree("y", corner.y));

			corners.pushBack(cr);
		}
		warp.pushBack(corners);
		json.pushBack(warp);
	}
	return json;
}
コード例 #22
0
ファイル: main.c プロジェクト: VladimirMarkelov/gnuastro-vvm
int
main (int argc, char *argv[])
{
  struct timeval t1;
  struct warpparams p={{{0},0},0};

  /* Set the starting time.*/
  time(&p.rawtime);
  gettimeofday(&t1, NULL);

  /* Read the input parameters. */
  ui_read_check_inputs_setup(argc, argv, &p);

  /* Run Warp */
  warp(&p);

  /* Free all non-freed allocations. */
  ui_free_report(&p, &t1);

  /* Return successfully.*/
  return EXIT_SUCCESS;
}
コード例 #23
0
ファイル: testtex.cpp プロジェクト: 400notout/oiio
static void
test_texture3d (ustring filename)
{
    std::cerr << "Testing 3d texture " << filename << ", output = " 
              << output_filename << "\n";
    const int nchannels = 4;
    ImageSpec outspec (output_xres, output_yres, nchannels, TypeDesc::HALF);
    ImageBuf image (output_filename, outspec);
    ImageBufAlgo::zero (image);

    Imath::M33f scale;  scale.scale (Imath::V2f (0.5, 0.5));
    Imath::M33f rot;    rot.rotate (radians(30.0f));
    Imath::M33f trans;  trans.translate (Imath::V2f (0.35f, 0.15f));
    Imath::M33f xform = scale * rot * trans;
    xform.invert();

    TextureOptions opt;
    opt.sblur = blur;
    opt.tblur = blur;
    opt.rblur = blur;
    opt.swidth = width;
    opt.twidth = width;
    opt.rwidth = width;
    opt.nchannels = nchannels;
    float localfill = (fill >= 0 ? fill : 0.0f);
    opt.fill = localfill;
    if (missing[0] >= 0)
        opt.missingcolor.init ((float *)&missing, 0);

    opt.swrap = opt.twrap = opt.rwrap = TextureOptions::WrapPeriodic;
    int shadepoints = blocksize*blocksize;
    Imath::V3f *P = ALLOCA (Imath::V3f, shadepoints);
    Runflag *runflags = ALLOCA (Runflag, shadepoints);
    Imath::V3f *dPdx = ALLOCA (Imath::V3f, shadepoints);
    Imath::V3f *dPdy = ALLOCA (Imath::V3f, shadepoints);
    Imath::V3f *dPdz = ALLOCA (Imath::V3f, shadepoints);
    float *result = ALLOCA (float, shadepoints*nchannels);
    
    for (int iter = 0;  iter < iters;  ++iter) {
        // Iterate over blocks

        // Trick: switch to second texture, if given, for second iteration
        if (iter && filenames.size() > 1)
            filename = ustring (filenames[1]);

        for (int by = 0;  by < output_yres;  by+=blocksize) {
            for (int bx = 0;  bx < output_xres;  bx+=blocksize) {
                // Process pixels within a block.  First save the texture warp
                // (s,t) and derivatives into SIMD vectors.
                int idx = 0;
                for (int y = by; y < by+blocksize; ++y) {
                    for (int x = bx; x < bx+blocksize; ++x) {
                        if (x < output_xres && y < output_yres) {
                            if (nowarp) {
                                P[idx][0] = (float)x/output_xres * sscale;
                                P[idx][1] = (float)y/output_yres * tscale;
                                P[idx][2] = 0.5f * sscale;
                                P[idx] += offset;
                                dPdx[idx][0] = 1.0f/output_xres * sscale;
                                dPdx[idx][1] = 0;
                                dPdx[idx][2] = 0;
                                dPdy[idx][0] = 0;
                                dPdy[idx][1] = 1.0f/output_yres * tscale;
                                dPdy[idx][2] = 0;
                                dPdz[idx].setValue (0,0,0);
                            } else {
                                Imath::V3f coord = warp ((float)x/output_xres,
                                                         (float)y/output_yres,
                                                         0.5, xform);
                                coord.x *= sscale;
                                coord.y *= tscale;
                                coord += offset;
                                Imath::V3f coordx = warp ((float)(x+1)/output_xres,
                                                          (float)y/output_yres,
                                                          0.5, xform);
                                coordx.x *= sscale;
                                coordx.y *= tscale;
                                coordx += offset;
                                Imath::V3f coordy = warp ((float)x/output_xres,
                                                          (float)(y+1)/output_yres,
                                                          0.5, xform);
                                coordy.x *= sscale;
                                coordy.y *= tscale;
                                coordy += offset;
                                P[idx] = coord;
                                dPdx[idx] = coordx - coord;
                                dPdy[idx] = coordy - coord;
                                dPdz[idx].setValue (0,0,0);
                            }
                            runflags[idx] = RunFlagOn;
                        } else {
                            runflags[idx] = RunFlagOff;
                        }
                        ++idx;
                    }
                }
                // Call the texture system to do the filtering.
                bool ok = texsys->texture3d (filename, opt, runflags, 0, shadepoints,
                                             Varying(P), Varying(dPdx),
                                             Varying(dPdy), Varying(dPdz),
                                             result);
                if (! ok) {
                    std::string e = texsys->geterror ();
                    if (! e.empty())
                        std::cerr << "ERROR: " << e << "\n";
                }
                for (int i = 0;  i < shadepoints*nchannels;  ++i)
                    result[i] *= scalefactor;

                // Save filtered pixels back to the image.
                idx = 0;
                for (int y = by; y < by+blocksize; ++y) {
                    for (int x = bx; x < bx+blocksize; ++x) {
                        if (runflags[idx]) {
                            image.setpixel (x, y, result + idx*nchannels);
                        }
                        ++idx;
                    }
                }
            }
        }
    }
    
    if (! image.save ()) 
        std::cerr << "Error writing " << output_filename 
                  << " : " << image.geterror() << "\n";
}
コード例 #24
0
ファイル: state.cpp プロジェクト: hanwujunlc/manaserv
void GameState::update(int tick)
{
    currentTick = tick;

#ifndef NDEBUG
    dbgLockObjects = true;
#endif

    ScriptManager::currentState()->update();

    // Update game state (update AI, etc.)
    const MapManager::Maps &maps = MapManager::getMaps();
    for (MapManager::Maps::const_iterator m = maps.begin(),
         m_end = maps.end(); m != m_end; ++m)
    {
        MapComposite *map = m->second;
        if (!map->isActive())
            continue;

        map->update();

        for (CharacterIterator p(map->getWholeMapIterator()); p; ++p)
        {
            informPlayer(map, *p);
        }

        for (ActorIterator it(map->getWholeMapIterator()); it; ++it)
        {
            Actor *a = *it;
            a->clearUpdateFlags();
            if (a->canFight())
            {
                static_cast< Being * >(a)->clearHitsTaken();
            }
        }
    }

#   ifndef NDEBUG
    dbgLockObjects = false;
#   endif

    // Take care of events that were delayed because of their side effects.
    for (DelayedEvents::iterator it = delayedEvents.begin(),
         it_end = delayedEvents.end(); it != it_end; ++it)
    {
        const DelayedEvent &e = it->second;
        Actor *o = it->first;
        switch (e.type)
        {
            case EVENT_REMOVE:
                remove(o);
                if (o->getType() == OBJECT_CHARACTER)
                {
                    Character *ch = static_cast< Character * >(o);
                    ch->disconnected();
                    gameHandler->kill(ch);
                }
                delete o;
                break;

            case EVENT_INSERT:
                insertOrDelete(o);
                break;

            case EVENT_WARP:
                assert(o->getType() == OBJECT_CHARACTER);
                warp(static_cast< Character * >(o), e.map, e.x, e.y);
                break;
        }
    }
    delayedEvents.clear();
}
コード例 #25
0
ファイル: Scripted.c プロジェクト: nopy4869/Brave-Quest
int main(int argc, char* argv[])
{
    initscr();
    scrollok(stdscr, TRUE);
    wprintw(stdscr, "Welcome to Scripted ver. %d.%d for the Brave Quest engine.\nCopyright 2012 Mad Science Inc.\nPlease do not redistrubute.\n",scriptedvernum,scriptedvernum2);
    stufffilename();
    if(loadscript(filename) == 1)
    {
        wprintw(stdscr, "File not Found. Would you like to make a new file?\n");
        if(bie() == 'y')
        {
            cleanfilebuff();
            if(savescript(filename) == 1)
            {
                wprintw(stdscr, "Your disk sucks.\n");
                bi();
                return 1;
            }
        }
        else
        {
            wprintw(stdscr, "Goodbye.\n");
            endwin();
            return 1;
        }
    }
    currlinenum = linenum;
    menu();
    wprintw(stdscr, "Press escape to go to the save menu\n");
    for(;;)
    {
        wprintw(stdscr, "q= give, w= take, e= say, r= flag, t= move, y= battle, u= check flag, i= check item, o= party add, p= party remove, [ = check character\n");
        wprintw(stdscr, "a= warp, s= check experience, d= give experience, f= make experience, g= exec script, h= screen effect, j= user input, k= goline, l= make health\n");
        wprintw(stdscr, "b= check stat, n= make stat, m= blank, ,= show line, .= change line.\n");
        input[0] = bie();
        if(input[0] == 27)
            menu();
        if(input[0] == 'q')
            give();
        if(input[0] == 'w')
            take();
        if(input[0] == 'e')
            say();
        if(input[0] == 'r')
            flag();
        if(input[0] == 't')
            mmove();
        if(input[0] == 'y')
            battle();
        if(input[0] == 'u')
            checkflag();
        if(input[0] == 'i')
            checkitem();
        if(input[0] == 'o')
            partyadd();
        if(input[0] == 'p')
            partyrm();
        if(input[0] == '[')
            checkparty();
        if(input[0] == 'a')
            warp();
        if(input[0] == 's')
            checkexp();
        if(input[0] == 'd')
            giveexp();
        if(input[0] == 'f')
            makeexp();
        if(input[0] == 'g')
            execscript();
        if(input[0] == 'h')
            screeneffect();
        if(input[0] == 'j')
            userinput();
        if(input[0] == 'k')
            goline();
        if(input[0] == 'l')
            makehealth();
        if(input[0] == 'z')
            teachspell();
        if(input[0] == 'x')
            unlearnspell();
        if(input[0] == 'b')
            checkstat();
        if(input[0] == 'n')
            makestat();
        if(input[0] == 'm')
            blank();
        if(input[0] == ',')
            showline();
        if(input[0] == '.')
            changeline();
        if(currlinenum > linenum)
            linenum = currlinenum;
    }
    return 0;
};
コード例 #26
0
ファイル: _smcep.c プロジェクト: rhdunn/sptk
static void frqtr2(double *c1, int m1, double *c2, int m2, int fftsz, double a,
                   double t)
{
   int i, j;
   double w, b, *ww, *f, *tc2, *re, *im, *pf, *pk, *next;
   int size_k, size_f, fftsz2;
   static double *k = NULL;
   static int size4, flag_k = 1;

   b = M_2PI / (double) fftsz;

   size_k = (m2 + 1) * (m1 + 1);

   if (k == NULL) {
      flag_k = 0;
      size4 = size_k;
      k = dgetmem(size4);
   } else if (size_k != size4) {
      free(k);
      flag_k = 0;
      size4 = size_k;
      k = dgetmem(size4);
   }

   /*-------  if "k" is not defined  ----------*/

   if (flag_k == 0) {

      ww = dgetmem(fftsz);

      for (j = 0, w = 0.0; j < fftsz; j++, w += b)
         ww[j] = warp(w, a, t);

      fftsz2 = fftsz + fftsz;   /* size of (re + im) */
      size_f = (m2 + 1) * fftsz2;       /* size of array "f" */
      f = dgetmem(size_f);

      for (i = 0, re = f, im = f + fftsz; i <= m2; i++) {

         for (j = 0; j < fftsz; j++)
            *(re++) = cos(ww[j] * i);
         for (j = 0; j < fftsz; j++)
            *(im++) = -sin(ww[j] * i);

         re -= fftsz;
         im -= fftsz;

         ifft(re, im, fftsz);

         for (j = 1; j <= m1; j++)
            re[j] += re[fftsz - j];

         re += fftsz2;
         im += fftsz2;
      }

      free(ww);


      /*-------  copy "f" to "k" ----------*/

      for (i = 0, next = f, pf = f, pk = k; i <= m2; i++) {
         for (j = 0; j <= m1; j++)
            *(pk++) = *(pf++);
         next += fftsz2;
         pf = next;
      }
      free(f);
      flag_k = 1;
   }

   tc2 = dgetmem(m2 + 1);       /*  tmp of c2  */

   for (i = 0, pk = k; i <= m2; i++)
      for (j = 0, tc2[i] = 0.0; j <= m1; j++)
         tc2[i] += *(pk++) * c1[j];

   movem(tc2, c2, sizeof(*c2), m2 + 1);

   free(tc2);

   return;
}
コード例 #27
0
ファイル: _smcep.c プロジェクト: rhdunn/sptk
static void ifreqt2(double *c1, int m1, double *c2, int m2, int fftsz, double a,
                    double t)
{
   int i, j;
   double w, b, *ww, *f, *re, *im, *pl, *pr, *plnxt, *prnxt, *pf, *ph, *next;
   int size_h, size_f, fftsz2, m12, m11;
   static double *h = NULL;
   static int size3, flag_h = 1;

   b = M_2PI / (double) fftsz;

   size_h = (m2 + 1) * (m1 + 1);

   if (h == NULL) {
      flag_h = 0;
      size3 = size_h;
      h = dgetmem(size3);
   } else if (size_h != size3) {
      free(h);
      flag_h = 0;
      size3 = size_h;
      h = dgetmem(size3);
   }

   /*-------  if "h" is not defined  ----------*/

   if (flag_h == 0) {
      ww = dgetmem(fftsz);

      for (j = 0, w = 0.0; j < fftsz; j++, w += b)
         ww[j] = warp(w, a, t);

      fftsz2 = fftsz + fftsz;   /* size of (re + im) */

      m12 = m1 + m1 + 1;
      size_f = m12 * fftsz2;    /* size of array "f" */
      f = dgetmem(size_f);

      for (i = -m1, re = f, im = f + fftsz; i <= m1; i++) {

         for (j = 0; j < fftsz; j++)
            *(re++) = cos(ww[j] * i);

         for (j = 0; j < fftsz; j++)
            *(im++) = -sin(ww[j] * i);

         re -= fftsz;
         im -= fftsz;

         ifft(re, im, fftsz);

         re += fftsz2;
         im += fftsz2;
      }

      free(ww);

      /*------- b'(n,m)=b(n,m)+b(n,-m) ----------*/

      pl = f;
      pr = f + (m12 - 1) * fftsz2;

      for (i = 0, plnxt = pl, prnxt = pr; i < m1; i++) {
         plnxt += fftsz2;
         prnxt -= fftsz2;

         for (j = 0; j <= m2; j++)
            *(pr++) += *(pl++);

         pl = plnxt;
         pr = prnxt;
      }

      /*-------  copy "f" to "h" ----------*/

      m11 = m1 + 1;
      pf = f + m1 * fftsz2;

      for (j = 0, next = pf; j <= m1; j++) {

         next += fftsz2;

         for (i = 0; i <= m2; i++)
            h[m11 * i + j] = *(pf++);

         pf = next;
      }
      free(f);
      flag_h = 1;

      for (j = 1; j <= m1; j++)
         h[j] *= 0.5;

      for (i = 1; i <= m2; i++)
         h[i * m11] *= 2.0;
   }

   for (i = 0, ph = h; i <= m2; i++)
      for (j = 0, c2[i] = 0.0; j <= m1; j++)
         c2[i] += *(ph++) * c1[j];

   return;
}
コード例 #28
0
ファイル: _smcep.c プロジェクト: rhdunn/sptk
static void freqt2(double *c1, const int m1, double *c2, const int m2,
                   const int fftsz, const double a, const double t)
{
   int i, j;
   double w, b, *ww, *dw, *f, *re, *im, *pf, *pg, *next;
   int size_g, size_f, fftsz2;
   static double *g = NULL;
   static int size2, flag_g = 1;

   b = M_2PI / (double) fftsz;

   size_g = (m2 + 1) * (m1 + 1);

   if (g == NULL) {
      flag_g = 0;
      size2 = size_g;
      g = dgetmem(size2);
   } else if (size_g != size2) {
      free(g);
      flag_g = 0;
      size2 = size_g;
      g = dgetmem(size2);
   }

   /*-------  if "g" is not defined  ----------*/

   if (flag_g == 0) {
      ww = dgetmem(fftsz);
      dw = dgetmem(fftsz);

      for (j = 0, w = 0.0; j < fftsz; j++, w += b)
         ww[j] = warp(w, a, t);

      for (j = 0, w = 0.0; j < fftsz; j++, w += b)
         dw[j] = derivw(w, a, t);


      fftsz2 = fftsz + fftsz;   /* size of (re + im) */
      size_f = (m2 + 1) * fftsz2;       /* size of array "f" */
      f = dgetmem(size_f);

      for (i = 0, re = f, im = f + fftsz; i <= m2; i++) {

         for (j = 0; j < fftsz; j++)
            *(re++) = cos(ww[j] * i) * dw[j];
         for (j = 0; j < fftsz; j++)
            *(im++) = -sin(ww[j] * i) * dw[j];

         re -= fftsz;
         im -= fftsz;

         ifft(re, im, fftsz);

         for (j = 1; j <= m1; j++)
            re[j] += re[fftsz - j];

         re += fftsz2;
         im += fftsz2;
      }

      free(ww);
      free(dw);


      /*-------  copy "f" to "g" ----------*/

      for (i = 0, next = f, pf = f, pg = g; i <= m2; i++) {
         for (j = 0; j <= m1; j++)
            *(pg++) = *(pf++);
         next += fftsz2;
         pf = next;
      }
      free(f);
      flag_g = 1;

      for (j = 1; j <= m1; j++)
         g[j] *= 0.5;

      for (i = 1; i <= m2; i++)
         g[i * (m1 + 1)] *= 2.0;
   }

   for (i = 0, pg = g; i <= m2; i++)
      for (j = 0, c2[i] = 0.0; j <= m1; j++)
         c2[i] += *(pg++) * c1[j];

   return;
}
コード例 #29
0
ファイル: _smcep.c プロジェクト: rhdunn/sptk
static void frqt_a(double *al, const int m, const int fftsz, const double a,
                   const double t)
{
   int i, j;
   double w, b, *ww, *f, *re, *im, *pf, *pl, *next;
   int size_l, size_f, fftsz2;
   static double *l = NULL;
   static int size1, flag_l = 1;

   b = M_2PI / (double) fftsz;

   size_l = m + 1;

   if (l == NULL) {
      flag_l = 0;
      size1 = size_l;
      l = dgetmem(size1);
   } else if (size_l != size1) {
      free(l);
      flag_l = 0;
      size1 = size_l;
      l = dgetmem(size1);
   }

   /*-------  if "l" is not defined  ----------*/

   if (flag_l == 0) {

      ww = dgetmem(fftsz);

      for (j = 0, w = 0.0; j < fftsz; j++, w += b)
         ww[j] = warp(w, a, t);

      fftsz2 = fftsz + fftsz;   /* size of (re + im) */
      size_f = (m + 1) * fftsz2;        /* size of array "f" */
      f = dgetmem(size_f);

      for (i = 0, re = f, im = f + fftsz; i <= m; i++) {

         for (j = 0; j < fftsz; j++)
            *(re++) = cos(ww[j] * i);
         for (j = 0; j < fftsz; j++)
            *(im++) = -sin(ww[j] * i);

         re -= fftsz;
         im -= fftsz;

         ifft(re, im, fftsz);

         re += fftsz2;
         im += fftsz2;
      }

      free(ww);


      /*-------  copy "f" to "l" ----------*/

      for (i = 0, next = f, pf = f, pl = l; i <= m; i++) {
         *(pl++) = *pf;
         next += fftsz2;
         pf = next;
      }

      free(f);
      flag_l = 1;
   }

   movem(l, al, sizeof(*al), m + 1);

   return;
}
コード例 #30
0
ファイル: testtex.cpp プロジェクト: 400notout/oiio
static void
test_plain_texture ()
{
    std::cerr << "Testing 2d texture " << filenames[0] << ", output = " 
              << output_filename << "\n";
    const int nchannels = 4;
    ImageSpec outspec (output_xres, output_yres, nchannels, TypeDesc::HALF);
    ImageBuf image (output_filename, outspec);
    ImageBufAlgo::zero (image);

    Imath::M33f scale;  scale.scale (Imath::V2f (0.5, 0.5));
    Imath::M33f rot;    rot.rotate (radians(30.0f));
    Imath::M33f trans;  trans.translate (Imath::V2f (0.35f, 0.15f));
    Imath::M33f xform = scale * rot * trans;
    xform.invert();

    TextureOptions opt;
    opt.sblur = blur;
    opt.tblur = blur;
    opt.swidth = width;
    opt.twidth = width;
    opt.nchannels = nchannels;
    
    float localfill = (fill >= 0.0f) ? fill : 1.0f;
    opt.fill = localfill;
    if (missing[0] >= 0)
        opt.missingcolor.init ((float *)&missing, 0);
//    opt.interpmode = TextureOptions::InterpSmartBicubic;
//    opt.mipmode = TextureOptions::MipModeAniso;
    opt.swrap = opt.twrap = TextureOptions::WrapPeriodic;
//    opt.twrap = TextureOptions::WrapBlack;

#if 1
    TextureOpt opt1;
    opt1.sblur = blur;
    opt1.tblur = blur;
    opt1.swidth = width;
    opt1.twidth = width;
    opt1.nchannels = nchannels;
    opt1.fill = localfill;
    if (missing[0] >= 0)
        opt1.missingcolor = (float *)&missing;
    opt1.swrap = opt1.twrap = TextureOpt::WrapPeriodic;
#endif

    int shadepoints = blocksize*blocksize;
    float *s = ALLOCA (float, shadepoints);
    float *t = ALLOCA (float, shadepoints);
    Runflag *runflags = ALLOCA (Runflag, shadepoints);
    float *dsdx = ALLOCA (float, shadepoints);
    float *dtdx = ALLOCA (float, shadepoints);
    float *dsdy = ALLOCA (float, shadepoints);
    float *dtdy = ALLOCA (float, shadepoints);
    float *result = ALLOCA (float, shadepoints*nchannels);
    
    ustring filename = ustring (filenames[0]);
    TextureSystem::Perthread *perthread_info = texsys->get_perthread_info ();
    TextureSystem::TextureHandle *texture_handle = texsys->get_texture_handle (filename);

    for (int iter = 0;  iter < iters;  ++iter) {
        if (iters > 1 && filenames.size() > 1) {
            // Use a different filename for each iteration
            int texid = std::min (iter, (int)filenames.size()-1);
            filename = ustring (filenames[texid]);
            std::cerr << "iter " << iter << " file " << filename << "\n";
        }

        // Iterate over blocks
        for (int by = 0, b = 0;  by < output_yres;  by+=blocksize) {
            for (int bx = 0;  bx < output_xres;  bx+=blocksize, ++b) {
                // Trick: switch to other textures on later iterations, if any
                if (iters == 1 && filenames.size() > 1) {
                    // Use a different filename from block to block
                    filename = ustring (filenames[b % (int)filenames.size()]);
                }

                // Process pixels within a block.  First save the texture warp
                // (s,t) and derivatives into SIMD vectors.
                int idx = 0;
                for (int y = by; y < by+blocksize; ++y) {
                    for (int x = bx; x < bx+blocksize; ++x) {
                        if (x < output_xres && y < output_yres) {
                            if (nowarp) {
                                s[idx] = (float)x/output_xres * sscale + offset[0];
                                t[idx] = (float)y/output_yres * tscale + offset[1];
                                dsdx[idx] = 1.0f/output_xres * sscale;
                                dtdx[idx] = 0;
                                dsdy[idx] = 0;
                                dtdy[idx] = 1.0f/output_yres * tscale;
                            } else {
                                Imath::V3f coord = warp ((float)x/output_xres,
                                                         (float)y/output_yres,
                                                         xform);
                                coord.x *= sscale;
                                coord.y *= tscale;
                                coord += offset;
                                Imath::V3f coordx = warp ((float)(x+1)/output_xres,
                                                          (float)y/output_yres,
                                                          xform);
                                coordx.x *= sscale;
                                coordx.y *= tscale;
                                coordx += offset;
                                Imath::V3f coordy = warp ((float)x/output_xres,
                                                          (float)(y+1)/output_yres,
                                                          xform);
                                coordy.x *= sscale;
                                coordy.y *= tscale;
                                coordy += offset;
                                s[idx] = coord[0];
                                t[idx] = coord[1];
                                dsdx[idx] = coordx[0] - coord[0];
                                dtdx[idx] = coordx[1] - coord[1];
                                dsdy[idx] = coordy[0] - coord[0];
                                dtdy[idx] = coordy[1] - coord[1];
                            }
                            runflags[idx] = RunFlagOn;
                        } else {
                            runflags[idx] = RunFlagOff;
                        }
                        ++idx;
                    }
                }

                // Call the texture system to do the filtering.
                bool ok;
                if (blocksize == 1) {
                    if (use_handle)
                        ok = texsys->texture (texture_handle, perthread_info, opt1,
                                              s[0], t[0], dsdx[0], dtdx[0],
                                              dsdy[0], dtdy[0], result);
                    else
                        ok = texsys->texture (filename, opt1,
                                              s[0], t[0], dsdx[0], dtdx[0],
                                              dsdy[0], dtdy[0], result);
                } else {
                    ok = texsys->texture (filename, opt, runflags, 0,
                                          shadepoints, Varying(s), Varying(t),
                                          Varying(dsdx), Varying(dtdx),
                                          Varying(dsdy), Varying(dtdy), result);
                }
                if (! ok) {
                    std::string e = texsys->geterror ();
                    if (! e.empty())
                        std::cerr << "ERROR: " << e << "\n";
                }
                for (int i = 0;  i < shadepoints*nchannels;  ++i)
                    result[i] *= scalefactor;

                // Save filtered pixels back to the image.
                idx = 0;
                for (int y = by; y < by+blocksize; ++y) {
                    for (int x = bx; x < bx+blocksize; ++x) {
                        if (runflags[idx]) {
                            image.setpixel (x, y, result + idx*nchannels);
                        }
                        ++idx;
                    }
                }
            }
        }
    }
    
    if (! image.save ()) 
        std::cerr << "Error writing " << output_filename 
                  << " : " << image.geterror() << "\n";
}