Beispiel #1
0
 void Graphics::ortho(const float left, const float right, const float bottom, const float top, const float near, const float far) {
   setMatrix(getMatrix() * Matrix::ortho2D(left, right, bottom, top));
 }
bool SkDrawMatrix::draw(SkAnimateMaker& maker) {
    SkMatrix& concat = getMatrix();
    maker.fCanvas->concat(concat);
    return false;
}
Beispiel #3
0
//////////////////////////////////////////////////////////////////////////
// drawLine
void ScnCanvasComponent::drawLine( const MaVec2d& PointA, const MaVec2d& PointB, const RsColour& Colour, BcU32 Layer )
{
	ScnCanvasComponentVertex* pVertices = allocVertices( 2 );
	ScnCanvasComponentVertex* pFirstVertex = pVertices;
	
	// Only draw if we can allocate vertices.
	if( pVertices != NULL )
	{
		// Now copy in data.
		BcU32 ABGR = Colour.asABGR();
		
		pVertices->X_ = PointA.x();
		pVertices->Y_ = PointA.y();
		pVertices->Z_ = 0.0f;
		pVertices->W_ = 1.0f;
		pVertices->ABGR_ = ABGR;
		++pVertices;
		pVertices->X_ = PointB.x();
		pVertices->Y_ = PointB.y();
		pVertices->Z_ = 0.0f;
		pVertices->W_ = 1.0f;
		pVertices->ABGR_ = ABGR;

		// Quickly check last primitive.
		BcBool AddNewPrimitive = BcTrue;
		if( LastPrimitiveSection_ != BcErrorCode )
		{
			ScnCanvasComponentPrimitiveSection& PrimitiveSection = PrimitiveSectionList_[ LastPrimitiveSection_ ];

			// If the last primitive was the same type as ours we can append to it.
			// NOTE: Need more checks here later.
			if( PrimitiveSection.Type_ == RsTopologyType::LINE_LIST &&
				PrimitiveSection.Layer_ == Layer &&
				PrimitiveSection.MaterialComponent_ == MaterialComponent_ )
			{
				PrimitiveSection.NoofVertices_ += 2;

				// Matrix stack.
				// TODO: Factor into a seperate function.
				if( IsIdentity_ == BcFalse )
				{
					MaMat4d Matrix = getMatrix();

					for( BcU32 Idx = 0; Idx < 2; ++Idx )
					{
						ScnCanvasComponentVertex* pVertex = &pFirstVertex[ Idx ];
						MaVec3d Vertex = MaVec3d( pVertex->X_, pVertex->Y_, pVertex->Z_ ) * Matrix;
						pVertex->X_ = Vertex.x();
						pVertex->Y_ = Vertex.y();
						pVertex->Z_ = Vertex.z();
						pVertices->W_ = 1.0f;
					}
				}
				
				AddNewPrimitive = BcFalse;
			}
		}
		
		// Add primitive.
		if( AddNewPrimitive == BcTrue )
		{
			addPrimitive( RsTopologyType::LINE_LIST, pFirstVertex, 2, Layer, BcTrue );
		}
	}
}
Beispiel #4
0
Vector SpotLight::getLightVector( HitProperties const& hp ) const {
	return ( getMatrix().getTranslation() - hp.point ).normalized();
}
Beispiel #5
0
static void
zprMotion(int x, int y)
{
    bool changed = false;

    const int dx = x - _mouseX;
    const int dy = y - _mouseY;

    GLint viewport[4];
    glGetIntegerv(GL_VIEWPORT,viewport);

    if (dx==0 && dy==0)
        return;

    if (_mouseMiddle || (_mouseLeft && _mouseRight))
    {
        double s = exp((double)dy*0.01);

        glTranslatef( zprReferencePoint[0], zprReferencePoint[1], zprReferencePoint[2]);
        glScalef(s,s,s);
        glTranslatef(-zprReferencePoint[0],-zprReferencePoint[1],-zprReferencePoint[2]);

        changed = true;
    }
    else
        if (_mouseLeft)
        {
            double ax,ay,az;
            double bx,by,bz;
            double angle;

            ax = dy;
            ay = dx;
            az = 0.0;
            angle = vlen(ax,ay,az)/(double)(viewport[2]+1)*180.0;

            /* Use inverse matrix to determine local axis of rotation */

            bx = _matrixInverse[0]*ax + _matrixInverse[4]*ay + _matrixInverse[8] *az;
            by = _matrixInverse[1]*ax + _matrixInverse[5]*ay + _matrixInverse[9] *az;
            bz = _matrixInverse[2]*ax + _matrixInverse[6]*ay + _matrixInverse[10]*az;

			
            glTranslatef( zprReferencePoint[0], zprReferencePoint[1], zprReferencePoint[2]);
            glRotatef(angle,bx,by,bz);
            glTranslatef(-zprReferencePoint[0],-zprReferencePoint[1],-zprReferencePoint[2]);

            changed = true;
        }
        else
            if (_mouseRight)
            {
                double px,py,pz;

                pos(&px,&py,&pz,x,y,viewport);

                glLoadIdentity();
                glTranslatef(px-_dragPosX,py-_dragPosY,pz-_dragPosZ);
                glMultMatrixd(_matrix);

                _dragPosX = px;
                _dragPosY = py;
                _dragPosZ = pz;

                changed = true;
            }

    _mouseX = x;
    _mouseY = y;

    if (changed)
    {
        getMatrix();
        glutPostRedisplay();
    }
}
Beispiel #6
0
QPointF Canvas::worldToScene(QVector3D v) const
{
    QMatrix4x4 M = getMatrix();
    QVector3D w = M * v;
    return QPointF(w.x(), w.y());
}
Beispiel #7
0
// Right hand effector's collision detection function for multiple objects.
// Purpose:
//		- Determine closest object (based on center) that effector is touching.
// Notes:
//		The list must be a list of Object instances, defined above.
//		This function does not account for rotation of the object or the effector.
void RightVirtualHand::detectCollisions(arEffector& self, vector<arInteractable*>& objects)
{
	// Return if grabbing an object.
	if(getGrabbedObject() != 0) return;
	
	// Set maximum distance for testing collision dection to 1000 ft.
	float maxDistance = 1000.0;
	
	// Track closest object and its distance. No object is initially closest.
	arInteractable* closestObject = 0;
	float closestDistance = maxDistance;
	
	// Step through list of objects and test each one for collisions.
	for(vector<arInteractable*>::iterator it=objects.begin(); it != objects.end(); ++it) {
	
		// Get information about object's position and dimensions.
		const arMatrix4 objectMatrix = (*it)->getMatrix();
		arMatrix4 objectTransMatrix = ar_extractTranslationMatrix(objectMatrix);
		const float objectX = objectTransMatrix[12];
		const float objectY = objectTransMatrix[13];
		const float objectZ = objectTransMatrix[14];
		const float objectLength = ((Object*)(*it))->getLength();
		const float objectHeight = ((Object*)(*it))->getHeight();
		const float objectWidth = ((Object*)(*it))->getWidth();
		
		// Get information about effector's position and dimensions. 
		arMatrix4 effectorTransMatrix = ar_extractTranslationMatrix(getMatrix());
		const float effectorX = effectorTransMatrix[12];
		const float effectorY = effectorTransMatrix[13];
		const float effectorZ = effectorTransMatrix[14];
		const float effectorLength = _size;
		const float effectorHeight = _size;
		const float effectorWidth = _size;
		
		// Determine if effector is within object along X-axis.
		if((objectX - objectLength/2.0) <= (effectorX + effectorLength/2.0) && (effectorX - effectorLength/2.0) <= (objectX + objectLength/2.0)) {
		// Determine if effector is within object along Y-axis.
		if((objectY - objectHeight/2.0) <= (effectorY + effectorHeight/2.0) && (effectorY - effectorHeight/2.0) <= (objectY + objectHeight/2.0)) {
		// Determine if effector is within object along Z-axis.
		if((objectZ - objectWidth/2.0) <= (effectorZ + effectorWidth/2.0) && (effectorZ - effectorWidth/2.0) <= (objectZ + objectWidth/2.0)) {
		
			// Collision detected. Now use selector to determine distance to center of the object.
			_selector.setMaxDistance(maxDistance);
			float objectDistance = _selector.calcDistance(self, objectMatrix);
			
			// Determine if object is closest so far.
			if(objectDistance < closestDistance) {
				// If so, remember object and distance to object.
				closestObject = *it;
				closestDistance = objectDistance;
			}
		}}}
	}
	
	// Check if an object was touched.
	if(closestObject != 0) {
		// If so, set selector's distance to match object's distance.
		_selector.setMaxDistance(closestDistance);
		setInteractionSelector(_selector);
		
		//cout << "object was selected?" << '\n';
		
		if(getOnButton(1) == 1)
		{
			//cout << "object was selected" << '\n';
			Object* oby = (Object*)closestObject;
			oby->_selected = !oby->_selected;
		}
	}
	else {
		// If not, set selector's distance to size of effector.
		_selector.setMaxDistance(_size);
		setInteractionSelector(_selector);
	}

}
Beispiel #8
0
CMatrix CModelX::getFrameMatrix(int no, bool local) {
	CFrameBone *f = (CFrameBone*)CFrameBone::getFrameByNo(no, pFrameRoot);
	return (local) ? f->getSMatrix() : getMatrix() * f->getSMatrix();
}
Beispiel #9
0
void Gizmo::setCameraRay(const Vec3& origin, const Vec3& cursor_dir)
{
	if (m_editor.getSelectedEntities().empty()) return;
	if (m_is_transforming) return;

	Matrix scale_mtx = Matrix::IDENTITY;
	scale_mtx.m11 = scale_mtx.m22 = scale_mtx.m33 = m_scale;
	Matrix gizmo_mtx;
	getMatrix(gizmo_mtx);
	Matrix mtx = gizmo_mtx * scale_mtx;
	Vec3 pos = mtx.getTranslation();
	m_camera_dir = (origin - pos).normalized();

	m_transform_axis = Axis::NONE;

	if (m_mode == Mode::TRANSLATE)
	{
		Matrix triangle_mtx = mtx;

		if (dotProduct(gizmo_mtx.getXVector(), m_camera_dir) < 0) triangle_mtx.setXVector(-triangle_mtx.getXVector());
		if (dotProduct(gizmo_mtx.getYVector(), m_camera_dir) < 0) triangle_mtx.setYVector(-triangle_mtx.getYVector());
		if (dotProduct(gizmo_mtx.getZVector(), m_camera_dir) < 0) triangle_mtx.setZVector(-triangle_mtx.getZVector());

		float t, tmin = FLT_MAX;
		bool hit = Math::getRayTriangleIntersection(
			origin, cursor_dir, pos, pos + triangle_mtx.getXVector() * 0.5f, pos + triangle_mtx.getYVector() * 0.5f, &t);
		if (hit)
		{
			tmin = t;
			m_transform_axis = Axis::XY;
		}
		hit = Math::getRayTriangleIntersection(
			origin, cursor_dir, pos, pos + triangle_mtx.getYVector() * 0.5f, pos + triangle_mtx.getZVector() * 0.5f, &t);
		if (hit && t < tmin)
		{
			tmin = t;
			m_transform_axis = Axis::YZ;
		}
		hit = Math::getRayTriangleIntersection(
			origin, cursor_dir, pos, pos + triangle_mtx.getXVector() * 0.5f, pos + triangle_mtx.getZVector() * 0.5f, &t);
		if (hit && t < tmin)
		{
			m_transform_axis = Axis::XZ;
		}

		if (m_transform_axis != Axis::NONE) return;

		float x_dist = Math::getLineSegmentDistance(origin, cursor_dir, pos, pos + mtx.getXVector());
		float y_dist = Math::getLineSegmentDistance(origin, cursor_dir, pos, pos + mtx.getYVector());
		float z_dist = Math::getLineSegmentDistance(origin, cursor_dir, pos, pos + mtx.getZVector());

		float influenced_dist = m_scale * INFLUENCE_DISTANCE;
		if (x_dist > influenced_dist && y_dist > influenced_dist && z_dist > influenced_dist)
		{
			m_transform_axis = Axis::NONE;
			return;
		}

		if (x_dist < y_dist && x_dist < z_dist) m_transform_axis = Axis::X;
		else if (y_dist < z_dist) m_transform_axis = Axis::Y;
		else m_transform_axis = Axis::Z;

		return;
	}

	if (m_mode == Mode::ROTATE)
	{
		Vec3 hit;
		if (Math::getRaySphereIntersection(origin, cursor_dir, pos, m_scale, hit))
		{
			auto x = gizmo_mtx.getXVector();
			float x_dist = fabs(dotProduct(hit, x) - dotProduct(x, pos));
			
			auto y = gizmo_mtx.getYVector();
			float y_dist = fabs(dotProduct(hit, y) - dotProduct(y, pos));

			auto z = gizmo_mtx.getZVector();
			float z_dist = fabs(dotProduct(hit, z) - dotProduct(z, pos));

			float qq= m_scale * 0.15f;
			if (x_dist > qq && y_dist > qq && z_dist > qq)
			{
				m_transform_axis = Axis::NONE;
				return;
			}

			if (x_dist < y_dist && x_dist < z_dist) m_transform_axis = Axis::X;
			else if (y_dist < z_dist) m_transform_axis = Axis::Y;
			else m_transform_axis = Axis::Z;
		}
	}
}
Beispiel #10
0
/** Performs the transformation. */
void Scale::apply() {
	
	State::push();
	State::apply(getMatrix());
}
Beispiel #11
0
CMatrix CModelX::getFrameMatrix(const char *name, bool local) {
	CFrameBone *f = (CFrameBone*)CFrameBone::getFrameByName(name, pFrameRoot);
	return (local) ? f->getSMatrix() : getMatrix() * f->getSMatrix();
}
Beispiel #12
0
 void Graphics::scale(const float x, const float y, const float z) {
   setMatrix(getMatrix() * Matrix::scale(x, y, z));
 }
Beispiel #13
0
 void Graphics::rotate(const float angle, const float x, const float y, const float z) {
   setMatrix(getMatrix() * Matrix::rotation(angle, x, y, z));
 }
Beispiel #14
0
 void Graphics::translate(const float x, const float y, const float z) {
   setMatrix(getMatrix() * Matrix::translation(x, y, z));
 }
Beispiel #15
0
void ASprite::computeMatrix()
{
    //m_program->bind();
    AMatrix4x4 viewMatrix = getViewPortMatrix() * getMatrix();

    AMatrix4x4 lbmatrix = viewMatrix;

    lbmatrix.translate(mx_offset,my_offset,0);
    lbmatrix.rotate(m_angle,0,0,1);
    lbmatrix.translate(-mx_offset,-my_offset,0);
    m_program->setUniformValue("mvp_matrix", lbmatrix);//set shader

    if(isNeedRealTime)
    {
	AMatrix4x4 ltmatrix = viewMatrix;
	AMatrix4x4 rbmatrix = viewMatrix;
	AMatrix4x4 rtmatrix = viewMatrix;

	//ltmatrix.translate(0,m_geometric.height(),0);
	//rbmatrix.translate(m_geometric.width(),0,0);
	//rtmatrix.translate(m_geometric.width(),m_geometric.height(),0);
	//ltmatrix.translate(0,-m_geometric.height(),0);

	ltmatrix.translate(mx_offset,my_offset,0);
	ltmatrix.rotate(m_angle,0,0,1);
	ltmatrix.translate(-mx_offset,-my_offset,0);
	ltmatrix.translate(0,m_geometric.height(),0);

	rbmatrix.translate(mx_offset,my_offset,0);
	rbmatrix.rotate(m_angle,0,0,1);
	rbmatrix.translate(-mx_offset,-my_offset,0);
	rbmatrix.translate(m_geometric.width(),0,0);

	rtmatrix.translate(mx_offset,my_offset,0);
	rtmatrix.rotate(m_angle,0,0,1);
	rtmatrix.translate(-mx_offset,-my_offset,0);
	rtmatrix.translate(m_geometric.width(),m_geometric.height(),0);

	AMatrix4x4 currentMatrix = getViewPortMatrix().inverted();
	AMatrix4x4 leftBottonMatrix =  currentMatrix * lbmatrix;
	AMatrix4x4 leftTopMatrix = currentMatrix * ltmatrix;
	AMatrix4x4 rightBottonMatrix = currentMatrix * rbmatrix;
	AMatrix4x4 rightTopMatrix = currentMatrix * rtmatrix;

	float lbx = leftBottonMatrix.row(0).w();
	float lby = leftBottonMatrix.row(1).w();

	m_leftBottonX = lbx;
	m_leftBottonY = lby;

	float ltx = leftTopMatrix.row(0).w();
	float lty = leftTopMatrix.row(1).w();

	m_leftTopX = ltx;
	m_leftTopY = lty;

	float rbx = rightBottonMatrix.row(0).w();
	float rby = rightBottonMatrix.row(1).w();

	m_rightBottonX = rbx;
	m_rightBottonY = rby;

	float rtx = rightTopMatrix.row(0).w();
	float rty = rightTopMatrix.row(1).w();

	m_rightTopX = rtx;
	m_rightTopY = rty;
    }

}
Beispiel #16
0
void Gizmo::renderTranslateGizmo(PipelineInstance& pipeline)
{
	if (!m_shader->isReady()) return;

	Matrix scale_mtx = Matrix::IDENTITY;
	scale_mtx.m11 = scale_mtx.m22 = scale_mtx.m33 = m_scale;
	Matrix gizmo_mtx;
	getMatrix(gizmo_mtx);
	Matrix mtx = gizmo_mtx * scale_mtx;
	
	Vertex vertices[9];
	uint16 indices[9];
	vertices[0].position = Vec3(0, 0, 0);
	vertices[0].color = m_transform_axis == Axis::X ? SELECTED_COLOR : X_COLOR;
	indices[0] = 0;
	vertices[1].position = Vec3(1, 0, 0);
	vertices[1].color = m_transform_axis == Axis::X ? SELECTED_COLOR : X_COLOR;
	indices[1] = 1;
	vertices[2].position = Vec3(0, 0, 0);
	vertices[2].color = m_transform_axis == Axis::Y ? SELECTED_COLOR : Y_COLOR;
	indices[2] = 2;
	vertices[3].position = Vec3(0, 1, 0);
	vertices[3].color = m_transform_axis == Axis::Y ? SELECTED_COLOR : Y_COLOR;
	indices[3] = 3;
	vertices[4].position = Vec3(0, 0, 0);
	vertices[4].color = m_transform_axis == Axis::Z ? SELECTED_COLOR : Z_COLOR;
	indices[4] = 4;
	vertices[5].position = Vec3(0, 0, 1);
	vertices[5].color = m_transform_axis == Axis::Z ? SELECTED_COLOR : Z_COLOR;
	indices[5] = 5;

	Lumix::TransientGeometry geom(vertices, 6, m_vertex_decl, indices, 6);
	pipeline.render(geom,
		mtx,
		0,
		6,
		BGFX_STATE_PT_LINES | BGFX_STATE_DEPTH_TEST_LEQUAL,
		m_shader->getInstance(0).m_program_handles[pipeline.getPassIdx()]);

	if (dotProduct(gizmo_mtx.getXVector(), m_camera_dir) < 0) mtx.setXVector(-mtx.getXVector());
	if (dotProduct(gizmo_mtx.getYVector(), m_camera_dir) < 0) mtx.setYVector(-mtx.getYVector());
	if (dotProduct(gizmo_mtx.getZVector(), m_camera_dir) < 0) mtx.setZVector(-mtx.getZVector());

	vertices[0].position = Vec3(0, 0, 0);
	vertices[0].color = m_transform_axis == Axis::XY ? SELECTED_COLOR : Z_COLOR;
	indices[0] = 0;
	vertices[1].position = Vec3(0.5f, 0, 0);
	vertices[1].color = m_transform_axis == Axis::XY ? SELECTED_COLOR : Z_COLOR;
	indices[1] = 1;
	vertices[2].position = Vec3(0, 0.5f, 0);
	vertices[2].color = m_transform_axis == Axis::XY ? SELECTED_COLOR : Z_COLOR;
	indices[2] = 2;

	vertices[3].position = Vec3(0, 0, 0);
	vertices[3].color = m_transform_axis == Axis::YZ ? SELECTED_COLOR : X_COLOR;
	indices[3] = 3;
	vertices[4].position = Vec3(0, 0.5f, 0);
	vertices[4].color = m_transform_axis == Axis::YZ ? SELECTED_COLOR : X_COLOR;
	indices[4] = 4;
	vertices[5].position = Vec3(0, 0, 0.5f);
	vertices[5].color = m_transform_axis == Axis::YZ ? SELECTED_COLOR : X_COLOR;
	indices[5] = 5;

	vertices[6].position = Vec3(0, 0, 0);
	vertices[6].color = m_transform_axis == Axis::XZ ? SELECTED_COLOR : Y_COLOR;
	indices[6] = 6;
	vertices[7].position = Vec3(0.5f, 0, 0);
	vertices[7].color = m_transform_axis == Axis::XZ ? SELECTED_COLOR : Y_COLOR;
	indices[7] = 7;
	vertices[8].position = Vec3(0, 0, 0.5f);
	vertices[8].color = m_transform_axis == Axis::XZ ? SELECTED_COLOR : Y_COLOR;
	indices[8] = 8;

	Lumix::TransientGeometry geom2(vertices, 9, m_vertex_decl, indices, 9);
	auto program_handle = m_shader->getInstance(0).m_program_handles[pipeline.getPassIdx()];
	pipeline.render(geom2, mtx, 0, 9, BGFX_STATE_DEPTH_TEST_LEQUAL, program_handle);
}
Beispiel #17
0
osg::Matrixd ViewingCore::getInverseMatrix() const
{
    osg::Matrixd m;
    m.invert( getMatrix() );
    return( m );
}
Beispiel #18
0
Matrix4X4 * GLMath::getTransformation(void)
{
    //_glMatrixMultiply(&transformation, getMatrix(_GL_MATRIXMODE_MODELVIEW), getMatrix(_GL_MATRIXMODE_PROJECTION));
    _glMatrixMultiply(&transformation, getMatrix(_GL_MATRIXMODE_PROJECTION), getMatrix(_GL_MATRIXMODE_MODELVIEW));
    return &transformation;
}
Beispiel #19
0
QVector3D Canvas::sceneToWorld(QPointF p) const
{
    QMatrix4x4 M = getMatrix().inverted();
    return M * QVector3D(p.x(), p.y(), 0);
}
	SFC::DT getMatrix( int rows, int columns, const std::string &typeName ) {
		return getMatrix(  rows, columns, getBasicType( typeName )  );
	}
Beispiel #21
0
	const glm::mat4 &Transformation::getTranslationMatrix() const
	{
		if(dirty)
			getMatrix();
		return m_cacheTranslationMatrix;
	}
Beispiel #22
0
Matrix4D ParametrizedRayGroup::getInverseMatrix(void){return getMatrix().invert();}
Beispiel #23
0
void
TextSnapshot_as::getTextRunInfo(size_t start, size_t end, as_object& ri) const
{
    std::string::size_type pos = 0;

    std::string::size_type len = end - start;

    for (TextFields::const_iterator field = _textFields.begin(),
            e = _textFields.end(); field != e; ++field) {

        const Records& rec = field->second;
        const SWFMatrix& mat = getMatrix(*field->first);
        const boost::dynamic_bitset<>& selected = field->first->getSelected();

        const std::string::size_type fieldStartIndex = pos;

        for (Records::const_iterator j = rec.begin(), end = rec.end();
                j != end; ++j) {
        
            const SWF::TextRecord* tr = *j;
            assert(tr);

            const SWF::TextRecord::Glyphs& glyphs = tr->glyphs();
            const SWF::TextRecord::Glyphs::size_type numGlyphs = glyphs.size();

            if (pos + numGlyphs < start) {
                pos += numGlyphs;
                continue;
            }

            const Font* font = tr->getFont();
            assert(font);

            double x = tr->xOffset();
            for (SWF::TextRecord::Glyphs::const_iterator k = glyphs.begin(),
                    e = glyphs.end(); k != e; ++k) {
                
                if (pos < start) {
                    x += k->advance;
                    ++pos;
                    continue;
                }
                
                as_object* el = new as_object(getGlobal(ri));

                el->init_member("indexInRun", pos);
                el->init_member("selected",
                        selected.test(pos - fieldStartIndex));
                el->init_member("font", font->name());
                el->init_member("color", tr->color().toRGBA());
                el->init_member("height", twipsToPixels(tr->textHeight()));

                const double factor = 65536.0;
                el->init_member("matrix_a", mat.a() / factor);
                el->init_member("matrix_b", mat.b() / factor);
                el->init_member("matrix_c", mat.c() / factor);
                el->init_member("matrix_d", mat.d() / factor);

                const double xpos = twipsToPixels(mat.tx() + x);
                const double ypos = twipsToPixels(mat.ty() + tr->yOffset());
                el->init_member("matrix_tx", xpos);
                el->init_member("matrix_ty", ypos);

                callMethod(&ri, NSV::PROP_PUSH, el);

                ++pos;
                x += k->advance;
                if (pos - start > len) return;
            }
        }
    }
    
}
Beispiel #24
0
Matrix4D ParametrizedRayGroup::getNormalMatrix(void){return getMatrix().invert().transpose();}
void ColorDisplayFilter::changed(ConstFieldMaskArg whichField, 
                                 UInt32            origin,
                                 BitVector         details)
{
    Inherited::changed(whichField, origin, details);

    if(0x0000 != (whichField & (ColorTableWidthFieldMask  |
                                ColorTableHeightFieldMask |
                                ColorTableDepthFieldMask  |
                                ColorTableFieldMask       )))
    {
        UInt32 c;
        std::vector<UChar8> vImageData;

        UInt32 uiWidth  = getColorTableWidth ();
        UInt32 uiHeight = getColorTableHeight();
        UInt32 uiDepth  = getColorTableDepth ();

        UInt32 uiSize = (uiWidth * uiHeight * uiDepth);

        if(uiSize != getMFColorTable()->size() || uiDepth < 2)
        {
            // create default linear table
            //FWARNING(("Wrong shading table size\n"));

            uiWidth = uiHeight = 1;

            uiDepth = 2;

            vImageData.push_back(0);
            vImageData.push_back(0);
            vImageData.push_back(0);

            vImageData.push_back(255);
            vImageData.push_back(255);
            vImageData.push_back(255);
        } 
        else
        {
            const MFColor3f &vColors = *(this->getMFColorTable());

            vImageData.resize(uiSize * 3);

            for(c = 0; c < uiSize ; ++c)
            {
                vImageData[c * 3 + 0] = UChar8(vColors[c][0] * 255);
                vImageData[c * 3 + 1] = UChar8(vColors[c][1] * 255);
                vImageData[c * 3 + 2] = UChar8(vColors[c][2] * 255);
            }
        }

        Image *pImg = this->getTableImage();

        if(pImg == NULL)
        {
            // Make Cluster Local
            ImageUnrecPtr pImage = Image::createLocal(FCLocal::Cluster);

            pImg = pImage;

            this->setTableImage(pImage);
        }

        pImg->set( Image::OSG_RGB_PF,
                   uiWidth, uiHeight, uiDepth,
                   1, 1, 0,
                  &vImageData[0]);

        
        SimpleSHLChunk *pShader = this->getFilterShader();

        if(pShader != NULL)
        {
            pShader->addUniformVariable("shadingWidth",  Int32(uiWidth));
            pShader->addUniformVariable("shadingHeight", Int32(uiHeight));
            pShader->addUniformVariable("shadingDepth",  Int32(uiDepth));
        }
    }
  
    if(0x0000 != (whichField & (MatrixFieldMask)))
    {
        SimpleSHLChunk *pShader = this->getFilterShader();

        if(pShader != NULL)
        {
            pShader->addUniformVariable("colorMatrix", getMatrix());
        }
    }

    if(0x0000 != (whichField & (GammaFieldMask)))
    {
        SimpleSHLChunk *pShader = this->getFilterShader();

        if(pShader != NULL)
        {
            pShader->addUniformVariable("gamma", getGamma());
        }
    }
}
Beispiel #26
0
//----------------------------------------------------- matrix.
ofMatrix4x4 QuadWarp::getMatrix() {
    return getMatrix(&srcPoints[0], &dstPoints[0]);
}
Beispiel #27
0
void cameraInfoHandler(const sensor_msgs::ImageConstPtr& left
        , const sensor_msgs::ImageConstPtr& right
        , const sensor_msgs::ImageConstPtr& depth
        , const sensor_msgs::CameraInfoConstPtr& leftCameraInfo
        , const sensor_msgs::CameraInfoConstPtr& rightCameraInfo)
{
    //TODO: calibarate cameras - assume cameras are calibrated

    //rectification

    static std::vector<std::vector<double> > leftCamMatData = {
        {leftCameraInfo->K[0], leftCameraInfo->K[1], leftCameraInfo->K[2]},
        {leftCameraInfo->K[3], leftCameraInfo->K[4], leftCameraInfo->K[5]},
        {leftCameraInfo->K[6], leftCameraInfo->K[7], leftCameraInfo->K[8]}
    };

    static std::vector<std::vector<double> > rightCamMatData = {
        {rightCameraInfo->K[0], rightCameraInfo->K[1], rightCameraInfo->K[2]},
        {rightCameraInfo->K[3], rightCameraInfo->K[4], rightCameraInfo->K[5]},
        {rightCameraInfo->K[6], rightCameraInfo->K[7], rightCameraInfo->K[8]}
    };

    static std::vector<std::vector<double> > rData = {
        {leftCameraInfo->R[0], leftCameraInfo->R[1], leftCameraInfo->R[2]},
        {leftCameraInfo->R[3], leftCameraInfo->R[4], leftCameraInfo->R[5]},
        {leftCameraInfo->R[6], leftCameraInfo->R[7], leftCameraInfo->R[8]}
    };

    static std::vector<std::vector<double> > leftCamDData = {
        { leftCameraInfo->D[0] },
        { leftCameraInfo->D[1] },
        { leftCameraInfo->D[2] },
        { leftCameraInfo->D[3] },
        { leftCameraInfo->D[4] }
    };

    static std::vector<std::vector<double> > rightCamDData = {
        { rightCameraInfo->D[0] },
        { rightCameraInfo->D[1] },
        { rightCameraInfo->D[2] },
        { rightCameraInfo->D[3] },
        { rightCameraInfo->D[4] }
    };

    static std::vector<std::vector<double> > tData = {
        { rightCameraInfo->P[3] },
        { rightCameraInfo->P[7] },
        { rightCameraInfo->P[11] }
    };

    static cv::Mat leftCamMat = getMatrix(leftCamMatData);
    static cv::Mat rightCamMat = getMatrix(rightCamMatData);
    static cv::Mat leftCamD = getMatrix(leftCamDData);
    static cv::Mat rightCamD = getMatrix(rightCamDData);
    static cv::Mat R = getMatrix(rData);
    static cv::Mat T = getMatrix(tData);
    static cv::Mat R1, R2, P1, P2;

    if (Q.empty())
    {
        cv::stereoRectify(
            leftCamMat,
            leftCamD,
            rightCamMat,
            rightCamD,
            cv::Size(leftCameraInfo->width, leftCameraInfo->height),
            R,
            T,
            R1,
            R2,
            P1,
            P2,
            Q
        );
        Q.convertTo(Q, CV_32FC1);
        Q.at<float>(3, 3) = -Q.at<float>(3, 3);
        std::cout << "Computed rectification matrices!" << std::endl;
    }

    if (leftCamMap1.empty() && leftCamMap2.empty())
    {
        cv::initUndistortRectifyMap(
            leftCamMat,
            leftCamD,
            R1,
            leftCamMat,
            cv::Size(leftCameraInfo->width, leftCameraInfo->height),
            CV_32FC1,
            leftCamMap1,
            leftCamMap2
        );
        std::cout << "Computed rectification map for left camera!" << std::endl;
    }


    if (rightCamMap1.empty() && rightCamMap2.empty())
    {
        cv::initUndistortRectifyMap(
            rightCamMat,
            rightCamD,
            R2,
            rightCamMat,
            cv::Size(rightCameraInfo->width, rightCameraInfo->height),
            CV_32FC1,
            rightCamMap1,
            rightCamMap2
        );
        std::cout << "Computed rectification map for right camera!" << std::endl;
    }

}
Beispiel #28
0
ofMatrix4x4 QuadWarp::getMatrixInverse() {
    return getMatrix(&dstPoints[0], &srcPoints[0]);
}
Beispiel #29
0
//////////////////////////////////////////////////////////////////////////
// drawSprite
void ScnCanvasComponent::drawSprite( const MaVec2d& Position, const MaVec2d& Size, BcU32 TextureIdx, const RsColour& Colour, BcU32 Layer )
{
	ScnCanvasComponentVertex* pVertices = allocVertices( 6 );
	ScnCanvasComponentVertex* pFirstVertex = pVertices;
	
	const MaVec2d CornerA = Position;
	const MaVec2d CornerB = Position + Size;

	const ScnRect Rect = DiffuseTexture_.isValid() ? DiffuseTexture_->getRect( TextureIdx ) : ScnRect();
	
	// Only draw if we can allocate vertices.
	if( pVertices != NULL )
	{
		// Now copy in data.
		BcU32 ABGR = Colour.asABGR();
		
		pVertices->X_ = CornerA.x();
		pVertices->Y_ = CornerA.y();
		pVertices->Z_ = 0.0f;
		pVertices->W_ = 1.0f;
		pVertices->U_ = Rect.X_;
		pVertices->V_ = Rect.Y_;
		pVertices->ABGR_ = ABGR;
		++pVertices;
		
		pVertices->X_ = CornerB.x();
		pVertices->Y_ = CornerA.y();
		pVertices->Z_ = 0.0f;
		pVertices->W_ = 1.0f;
		pVertices->U_ = Rect.X_ + Rect.W_;
		pVertices->V_ = Rect.Y_;
		pVertices->ABGR_ = ABGR;
		++pVertices;
		
		pVertices->X_ = CornerA.x();
		pVertices->Y_ = CornerB.y();
		pVertices->Z_ = 0.0f;
		pVertices->W_ = 1.0f;
		pVertices->U_ = Rect.X_;
		pVertices->V_ = Rect.Y_ + Rect.H_;
		pVertices->ABGR_ = ABGR;
		++pVertices;
		
		pVertices->X_ = CornerA.x();
		pVertices->Y_ = CornerB.y();
		pVertices->Z_ = 0.0f;
		pVertices->W_ = 1.0f;
		pVertices->U_ = Rect.X_;
		pVertices->V_ = Rect.Y_ + Rect.H_;
		pVertices->ABGR_ = ABGR;
		++pVertices;

		pVertices->X_ = CornerB.x();
		pVertices->Y_ = CornerA.y();
		pVertices->Z_ = 0.0f;
		pVertices->W_ = 1.0f;
		pVertices->U_ = Rect.X_ + Rect.W_;
		pVertices->V_ = Rect.Y_;
		pVertices->ABGR_ = ABGR;
		++pVertices;

		pVertices->X_ = CornerB.x();
		pVertices->Y_ = CornerB.y();
		pVertices->Z_ = 0.0f;
		pVertices->W_ = 1.0f;
		pVertices->U_ = Rect.X_ + Rect.W_;
		pVertices->V_ = Rect.Y_ + Rect.H_;
		pVertices->ABGR_ = ABGR;
		
		// Quickly check last primitive.
		BcBool AddNewPrimitive = BcTrue;
		if( LastPrimitiveSection_ != BcErrorCode )
		{
			ScnCanvasComponentPrimitiveSection& PrimitiveSection = PrimitiveSectionList_[ LastPrimitiveSection_ ];

			// If the last primitive was the same type as ours we can append to it.
			// NOTE: Need more checks here later.
			if( PrimitiveSection.Type_ == RsTopologyType::TRIANGLE_LIST &&
				PrimitiveSection.Layer_ == Layer &&
				PrimitiveSection.MaterialComponent_ == MaterialComponent_ )
			{
				PrimitiveSection.NoofVertices_ += 6;

				// Matrix stack.
				// TODO: Factor into a seperate function.
				if( IsIdentity_ == BcFalse )
				{
					MaMat4d Matrix = getMatrix();

					for( BcU32 Idx = 0; Idx < 6; ++Idx )
					{
						ScnCanvasComponentVertex* pVertex = &pFirstVertex[ Idx ];
						MaVec3d Vertex = MaVec3d( pVertex->X_, pVertex->Y_, pVertex->Z_ ) * Matrix;
						pVertex->X_ = Vertex.x();
						pVertex->Y_ = Vertex.y();
						pVertex->Z_ = Vertex.z();
						pVertex->W_ = 1.0f;
					}
				}
				
				AddNewPrimitive = BcFalse;
			}
		}
		
		// Add primitive.
		if( AddNewPrimitive == BcTrue )
		{
			addPrimitive( RsTopologyType::TRIANGLE_LIST, pFirstVertex, 6, Layer, BcTrue );
		}
	}
}
Beispiel #30
0
 void Graphics::frustum(const float left, const float right, const float bottom, const float top, const float near, const float far) {
   setMatrix(getMatrix() * Matrix::frustum(left, right, bottom, top, near, far));
 }