void pl_collisionshape_SetScaling(PlCollisionShape* cshape, PlVector3* cscaling)
{
	CAST_ASSERT(cshape,btCollisionShape*,shape);

	btVector3 scaling(cscaling[0],cscaling[1],cscaling[2]);
	shape->setLocalScaling(scaling);	
}
void ImportObjSetup::initPhysics()
{
	m_guiHelper->setUpAxis(2);
	this->createEmptyDynamicsWorld();
	m_guiHelper->createPhysicsDebugDrawer(m_dynamicsWorld);
	m_dynamicsWorld->getDebugDrawer()->setDebugMode(btIDebugDraw::DBG_DrawWireframe);
	const char* fileName = "samurai_monastry.obj";
    char relativeFileName[1024];
	const char* prefix[]={"./data/","../data/","../../data/","../../../data/","../../../../data/"};
	int prefixIndex=-1;
	{
		
		int numPrefixes = sizeof(prefix)/sizeof(char*);
		
		for (int i=0;i<numPrefixes;i++)
		{
			FILE* f = 0;
			sprintf(relativeFileName,"%s%s",prefix[i],fileName);
			f = fopen(relativeFileName,"r");
			if (f)
			{
				fclose(f);
				prefixIndex = i;
				break;
			}
		}
	}
	
	if (prefixIndex<0)
		return;
	
	btVector3 shift(0,0,0);
	btVector3 scaling(10,10,10);
//	int index=10;
	
	{
		
		std::vector<tinyobj::shape_t> shapes;
		std::string err = tinyobj::LoadObj(shapes, relativeFileName, prefix[prefixIndex]);
		
		GLInstanceGraphicsShape* gfxShape = btgCreateGraphicsShapeFromWavefrontObj(shapes);
		
		btTransform trans;
		trans.setIdentity();
		trans.setRotation(btQuaternion(btVector3(1,0,0),SIMD_HALF_PI));
		
		btVector3 position = trans.getOrigin();
		btQuaternion orn = trans.getRotation();
		
		btVector3 color(0,0,1);
		
		
		int shapeId = m_guiHelper->getRenderInterface()->registerShape(&gfxShape->m_vertices->at(0).xyzw[0], gfxShape->m_numvertices, &gfxShape->m_indices->at(0), gfxShape->m_numIndices);
		
		//int id = 
		m_guiHelper->getRenderInterface()->registerGraphicsInstance(shapeId,position,orn,color,scaling);

	
	}
}
Exemple #3
0
p_struct createDirich(std::vector<double> alpha, std::size_t numSamples) {
  arma::mat R(numSamples, alpha.size()); //careful because of fortran <-> c-order!
  typedef std::gamma_distribution<double> Distribution;

  std::vector<int> seeds(alpha.size());
  std::seed_seq({0}).generate(seeds.begin(), seeds.end());

  std::vector<std::future<int> > answers(alpha.size());

  for (std::size_t i = 0; i < alpha.size(); ++i) {
    std::default_random_engine rSeedEngine_(seeds[i]);
    auto generator = std::bind(Distribution(alpha[i]), rSeedEngine_);
    answers[i] = std::async(std::launch::deferred,&writeToArray<decltype(R.begin()), decltype(generator)>, R.begin() + numSamples * i, R.begin() + numSamples * (i + 1), generator);
  }
  for (int i = 0; i < alpha.size(); ++i) {
    answers[i].get();
  }
  //normalize for every sample:
  arma::mat scaling = arma::sum(R,1);
  for (std::size_t i = 0; i < numSamples; ++i) {
    R.row(i) /= arma::as_scalar(scaling(i));
  }
  p_struct p;
  p.p2 = 1 - arma::as_scalar(arma::sum(arma::max(R, 1))) / numSamples;
  arma::mat alphaW(alpha.data(), alpha.size(), 1, false);
  p.p1 = 1 - arma::as_scalar(arma::max(alphaW) / arma::sum(alphaW));
  //arma::sum(R, 1).print();
  //std::cout << "blub" << std::endl;
  return p;
}
Exemple #4
0
void plSetScaling(plCollisionShapeHandle cshape, plVector3 cscaling)
{
	btCollisionShape* shape = reinterpret_cast<btCollisionShape*>( cshape);
	btAssert(shape);
	btVector3 scaling(cscaling[0],cscaling[1],cscaling[2]);
	shape->setLocalScaling(scaling);	
}
void CImage::DrawSprite(LPD3DXSPRITE SpriteInterface, LPDIRECT3DTEXTURE9 TextureInterface, int PosX, int PosY, int Rotation, int Align)
{
	if(SpriteInterface == NULL || TextureInterface == NULL)
		return;

	D3DXVECTOR3 Vec;

	Vec.x = (FLOAT)PosX;
	Vec.y = (FLOAT)PosY;
	Vec.z = (FLOAT)0.0f;

	D3DXMATRIX mat;
	D3DXVECTOR2 scaling(1.0f, 1.0f);
	D3DSURFACE_DESC desc;
	TextureInterface->GetLevelDesc(0, &desc);
	D3DXVECTOR2 spriteCentre;
	if(Align == 1)
		spriteCentre = D3DXVECTOR2((FLOAT)desc.Width / 2, (FLOAT)desc.Height / 2);
	else
		spriteCentre = D3DXVECTOR2(0, 0);
	D3DXVECTOR2 trans = D3DXVECTOR2(0, 0);
	D3DXMatrixTransformation2D(&mat, NULL, 0.0, &scaling, &spriteCentre, (FLOAT)Rotation, &trans);

	SpriteInterface->SetTransform(&mat);
	SpriteInterface->Begin(D3DXSPRITE_ALPHABLEND);
	SpriteInterface->Draw(TextureInterface, NULL, NULL, &Vec, 0xFFFFFFFF);
	SpriteInterface->End();
}
void ImportObjSetup::initPhysics()
{
	m_guiHelper->setUpAxis(2);
	this->createEmptyDynamicsWorld();
	m_guiHelper->createPhysicsDebugDrawer(m_dynamicsWorld);
	m_dynamicsWorld->getDebugDrawer()->setDebugMode(btIDebugDraw::DBG_DrawWireframe);


	btTransform trans;
    trans.setIdentity();
	trans.setRotation(btQuaternion(btVector3(1,0,0),SIMD_HALF_PI));
	btVector3 position = trans.getOrigin();
	btQuaternion orn = trans.getRotation();
		
    btVector3 scaling(1,1,1);
	btVector3 color(1,1,1);
		
   int shapeId = loadAndRegisterMeshFromFile2(m_fileName, m_guiHelper->getRenderInterface());    
   if (shapeId>=0)
   {
        //int id = 
        m_guiHelper->getRenderInterface()->registerGraphicsInstance(shapeId,position,orn,color,scaling);
   } 

}
Exemple #7
0
		void Statistics::scaling(vector<vector<double> >& m)
		{
			for (unsigned int i = 0; i < m.size(); i++)
			{
				scaling(m[i]);
			}
		}
Exemple #8
0
    //-----------------------------------------------------------------------
    //                           s e t S c a l e
    //-----------------------------------------------------------------------
    void TCollisionShape::setScale(const TVector3& value)
    {
        btVector3 scaling(value.X, value.Y, value.Z);

        m_shape->setLocalScaling(scaling);

    }
Exemple #9
0
/* Given one set of values from one margin, do the actual scaling.
 On the first pass, this function takes notes on each margin's element list and total 
 in the original data. Later passes just read the notes and call the scaling() function above.
*/
static void one_set_of_values(mnode_t *const * const icon, const int ctr, void *in){
    rake_t *r = in;
    int size = r->indata->matrix->size1;
    static bool *t = NULL;
    if (!t) t = malloc(size * sizeof(bool));
	int first_pass = 0;
    double in_sum;
	if (ctr < r->ct)
		in_sum = gsl_vector_get(r->indata_values, ctr);
    else {
        r->ct++;
        if (ctr >= r->al) rakeinfo_grow(r);
   		index_get_element_list(icon, t);
        in_sum = 0;
        int n=0, al=0;
        r->elmtlist[ctr] = NULL;
        for(int m=0; m < size; m++)
            if (t[m]){
                in_sum += r->indata->weights->data[m];
                if (n >= al) {
                    al = (al+1)*2;
                    r->elmtlist[ctr] = realloc(r->elmtlist[ctr], al*sizeof(size_t));
                }
                r->elmtlist[ctr][n++] = m;
            }
        r->elmtlist_sizes[ctr] = n;
        r->indata_values->data[ctr] = in_sum;
		first_pass++;
	}
    if (!r->elmtlist_sizes[ctr]) return;
    if (!first_pass && !in_sum)  return;
    scaling(r->elmtlist[ctr], r->elmtlist_sizes[ctr], r->fit->weights, in_sum);
}
Exemple #10
0
    void Checkbox::setSize(float width, float height)
    {
        // Don't do anything when the checkbox wasn't loaded correctly
        if (m_Loaded == false)
            return;

        // A negative size is not allowed for this widget
        if (width  < 0) width  = -width;
        if (height < 0) height = -height;

        // Set the size of the checkbox
        m_Size.x = width;
        m_Size.y = height;

        // If the text is auto sized then recalculate the size
        if (m_TextSize == 0)
            setText(m_Text.getString());

        sf::Vector2f scaling(m_Size.x / m_TextureUnchecked.getSize().x, m_Size.y / m_TextureUnchecked.getSize().y);
        m_TextureChecked.sprite.setScale(scaling);
        m_TextureUnchecked.sprite.setScale(scaling);
        m_TextureFocused.sprite.setScale(scaling);
        m_TextureHover.sprite.setScale(scaling);

        // Reposition the text
        setPosition(getPosition());
    }
Exemple #11
0
	btRigidBody* localCreateRigidBody (btScalar mass, const btTransform& startTransform, btConvexShape* shape)
	{
		bool isDynamic = (mass != 0.f);

		btVector3 localInertia(0,0,0);
		if (isDynamic)
			shape->calculateLocalInertia(mass,localInertia);

		btDefaultMotionState* myMotionState = new btDefaultMotionState(startTransform);
		
		btRigidBody::btRigidBodyConstructionInfo rbInfo(mass,myMotionState,shape,localInertia);
		btRigidBody* body = new btRigidBody(rbInfo);

		m_ownerWorld->addRigidBody(body);
		
		btVector3 color(1,0,0);
		btVector3 scaling(1,1,1);
		
		btShapeHull* hull = new btShapeHull(shape);
		hull->buildHull(0.01);
		
		{
			int strideInBytes = 9*sizeof(float);
			int numVertices = hull->numVertices();
			int numIndices =hull->numIndices();
			
			btAlignedObjectArray<GraphicsVertex> gvertices;
			
			for (int i=0;i<numVertices;i++)
			{
				GraphicsVertex vtx;
				btVector3 pos =hull->getVertexPointer()[i];
				vtx.pos[0] = pos.x();
				vtx.pos[1] = pos.y();
				vtx.pos[2] = pos.z();
				vtx.pos[3] = 1.f;
				pos.normalize();
				vtx.normal[0] =pos.x();
				vtx.normal[1] =pos.y();
				vtx.normal[2] =pos.z();
				vtx.texcoord[0] = 0.5f;
				vtx.texcoord[1] = 0.5f;
				gvertices.push_back(vtx);
			}
			
			btAlignedObjectArray<int> indices;
			for (int i=0;i<numIndices;i++)
				indices.push_back(hull->getIndexPointer()[i]);
			
			int shapeId = m_app->m_instancingRenderer->registerShape(&gvertices[0].pos[0],numVertices,&indices[0],numIndices);
			
			m_app->m_instancingRenderer->registerGraphicsInstance(shapeId,body->getWorldTransform().getOrigin(),body->getWorldTransform().getRotation(),color,scaling);
			
		}
		delete hull;

		

		return body;
	}
Exemple #12
0
int OpticSprite::draw(LPD3DXSPRITE sprite, double time, D3DXCOLOR colour, double offsetX, double offsetY) {
	if(!this->animate) {
		sprite->Draw(texture, NULL, NULL, NULL, colour);
		return 1;
	}

	if(animation.lifetime() > time) {
		animation.updateState(aniState, time);
		colour = D3DXCOLOR(aniState.red, aniState.green, aniState.blue, colour.a < aniState.alpha? colour.a : aniState.alpha);
		float rotation = 6.28318531f * aniState.rotation;
		D3DXMATRIX mat, current;
		D3DXVECTOR2 scaling(aniState.scale_x, aniState.scale_y);
		D3DXVECTOR2 position(floor(((pResolution->width * aniState.position_x) - translateCentre.x) + offsetX),
							 floor(((pResolution->height * aniState.position_y) - translateCentre.y) + offsetY));
		D3DXMatrixTransformation2D(&mat, &transformCentre, 0.0f, &scaling, &transformCentre, rotation, &position);
		sprite->GetTransform(&current);
		mat *= current;
		sprite->SetTransform(&mat);
		
		HRESULT res;

		//Spritesheet rect calculations are slightly iffy thanks to the texture scaling (rounding errors)
		if(this->spritesheet) {
			int x = (width * currFrame) % surfaceDesc.Width;
			
			//Hacky workaround
			int diff = x - surfaceDesc.Width;

			if(abs(diff) <= 10) {
				x = 0;
			}
			//End of hacky workaround

			int y = height * currRow;
			RECT source;
			source.top = y;
			source.left = x;
			source.right = x + width;
			source.bottom = y + height;
			res = sprite->Draw(texture, &source, NULL, NULL, colour);
			sprite->SetTransform(&current);

			if(!advanceFrame(time, x, y)) {
				return 0;
			}
		} else {
			res = sprite->Draw(texture, NULL, NULL, NULL, colour);
			sprite->SetTransform(&current);
		}

		if(res != S_OK) {
			throw OpticSpriteException("Rendering sprite failed!");
		}

		return 1;
	}

	return 0;
}
Exemple #13
0
Transform& Transform::scale(float scaleX, float scaleY, float centerX, float centerY)
{
    Transform scaling(scaleX, 0,      centerX * (1 - scaleX),
                      0,      scaleY, centerY * (1 - scaleY),
                      0,      0,      1);

    return combine(scaling);
}
Exemple #14
0
Transform& Transform::scale(float scaleX, float scaleY)
{
    Transform scaling(scaleX, 0,      0,
                      0,      scaleY, 0,
                      0,      0,      1);

    return combine(scaling);
}
void Experiment2D22::parallelPlot() {

	viewer->clear();
	drawaxis();
	scaling();
	drawPlot();
	viewer->refresh();
}
Exemple #16
0
Transform& Transform::Scale(float scaleX, float scaleY)
{
    Transform scaling(scaleX, 0,      0,
                      0,      scaleY, 0,
                      0,      0,      1);

    return *this = Combine(scaling);
}
Exemple #17
0
			Transformation &scale(const vector2df &factors)
			{
				Transformation scaling(factors.x, 0, 0,
					0, factors.y, 0,
					0, 0, 1);

				return combine(scaling);
			}
Exemple #18
0
void main()
{
	int gd=DETECT,gm,i,n,ch;
	float tx,ty,sx,sy,theta;
	point p[15];
	void translate(struct point *,float,float,int);
	void scaling(struct point *,float,float,int);
	void rotate(struct point *,float,int);
	void draw(struct point*,int);
	initgraph(&gd,&gm,"c:\\tc\\bgi");
	printf("Enter number of vertices :" );
	scanf("%d",&n);
	printf("Enter no of coordinates:");
	for(i=0;i<n;i++)
	{
		scanf("%d%d",&p[i].x,&p[i].y);
	}

	p[n]=p[0];

	printf("\n1.translate");
	printf("\n2.scaling");
	printf("\n3.rotate");
	printf("\n4.Exit");
	printf("\nenter your choice");
	scanf("%d",&ch);
	switch(ch)
	{
		case 1:
			cleardevice();
			draw(p,n);
			printf("\nEnter translation factors:");
			scanf("%f%f",&tx,&ty);
			translate(p,tx,ty,n);
			draw(p,n);
			break;
		case 2:
			cleardevice();
			draw(p,n);
			printf("Enter scaling factor :");
			scanf("%f%f",&sx,&sy);
			scaling(p,sx,sy,n);
			draw(p,n);
			break;
		case 3:
			cleardevice();
			draw(p,n);
			printf("Enter rotation angle");
			scanf("%f",&theta);
			rotate(p,theta,n);
			draw(p,n);
			getch();
			break;
		case 4:
			exit(1);
	}

}
double ResizeHandle::currentScale() {
	if (scaling()) {
		ZoomableGraphicsView *sw = dynamic_cast<ZoomableGraphicsView*>(scene()->parent());
		if(sw) {
			return sw->currentZoom()/100;
		}
	}
	return 1;
}
Exemple #20
0
/*
 * HEADER:510:scale:inv:0:scale for packing
 */
int f_scale(ARG0) {

    int dec, bin, nbits;
    double base;
    if (mode < 0) return 0;
    if (scaling(sec, &base, &dec, &bin, &nbits) == 0) {
       sprintf(inv_out,"scale=%d,%d", dec, bin);
    }
    return 0;
}
Exemple #21
0
int f_scaling(ARG0) {

    int dec, bin, nbits;
    double base;
    if (mode < 0) return 0;
    if (scaling(sec, &base, &dec, &bin, &nbits) == 0) {
       sprintf(inv_out,"scaling ref=%g dec_scale=%d bin_scale=%d nbits=%d", base, dec, bin, nbits);
    }
    return 0;
}
Exemple #22
0
void Displayable::mult_scale(float s) {
  if (fixed())  return;		// only transform unfixed objects

  // do trans for all children as well
  for (int i=0; i < num_children; i++)
    child(i)->mult_scale(s);

  if (!scaling())  return;
  scale *= s;
  need_matrix_recalc();
}
QMatrix4x4 Transform::modelMatrix() {
    if(m_dirty) {

        m_matrix.setToIdentity();
        m_matrix.scale(scaling());
        m_matrix.rotate(rotation());
        m_matrix.translate(position());
        m_dirty = false;
    }
    return m_matrix;
}
Exemple #24
0
Matrix2d Matrix2d::transformWith2P(const Point2d& from1, const Point2d& from2,
                                   const Point2d& to1, const Point2d& to2)
{
    if (from1 == from2 || to1 == to2
        || from1.isDegenerate() || from2.isDegenerate() || to1.isDegenerate() || to2.isDegenerate()) {
        return Matrix2d::kIdentity();
    }
    return (translation(to1 - from1)
            * scaling(to2.distanceTo(to1) / from2.distanceTo(from1), to1)
            * rotation((to2 - to1).angle2() - (from2 - from1).angle2(), to1));
}
Exemple #25
0
// reset the transformation to the identity matrix
void Displayable::reset_transformation(void) {
  // only reset if we're not fixed and given operations are allowed
  if (scaling())           scale=1;
  if (rotating())          { rotm.identity(); }
  if (glob_translating())  globt[0] = globt[1] = globt[2] = 0;
  if (cent_translating())  centt[0] = centt[1] = centt[2] = 0;	
  need_matrix_recalc();

  // do reset for all children as well
  for (int i=0; i < num_children; i++)
    child(i)->reset_transformation();
}
void PDFCanvas::paint ( QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget )
{
    painter->fillRect(geometry(), Qt::darkGray);
    
    painter->translate(-d->documentOffset);

    QMatrix scaled = scaling();
    QRectF geom(0.0, d->documentOffset.y(), geometry().width(), geometry().height());
    QList<PDFPage*> visiblePages = d->document->visiblePages(geom, scaled);
    foreach(PDFPage *page, visiblePages) {
        QPolygonF bounds = page->boundingRect() * scaled;
        page->paint(painter, bounds.boundingRect());
    }
Exemple #27
0
void
poor_stretched_font_rep::draw_fixed (renderer ren, string s, SI x, SI y, SI xk) {
  if (ren->is_screen) {
    STACK_NEW_ARRAY (xpos, SI, N(s)+1);
    get_xpositions (s, xpos, xk);
    draw_fixed (ren, s, x, y, xpos);
    STACK_DELETE_ARRAY (xpos);
  }
  else {
    ren->set_transformation (scaling (point (1.0, factor), point (0.0, 0.0)));
    base->draw_fixed (ren, s, x, y, xk);
    ren->reset_transformation ();
  }
}
void display() 
{ 
	int opt;
	float sx, sy;

	glClearColor(1.0, 1.0, 1.0, 1.0);
	glClear(GL_COLOR_BUFFER_BIT); 
	
	drawTriangle(p);

	printf("************ Traingle Scaling ***************");
	printf("\n1. Scale along x-axis \n 2. Scale along y-axis \n 3. Scale along both x-axis and y-axis \n");
	printf("Enter your option:");
	scanf("%d", & opt);
	switch(opt)
	{
	case 1: printf("\n Enter value for sx: ");
			scanf("%f", &sx);
			scaling(sx, 0);
			break;
	case 2:	printf("\n Enter value for sy: ");
			scanf("%f", &sy);
			scaling(0, sy);
			break;
	case 3: printf("\n Enter value for sx : ");
			scanf("%f", &sx);
			printf("\n Enter value for sy : ");
			scanf("%f", &sy);
			scaling(sx, sy);
			break;
	default:
			return;
	}

	glFlush(); 
	
} 
Exemple #29
0
void VolumeScaling::process() {
    const VolumeHandleBase* inputVolume = inport_.getData();  
    
    if (!enableProcessing_.get()) {
        spacingDisplay_.set(inputVolume->getSpacing());
        outport_.setData(const_cast<VolumeHandleBase*>(inputVolume), false);
    }
    else {
        tgt::vec3 scaling(scalingX_.get(), scalingY_.get(), scalingZ_.get());
        tgt::vec3 spacing = inputVolume->getSpacing() * scaling;
        spacingDisplay_.set(spacing);
        VolumeHandleBase* outputVolume = new VolumeHandleDecoratorReplace(inputVolume, "Spacing", new Vec3MetaData(spacing));
        outport_.setData(outputVolume);
    }
}
Exemple #30
0
/** Returns a point inside the cylinder,
    specified by its location relative to the cylinder axis,
    its relative radius and  its rotation angle about the axis

    @param relative_height a number in the range [0..1] that specifies
                           the point location relative to the cylinder axis
                           such that 0 specifies the cylinder bottom and
                           1 specifies its top
    @param relative_radius a number in the range [0..1] that specifies
                           the distance of the point from the cylinder axis
                           relative to the cylinder radius, 0 being on the
                           axis itself, and 1 being on the cylinder surface
    @param angle angle in radians about the cylinder axis, with 0 set to
                 an arbitrary but consistent direction
  */
const Vector3D Cylinder3D::get_inner_point_at(double relative_height,
                                              double relative_radius,
                                              double angle) const {
  // compute the point relative to cylinder of equivalent dimensions,
  // but whose main axis segment is z-aligned and lying at the origin
  Vector3D scaling(get_radius() * relative_radius,
                   get_radius() * relative_radius, get_segment().get_length());
  Vector3D pt(scaling[0] * sin(angle), scaling[1] * cos(angle),
              scaling[2] * relative_height);
  // transform the cylinder axis from the origin to the correct location
  Rotation3D rot = get_rotation_taking_first_to_second(
      Vector3D(0, 0, 1),
      get_segment().get_point(1) - get_segment().get_point(0));
  Transformation3D tr(rot, get_segment().get_point(0));
  return tr.get_transformed(pt);
}