本文整理汇总了C++中Matrix44f::translate方法的典型用法代码示例。如果您正苦于以下问题:C++ Matrix44f::translate方法的具体用法?C++ Matrix44f::translate怎么用?C++ Matrix44f::translate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Matrix44f
的用法示例。
在下文中一共展示了Matrix44f::translate方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
btSoftBody* SoftBody::createSoftMesh( btSoftBodyWorldInfo &info, const TriMesh &mesh, const Vec3f &scale,
const Vec3f &position, const Quatf &rotation )
{
Matrix44f transform;
transform.setToIdentity();
transform.translate( position );
transform.rotate( rotation.v );
transform.translate( position * -1.0f );
transform.translate( position );
btScalar* positions = new btScalar[ mesh.getNumVertices() * 3 ];
size_t i = 0;
for ( vector<Vec3f>::const_iterator iter = mesh.getVertices().begin(); iter != mesh.getVertices().end(); ++iter, i += 3 ) {
Vec3f position = transform.transformPoint( *iter );
positions[ i + 0 ] = position.x;
positions[ i + 1 ] = position.y;
positions[ i + 2 ] = position.z;
}
int* indices = new int[ mesh.getIndices().size() ];
i = 0;
for ( vector<size_t>::const_iterator iter = mesh.getIndices().begin(); iter != mesh.getIndices().end(); ++iter, ++i ) {
indices[ i ] = (int)*iter;
}
btSoftBody* body = btSoftBodyHelpers::CreateFromTriMesh( info, positions, indices, mesh.getNumTriangles() );
//body->scale( toBulletVector3( scale ) );
delete [] indices;
delete [] positions;
return body;
}
示例2: update
void UiLayer::update()
{
Vec2f interfaceSize = getRoot()->getInterfaceSize();
// check for orientation change
if( interfaceSize != mInterfaceSize ){
updateLayout( interfaceSize );
}
if ( !mHasPanelBeenDragged ) {
// if we're not dragging, animate to current state
if( mIsPanelOpen ){
mPanelY += (mPanelOpenY - mPanelY) * 0.25f;
}
else {
mPanelY += (mPanelClosedY - mPanelY) * 0.25f;
}
}
mChooserY += (mChooserDestY - mChooserY) * 0.25f;
mSettingsY += (mSettingsDestY - mSettingsY) * 0.25f;
mPlaylistChooser->setTransform( Matrix44f::createTranslation( Vec3f(0, mChooserY, 0) ) );
mAlphaChooser->setTransform( Matrix44f::createTranslation( Vec3f(0, mChooserY, 0) ) );
mSettingsPanel->setTransform( Matrix44f::createTranslation( Vec3f(0, mSettingsY, 0) ) );
// don't use mPanelOpenY or current height as a constraint here,
// use maximum value because we want things to ease closed
const float maxPanelY = mInterfaceSize.y - getMaxPanelHeight();
mPanelY = constrain( mPanelY, maxPanelY, mPanelClosedY );
Matrix44f transform;
transform.translate( Vec3f( 0, ceil( mPanelY ), 0 ) );
setTransform( transform );
}
示例3: switch
// if you're doing 2D drawing, this matrix moves the origin to the correct device corner
// to get the window size, use app::getWindowSize(), test for
// isLandscape(event.getInterfaceOrientation()) and apply a .yx() swizzle
Matrix44f getOrientationMatrix44(const Orientation &orientation, const Vec2f &deviceSize)
{
Matrix44f orientationMtx;
switch ( orientation )
{
case UPSIDE_DOWN_PORTRAIT_ORIENTATION:
orientationMtx.translate( Vec3f( deviceSize.x, deviceSize.y, 0 ) );
orientationMtx.rotate( Vec3f( 0, 0, M_PI ) );
break;
case LANDSCAPE_LEFT_ORIENTATION:
orientationMtx.translate( Vec3f( deviceSize.x, 0, 0 ) );
orientationMtx.rotate( Vec3f( 0, 0, M_PI/2.0 ) );
break;
case LANDSCAPE_RIGHT_ORIENTATION:
orientationMtx.translate( Vec3f( 0, deviceSize.y, 0 ) );
orientationMtx.rotate( Vec3f( 0, 0, -M_PI/2.0 ) );
break;
default:
break;
}
return orientationMtx;
}
示例4: toBulletTransform
btSoftBody* SoftBody::createSoftHull( btSoftBodyWorldInfo &info, const TriMesh &mesh, const Vec3f &scale,
const Vec3f &position, const Quatf &rotation )
{
Matrix44f transform;
transform.setToIdentity();
transform.translate( position );
transform.rotate( rotation.v );
transform.translate( position * -1.0f );
transform.translate( position );
btVector3* positions = new btVector3[ mesh.getNumVertices() ];
size_t i = 0;
for ( vector<Vec3f>::const_iterator iter = mesh.getVertices().begin(); iter != mesh.getVertices().end(); ++iter, ++i ) {
positions[ i ] = toBulletVector3( *iter );
}
btSoftBody* body = btSoftBodyHelpers::CreateFromConvexHull( info, positions, mesh.getNumIndices(), false );
body->transform( toBulletTransform( transform ) );
body->scale( toBulletVector3( scale ) );
delete [] positions;
return body;
}
示例5: createSoftCloth
btSoftBody* SoftBody::createSoftCloth( btSoftBodyWorldInfo &info, const Vec2f &size, const Vec2i &resolution,
int32_t corners, const Vec3f &position, const Quatf &rotation )
{
Matrix44f transform;
transform.setToIdentity();
transform.translate( position );
transform.rotate( rotation.v );
transform.translate( position * -1.0f );
transform.translate( position );
float h = size.y * 0.5f;
float w = size.x * 0.5f;
btSoftBody* body = btSoftBodyHelpers::CreatePatch(
info,
toBulletVector3( transform.transformPoint( Vec3f( -w, 0.0f, -h ) ) ),
toBulletVector3( transform.transformPoint( Vec3f( w, 0.0f, -h ) ) ),
toBulletVector3( transform.transformPoint( Vec3f( -w, 0.0f, h ) ) ),
toBulletVector3( transform.transformPoint( Vec3f( w, 0.0f, h ) ) ),
resolution.x, resolution.y,
corners, true
);
return body;
}
示例6: setup
void MeshViewApp::setup()
{
loadConfig("configs/gaztank.ini");
setupCamera();
// Create lights
m_light1 = new gl::Light(gl::Light::DIRECTIONAL, 0);
m_light1->setDirection(Vec3f(0, 0, 1).normalized());
m_light1->setAmbient(Color(0.0f, 0.0f, 0.1f));
m_light1->setDiffuse(Color(0.9f, 0.6f, 0.3f));
m_light1->setSpecular(Color(0.9f, 0.6f, 0.3f));
m_light2 = new gl::Light(gl::Light::DIRECTIONAL, 1);
m_light2->setDirection(Vec3f(0, 0, -1).normalized());
m_light2->setAmbient(Color(0.0f, 0.0f, 0.0f));
m_light2->setDiffuse(Color(0.2f, 0.6f, 1.0f));
m_light2->setSpecular(Color(0.2f, 0.2f, 0.2f));
// Setup matrix
m_matrix.setToIdentity();
m_matrix.translate(Vec3f::zero());
m_matrix.rotate(Vec3f::zero());
m_matrix.scale(Vec3f::one());
m_rotateMesh = false;
// Create a parameter window
m_params = params::InterfaceGl::create(getWindow(), "Properties", Vec2i(180, 240));
m_params->addText("LMB + drag - rotate");
m_params->addText("RMB + drag - zoom");
m_params->addSeparator();
m_params->addButton("Full screen", [&] { setFullScreen(!isFullScreen()); });
m_params->addParam("Auto rotate", &m_rotateMesh);
m_params->addSeparator();
m_params->addParam("Diffuse", &m_diffuseEnabled);
m_params->addParam("Normal", &m_normalEnabled);
m_params->addParam("Specular", &m_specularEnabled);
m_params->addParam("AO", &m_aoEnabled);
m_params->addParam("Emissive", &m_emissiveEnabled);
m_params->addSeparator();
m_params->addParam("Gamma", &m_gamma, "min=0.0 max=10.0 step=0.1");
m_time = (float)getElapsedSeconds();
}
示例7: initializeBuffer
void HexagonMirrorApp::initializeBuffer()
{
// To pass the model matrix for each instance, we will use
// a custom vertex shader attribute. Using an attribute will
// give us more freedom and more storage capacity than using
// a uniform buffer, which often has a capacity limit of 64KB
// or less, which is just enough for 1024 instances.
//
// Because we want the attribute to stay the same for all
// vertices of an instance, we set the divisor to '1' instead
// of '0', so the attribute will only change after all
// vertices of the instance have been drawn.
//
// See for more information: http://ogldev.atspace.co.uk/www/tutorial33/tutorial33.html
// initialize transforms for every instance
std::vector< Matrix44f > matrices;
matrices.reserve( NUM_INSTANCES );
for(size_t i=0; i<NUM_INSTANCES; ++i)
{
// determine position for this hexagon
float x = math<float>::fmod( float(i), INSTANCES_PER_ROW );
float y = math<float>::floor( float(i) / INSTANCES_PER_ROW );
// create transform matrix, then rotate and translate it
Matrix44f model;
model.translate( Vec3f( 3.0f * x + 1.5f * math<float>::fmod( y, 2.0f ) , 0.866025f * y, 0.0f ) );
matrices.push_back( model );
}
// retrieve attribute location from the shader
// (note: make sure the shader is loaded and compiled before calling this function)
GLint ulocation = mShaderInstanced.getAttribLocation( "model_matrix" );
// if found...
if( ulocation != -1 )
{
// create vertex array object to hold our buffer
// (note: this is required for OpenGL 3.1 and above)
glGenVertexArrays(1, &mVAO);
glBindVertexArray(mVAO);
// create array buffer to store model matrices
mBuffer = gl::Vbo( GL_ARRAY_BUFFER );
// setup the buffer to contain space for all matrices.
// we need 4 attributes to contain the 16 floats of a single matrix,
// because the maximum size of an attribute is 4 floats (16 bytes).
// When adding a 'mat4' attribute, OpenGL will make sure that
// the attribute locations are sequential, e.g.: 3, 4, 5 and 6
mBuffer.bind();
for (unsigned int i = 0; i < 4 ; i++) {
glEnableVertexAttribArray(ulocation + i);
glVertexAttribPointer( ulocation + i, 4, GL_FLOAT, GL_FALSE, sizeof(Matrix44f), (const GLvoid*) (4 * sizeof(GLfloat) * i) );
// get the next matrix after each instance, instead of each vertex
glVertexAttribDivisor( ulocation + i, 1 );
}
// fill the buffer with our data
mBuffer.bufferData( matrices.size() * sizeof(Matrix44f), &matrices.front(), GL_STATIC_READ );
mBuffer.unbind();
// unbind the VAO
glBindVertexArray(0);
}
}
示例8: createCube
TriMesh MeshHelper::createCube( const Vec3i &resolution )
{
vector<uint32_t> indices;
vector<Vec3f> normals;
vector<Vec3f> positions;
vector<Vec2f> texCoords;
ci::TriMesh front = createSquare( Vec2i( resolution.x, resolution.y ) );
ci::TriMesh left = createSquare( Vec2i( resolution.z, resolution.y ) );
ci::TriMesh top = createSquare( Vec2i( resolution.x, resolution.z ) );
Vec3f normal;
Vec3f offset;
Matrix44f transform;
// Back
normal = Vec3f( 0.0f, 0.0f, -1.0f );
offset = normal * 0.5f;
transform.setToIdentity();
transform.translate( offset );
for ( vector<Vec3f>::iterator iter = front.getVertices().begin(); iter != front.getVertices().end(); ++iter ) {
positions.push_back( transform.transformPoint( *iter ) );
normals.push_back( normal );
}
for ( vector<Vec2f>::iterator iter = front.getTexCoords().begin(); iter != front.getTexCoords().end(); ++iter ) {
texCoords.push_back( *iter );
}
// Bottom
normal = Vec3f( 0.0f, -1.0f, 0.0f );
offset = normal * 0.5f;
transform.setToIdentity();
transform.translate( offset );
transform.rotate( Vec3f( -(float)M_PI * 0.5f, 0.0f, 0.0f ) );
transform.translate( offset * -1.0f );
transform.translate( offset );
for ( vector<Vec3f>::iterator iter = top.getVertices().begin(); iter != top.getVertices().end(); ++iter ) {
positions.push_back( transform.transformPoint( *iter ) );
normals.push_back( normal );
}
for ( vector<Vec2f>::iterator iter = top.getTexCoords().begin(); iter != top.getTexCoords().end(); ++iter ) {
texCoords.push_back( *iter );
}
normal = Vec3f( 0.0f, 0.0f, 1.0f );
offset = normal * 0.5f;
transform.setToIdentity();
transform.translate( offset );
for ( vector<Vec3f>::iterator iter = front.getVertices().begin(); iter != front.getVertices().end(); ++iter ) {
positions.push_back( transform.transformPoint( *iter ) );
normals.push_back( normal );
}
for ( vector<Vec2f>::iterator iter = front.getTexCoords().begin(); iter != front.getTexCoords().end(); ++iter ) {
texCoords.push_back( *iter );
}
normal = Vec3f( -1.0f, 0.0f, 0.0f );
offset = normal * 0.5f;
transform.setToIdentity();
transform.translate( offset );
transform.rotate( Vec3f( 0.0f, -(float)M_PI * 0.5f, 0.0f ) );
transform.translate( offset * -1.0f );
transform.translate( offset );
for ( vector<Vec3f>::iterator iter = left.getVertices().begin(); iter != left.getVertices().end(); ++iter ) {
positions.push_back( transform.transformPoint( *iter ) );
normals.push_back( normal );
}
for ( vector<Vec2f>::iterator iter = left.getTexCoords().begin(); iter != left.getTexCoords().end(); ++iter ) {
texCoords.push_back( *iter );
}
// Right
normal = Vec3f( 1.0f, 0.0f, 0.0f );
offset = normal * 0.5f;
transform.setToIdentity();
transform.translate( offset );
transform.rotate( Vec3f( 0.0f, (float)M_PI * 0.5f, 0.0f ) );
transform.translate( offset * -1.0f );
transform.translate( offset );
for ( vector<Vec3f>::iterator iter = left.getVertices().begin(); iter != left.getVertices().end(); ++iter ) {
positions.push_back( transform.transformPoint( *iter ) );
normals.push_back( normal );
}
for ( vector<Vec2f>::iterator iter = left.getTexCoords().begin(); iter != left.getTexCoords().end(); ++iter ) {
texCoords.push_back( *iter );
}
normal = Vec3f( 0.0f, 1.0f, 0.0f );
offset = normal * 0.5f;
transform.setToIdentity();
transform.translate( offset );
transform.rotate( Vec3f( (float)M_PI * 0.5f, 0.0f, 0.0f ) );
transform.translate( offset * -1.0f );
transform.translate( offset );
for ( vector<Vec3f>::iterator iter = top.getVertices().begin(); iter != top.getVertices().end(); ++iter ) {
positions.push_back( transform.transformPoint( *iter ) );
normals.push_back( normal );
}
for ( vector<Vec2f>::iterator iter = top.getTexCoords().begin(); iter != top.getTexCoords().end(); ++iter ) {
texCoords.push_back( *iter );
//.........这里部分代码省略.........
示例9: ap
void SecondStudy::TheApp::draw() {
// clear out the window with black
gl::clear(ColorAf(0.0f, 0.0f, 0.0f, 1.0f));
gl::color(0.0f, 0.0f, 0.0f);
gl::drawSolidRect(getWindowBounds());
gl::color(1.0f, 1.0f, 1.0f, 1.0f);
glLineWidth(5.0f);
gl::pushModelView();
Matrix44f st;
//st.scale(Vec2f(_screenZoom, _screenZoom));
//st.translate(Vec3f(_screenOffset));
//gl::multModelView(st);
_sequencesMutex.lock();
for(auto& s : _sequences) {
if(s.size() > 1) {
for(auto it = s.begin(); it != prev(s.end()); ++it) {
shared_ptr<MeasureWidget> a = *it;
shared_ptr<MeasureWidget> b = *(next(it));
Matrix44f at;
at.translate(Vec3f(a->position()));
at.rotate(Vec3f(0.0f, 0.0f, a->angle()));
Matrix44f bt;
bt.translate(Vec3f(b->position()));
bt.rotate(Vec3f(0.0f, 0.0f, b->angle()));
Vec3f ap3 = at.transformPoint(Vec3f(a->outletIcon().getCenter()));
Vec3f bp3 = bt.transformPoint(Vec3f(b->inletIcon().getCenter()));
Vec2f ap(ap3.x, ap3.y);
Vec2f bp(bp3.x, bp3.y);
gl::drawLine(ap, bp);
}
}
}
_sequencesMutex.unlock();
_widgetsMutex.lock();
for(auto w : _widgets) {
w->draw();
}
_widgetsMutex.unlock();
gl::popModelView();
// Let's draw the traces as they are being created
_tracesMutex.lock();
_groupsMutex.lock();
for(int i = 0; i < _groups.size(); i++) {
for(auto trace : _groups[i]) {
if(trace->isVisible) {
gl::color(1.0f, 1.0f, 1.0f, 0.25f);
} else {
float c = (trace->lifespan() / 10.0f) * 0.25f;
gl::color(1.0f, 1.0f, 1.0f, c);
}
if(trace->touchPoints.size() > 1) {
for(auto cursorIt = trace->touchPoints.begin(); cursorIt != prev(trace->touchPoints.end()); ++cursorIt) {
Vec2f a = tuioToWindow(cursorIt->getPos());
Vec2f b = tuioToWindow(next(cursorIt)->getPos());
gl::lineWidth(2.0f);
gl::drawLine(a, b);
}
}
if(trace->isVisible) {
gl::drawSolidCircle(tuioToWindow(trace->currentPosition()), 8.0f);
gl::drawSolidCircle(tuioToWindow(trace->currentPosition()), 50.0f);
} else {
gl::drawSolidCircle(tuioToWindow(trace->currentPosition()), 4.0f);
}
}
}
_groupsMutex.unlock();
_tracesMutex.unlock();
}