本文整理汇总了C++中Matrix4类的典型用法代码示例。如果您正苦于以下问题:C++ Matrix4类的具体用法?C++ Matrix4怎么用?C++ Matrix4使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Matrix4类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: toMatrix
Vector3d Quaternion::directionVector(const int col) const {
Matrix4 dirMat = toMatrix();
return Vector3d(dirMat.getValue(0, col), dirMat.getValue(1, col), dirMat.getValue(2, col));
}
示例2: SetAttribute
bool XMLElement::SetMatrix4(const ea::string& name, const Matrix4& value)
{
return SetAttribute(name, value.ToString());
}
示例3: memcpy
void Matrix4::load(const Matrix4& v) {
memcpy(data, v.data, sizeof(data));
mType = v.getType();
}
示例4:
Matrix4 operator*(Matrix4 left, const Matrix4& right) {
return left.Multiply(right);
}
示例5: Vector4
void DisCOVERay::renderRect(const vistle::Matrix4 &P, const vistle::Matrix4 &MV, const IceTInt *viewport,
int width, int height, unsigned char *rgba, float *depth) {
//StopWatch timer("DisCOVERay::render()");
#if 0
CERR << "IceT draw CB: vp=" << viewport[0] << ", " << viewport[1] << ", " << viewport[2] << ", " << viewport[3]
<< ", img: " << width << "x" << height
<< std::endl;
#endif
const int w = viewport[2];
const int h = viewport[3];
const int ts = m_tilesize;
const int wt = ((w+ts-1)/ts)*ts;
const int ht = ((h+ts-1)/ts)*ts;
const int ntx = wt/ts;
const int nty = ht/ts;
//CERR << "PROJ:" << P << std::endl << std::endl;
const vistle::Matrix4 MVP = P * MV;
const auto inv = MVP.inverse();
const Vector4 ro4 = MV.inverse().col(3);
const Vector ro = ro4.block<3,1>(0,0)/ro4[3];
const Vector4 lbn4 = inv * Vector4(-1, -1, -1, 1);
Vector lbn(lbn4[0], lbn4[1], lbn4[2]);
lbn /= lbn4[3];
const Vector4 lbf4 = inv * Vector4(-1, -1, 1, 1);
Vector lbf(lbf4[0], lbf4[1], lbf4[2]);
lbf /= lbf4[3];
const Vector4 rbn4 = inv * Vector4(1, -1, -1, 1);
Vector rbn(rbn4[0], rbn4[1], rbn4[2]);
rbn /= rbn4[3];
const Vector4 ltn4 = inv * Vector4(-1, 1, -1, 1);
Vector ltn(ltn4[0], ltn4[1], ltn4[2]);
ltn /= ltn4[3];
const Scalar tFar = (lbf-ro).norm()/(lbn-ro).norm();
const Matrix4 depthTransform = MVP;
TileTask renderTile(*this, m_renderManager.viewData(m_currentView));
renderTile.rgba = rgba;
renderTile.depth = depth;
renderTile.depthTransform2 = depthTransform.row(2);
renderTile.depthTransform3 = depthTransform.row(3);
renderTile.ntx = ntx;
renderTile.xoff = viewport[0];
renderTile.yoff = viewport[1];
renderTile.xlim = viewport[0] + viewport[2];
renderTile.ylim = viewport[1] + viewport[3];
renderTile.imgWidth = width;
renderTile.imgHeight = height;
renderTile.dx = (rbn-lbn)/renderTile.imgWidth;
renderTile.dy = (ltn-lbn)/renderTile.imgHeight;
renderTile.lowerBottom = lbn + 0.5*renderTile.dx + 0.5*renderTile.dy;
renderTile.origin = ro;
renderTile.tNear = 1.;
renderTile.tFar = tFar;
renderTile.modelView = MV;
#ifdef USE_TBB
tbb::parallel_for(0, ntx*nty, 1, renderTile);
#else
#pragma omp parallel for schedule(dynamic)
for (int t=0; t<ntx*nty; ++t) {
renderTile(t);
}
#endif
#if 0
std::vector<std::future<void>> tiles;
for (int t=0; t<ntx*nty; ++t) {
TileTask renderTile(*this, t);
renderTile.rgba = rgba;
renderTile.depth = depth;
renderTile.depthTransform = depthTransform;
renderTile.ntx = ntx;
renderTile.xoff = x0;
renderTile.yoff = y0;
renderTile.width = x1;
renderTile.height = y1;
renderTile.dx = (rbn-lbn)/w;
renderTile.dy = (ltn-lbn)/h;
renderTile.lowerBottom = lbn + 0.5*renderTile.dx + 0.5*renderTile.dy;
renderTile.tNear = 1.;
renderTile.tFar = zFar/zNear;
tiles.emplace_back(std::async(std::launch::async, renderTile));
}
for (auto &task: tiles) {
task.get();
}
#endif
//.........这里部分代码省略.........
示例6: GlobalBrushCreator
scene::INodePtr BrushDef3Parser::parse(parser::DefTokeniser& tok) const
{
// Create a new brush
scene::INodePtr node = GlobalBrushCreator().createBrush();
// Cast the node, this must succeed
IBrushNodePtr brushNode = boost::dynamic_pointer_cast<IBrushNode>(node);
assert(brushNode != NULL);
IBrush& brush = brushNode->getIBrush();
tok.assertNextToken("{");
// Parse face tokens until a closing brace is encountered
while (1)
{
std::string token = tok.nextToken();
// Token should be either a "(" (start of face) or "}" (end of brush)
if (token == "}")
{
break; // end of brush
}
else if (token == "(") // FACE
{
// Construct a plane and parse its values
Plane3 plane;
plane.normal().x() = string::to_float(tok.nextToken());
plane.normal().y() = string::to_float(tok.nextToken());
plane.normal().z() = string::to_float(tok.nextToken());
plane.dist() = -string::to_float(tok.nextToken()); // negate d
tok.assertNextToken(")");
// Parse TexDef
Matrix4 texdef;
tok.assertNextToken("(");
tok.assertNextToken("(");
texdef.xx() = string::to_float(tok.nextToken());
texdef.yx() = string::to_float(tok.nextToken());
texdef.tx() = string::to_float(tok.nextToken());
tok.assertNextToken(")");
tok.assertNextToken("(");
texdef.xy() = string::to_float(tok.nextToken());
texdef.yy() = string::to_float(tok.nextToken());
texdef.ty() = string::to_float(tok.nextToken());
tok.assertNextToken(")");
tok.assertNextToken(")");
// Parse Shader
std::string shader = tok.nextToken();
// Parse Flags (usually each brush has all faces detail or all faces structural)
IBrush::DetailFlag flag = static_cast<IBrush::DetailFlag>(
string::convert<std::size_t>(tok.nextToken(), IBrush::Structural));
brush.setDetailFlag(flag);
// Ignore the other two flags
tok.skipTokens(2);
// Finally, add the new face to the brush
/*IFace& face = */brush.addFace(plane, texdef, shader);
}
else {
std::string text = (boost::format(_("BrushDef3Parser: invalid token '%s'")) % token).str();
throw parser::ParseException(text);
}
}
// Final outer "}"
tok.assertNextToken("}");
return node;
}
示例7: glEnable
//----------------------------------------------------------------------------
// Callback method called by GLUT when window readraw is necessary or when glutPostRedisplay() was called.
void Window::displayCallback()
{
glEnable(GL_LIGHT0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // clear color and depth buffers
glColor3f(0, 0, 1);
//Setting moving camera
Matrix4 glmatrix;
if (cam) {
if (t == 99) {
back = true;
}
if (t == 0)
back = false;
Vector3 upd = belzCamera.upd;
belzCamera.set(points[t], Vector3(0,0,0), upd);
std::cout << t << std::endl;
}
if (altCam) {
glmatrix = belzCamera.getInverse();
}
else {
glmatrix = camera.getInverse();
}
//Drawing Light Source
Matrix4 temp;
temp.makeTranslate(position[0], position[1], position[2]);
setMatrix(glmatrix, temp);
glColor3f(1, 1, 0);
glutSolidSphere(.5, 100, 100);
setMatrix(glmatrix);
glLightfv(GL_LIGHT0, GL_POSITION, position);
//glLightfv(GL_LIGHT0, GL_AMBIENT, ambient);
/*
//Seting main objects
glColor3d(1, 0, 0);
setMatrix(glmatrix, object.getMatrix());
glutSolidCube(2);
temp.makeTranslate(3, 1.5, 0);
setMatrix(glmatrix, temp);
glColor3d(1, 0, 1);
glutSolidCube(3);
temp.makeTranslate(0, 1.5, 3);
setMatrix(glmatrix, temp);
glColor3d(0, 1, 1);
glutSolidCube(3);
temp.makeTranslate(0, 1.5, -3);
setMatrix(glmatrix, temp);
glColor3d(1, 1, 0);
glutSolidCube(3);
temp.makeTranslate(-3, 1.5, 0);
setMatrix(glmatrix, temp);
glColor3d(1, 1, 1);
glutSolidCube(3);
//Setting Floor
setMatrix(glmatrix);
glBegin(GL_QUADS);
glNormal3d(0, 1, 0);
glColor3d(0.5, 0.6, 0.7);
glVertex3d(-10, 0, -10);
glVertex3d(-10, 0, 10);
glVertex3d(10, 0, 10);
glVertex3d(10, 0, -10);
glEnd();*/
setMatrix(glmatrix);
if (light) {
Globals::shader->bind();
}
else
Globals::shader->unbind();
glutSolidTeapot(5);
plane.animate();
plane.draw();
Globals::shader->unbind();
//Drawing Bezier Curve
glBegin(GL_LINE_STRIP);
for (int i = 0; i < 99; i++) {
Vector3 current = points[i];
Vector3 next = points[i + 1];
glLineWidth(2.5);
glColor3f(1.0, 1.0, 0.0);
glVertex3d(current.getX(), current.getY(), current.getZ());
glVertex3d(next.getX(), next.getY(), next.getZ());
}
glEnd();
//Drawing Head
glActiveTexture(GL_TEXTURE0);
temp = glmatrix;
control.set(person.getMatrix());
character.draw(temp, light);
//Drawing Camera
setMatrix(glmatrix, cameraObject.getMatrix());
glColor3f(0, 1, 1);
//.........这里部分代码省略.........
示例8: glMatrixMode
//----------------------------------------------------------------------------
// Callback method called by GLUT when users press specific keys on the keyboard
void Window::keyboardCallback(unsigned char key, int xn, int yn) {
glMatrixMode(GL_PROJECTION);
Matrix4 temp;
switch (key) {
case'q':
person.rotateY(5);
temp.makeRotateY(5);
ahead = temp * ahead;
side = temp * side;
camera.rotateDirectionY(5);
break;
case'Q':
person.rotateY(5);
break;
case'e':
person.rotateY(-5);
temp.makeRotateY(-5);
ahead = temp * ahead;
side = temp * side;
camera.rotateDirectionY(-5);
break;
case'E':
person.rotateY(-5);
break;
case 'z':
camera.moveUp(1);
break;
case 'Z':
camera.moveDown(1);
break;
case 'w':
walk = true;
person.move(ahead.get(0), ahead.get(1), ahead.get(2));
camera.move(Vector3(ahead.get(0),ahead.get(1),ahead.get(2)),1);
break;
case's':
walk = true;
person.move(-ahead.get(0), -ahead.get(1), -ahead.get(2));
camera.move(Vector3(-ahead.get(0), -ahead.get(1), -ahead.get(2)), 1);
break;
case 'a':
person.move(side.get(0), side.get(1), side.get(2));
camera.move(Vector3(side.get(0), side.get(1), side.get(2)), 1);
break;
case 'd':
person.move(-side.get(0), -side.get(1), -side.get(2));
camera.move(Vector3(-side.get(0), -side.get(1), -side.get(2)), 1);
break;
case 'i':
camera.moveForward(1);
break;
case'k':
camera.moveBackward(1);
break;
case 'j':
camera.moveLeft(1);
break;
case 'l':
camera.moveRight(1);
break;
case 'r':
t = 0;
cameraObject.set(initial.get(0), initial.get(1), initial.get(2));
object.reset();
object.move(0, 1, 0);
belzCamera.set(points[0], belzD, belzUp);
person.reset();
camera.set(e, d, up);
ahead = Vector4(0, 0, -1, 0);
side = Vector4(-1, 0, 0, 0);
break;
case 'p':
cam = !cam;
break;
case'o':
altCam = !altCam;
break;
case'+':
t++;
if (t == 100)
t = 99;
break;
case'-':
t--;
if (t == 0)
t = 1;
break;
case'.':
automatic = !automatic;
break;
case'/':
light = !light;
break;
}
glMatrixMode(GL_MODELVIEW);
}
示例9: ASSERT_MATRIX_EQ
/// test equaility of two matrices
void ASSERT_MATRIX_EQ(const Matrix4& m1, const Matrix4& m2)
{
ASSERT_FLOAT_EQ(m1.get(0,0), m2.get(0,0));
ASSERT_FLOAT_EQ(m1.get(0,1), m2.get(0,1));
ASSERT_FLOAT_EQ(m1.get(0,2), m2.get(0,2));
ASSERT_FLOAT_EQ(m1.get(0,3), m2.get(0,3));
ASSERT_FLOAT_EQ(m1.get(1,0), m2.get(1,0));
ASSERT_FLOAT_EQ(m1.get(1,1), m2.get(1,1));
ASSERT_FLOAT_EQ(m1.get(1,2), m2.get(1,2));
ASSERT_FLOAT_EQ(m1.get(1,3), m2.get(1,3));
ASSERT_FLOAT_EQ(m1.get(2,0), m2.get(2,0));
ASSERT_FLOAT_EQ(m1.get(2,1), m2.get(2,1));
ASSERT_FLOAT_EQ(m1.get(2,2), m2.get(2,2));
ASSERT_FLOAT_EQ(m1.get(2,3), m2.get(2,3));
ASSERT_FLOAT_EQ(m1.get(3,0), m2.get(3,0));
ASSERT_FLOAT_EQ(m1.get(3,1), m2.get(3,1));
ASSERT_FLOAT_EQ(m1.get(3,2), m2.get(3,2));
ASSERT_FLOAT_EQ(m1.get(3,3), m2.get(3,3));
}
示例10: glClear
//----------------------------------------------------------------------------
// Callback method called by GLUT when window readraw is necessary or when glutPostRedisplay() was called.
void Window::displayCallback()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // clear color and depth buffers
glMatrixMode(GL_MODELVIEW); // make sure we're in Modelview mode
// Tell OpenGL what ModelView matrix to use:
Matrix4 glmatrix;
glmatrix = Globals::cube.getMatrix();
glmatrix.transpose();
glLoadMatrixd(glmatrix.getPointer());
// Draw all six faces of the cube:
glBegin(GL_QUADS);
glColor3f(1.0, 0.0, 0.0); // This makes the cube green; the parameters are for red, green and blue.
// To change the color of the other faces you will need to repeat this call before each face is drawn.
// Draw front face:
glNormal3f(0.0, 0.0, 1.0);
glVertex3f(-5.0, 5.0, 5.0);
glVertex3f( 5.0, 5.0, 5.0);
glVertex3f( 5.0, -5.0, 5.0);
glVertex3f(-5.0, -5.0, 5.0);
// Draw left side:
glNormal3f(-1.0, 0.0, 0.0);
glVertex3f(-5.0, 5.0, 5.0);
glVertex3f(-5.0, 5.0, -5.0);
glVertex3f(-5.0, -5.0, -5.0);
glVertex3f(-5.0, -5.0, 5.0);
// Draw right side:
glNormal3f(1.0, 0.0, 0.0);
glVertex3f( 5.0, 5.0, 5.0);
glVertex3f( 5.0, 5.0, -5.0);
glVertex3f( 5.0, -5.0, -5.0);
glVertex3f( 5.0, -5.0, 5.0);
// Draw back face:
glNormal3f(0.0, 0.0, -1.0);
glVertex3f(-5.0, 5.0, -5.0);
glVertex3f( 5.0, 5.0, -5.0);
glVertex3f( 5.0, -5.0, -5.0);
glVertex3f(-5.0, -5.0, -5.0);
// Draw top side:
glNormal3f(0.0, 1.0, 0.0);
glVertex3f(-5.0, 5.0, 5.0);
glVertex3f( 5.0, 5.0, 5.0);
glVertex3f( 5.0, 5.0, -5.0);
glVertex3f(-5.0, 5.0, -5.0);
// Draw bottom side:
glNormal3f(0.0, -1.0, 0.0);
glVertex3f(-5.0, -5.0, -5.0);
glVertex3f( 5.0, -5.0, -5.0);
glVertex3f( 5.0, -5.0, 5.0);
glVertex3f(-5.0, -5.0, 5.0);
glEnd();
glFlush();
glutSwapBuffers();
}
示例11: sendProjectionMatrix
// takes a projection matrix and send to the the shaders
static void sendProjectionMatrix(const ShaderState& curSS, const Matrix4& projMatrix) {
GLfloat glmatrix[16];
projMatrix.writeToColumnMajorMatrix(glmatrix); // send projection matrix
safe_glUniformMatrix4fv(curSS.h_uProjMatrix, glmatrix);
}
示例12: fromMatrix
Quaternion::Quaternion(const Matrix4 &m) {
fromMatrix(m.getRotation());
}
示例13: glUniformMatrix4fv
void Lighting::SetWorldMatrix(const Matrix4& WorldInverse)
{
glUniformMatrix4fv(m_WorldMatrixLocation, 1, GL_FALSE, (const GLfloat*)WorldInverse.Begin());
}
示例14: Entity
void Skeleton::loadSkeleton(const String& fileName) {
OSFILE *inFile = OSBasics::open(fileName.c_str(), "rb");
if(!inFile) {
return;
}
bonesEntity = new Entity();
bonesEntity->visible = false;
addChild(bonesEntity);
unsigned int numBones;
float t[3],rq[4],s[3];
OSBasics::read(&numBones, sizeof(unsigned int), 1, inFile);
unsigned int namelen;
char buffer[1024];
Matrix4 mat;
unsigned int hasParent, boneID;
for(int i=0; i < numBones; i++) {
OSBasics::read(&namelen, sizeof(unsigned int), 1, inFile);
memset(buffer, 0, 1024);
OSBasics::read(buffer, 1, namelen, inFile);
Bone *newBone = new Bone(String(buffer));
OSBasics::read(&hasParent, sizeof(unsigned int), 1, inFile);
if(hasParent == 1) {
OSBasics::read(&boneID, sizeof(unsigned int), 1, inFile);
newBone->parentBoneId = boneID;
} else {
newBone->parentBoneId = -1;
}
OSBasics::read(t, sizeof(float), 3, inFile);
OSBasics::read(s, sizeof(float), 3, inFile);
OSBasics::read(rq, sizeof(float), 4, inFile);
bones.push_back(newBone);
Quaternion bq;
bq.set(rq[0], rq[1], rq[2], rq[3]);
newBone->baseRotation = bq;
newBone->baseScale = Vector3(s[0], s[1], s[2]);
newBone->basePosition = Vector3(t[0], t[1], t[2]);
newBone->setPosition(t[0], t[1], t[2]);
newBone->setRotationQuat(rq[0], rq[1], rq[2], rq[3]);
newBone->setScale(s[0], s[1], s[2]);
newBone->rebuildTransformMatrix();
newBone->setBaseMatrix(newBone->getTransformMatrix());
newBone->setBoneMatrix(newBone->getTransformMatrix());
OSBasics::read(t, sizeof(float), 3, inFile);
OSBasics::read(s, sizeof(float), 3, inFile);
OSBasics::read(rq, sizeof(float), 4, inFile);
Quaternion q;
q.set(rq[0], rq[1], rq[2], rq[3]);
Matrix4 m = q.createMatrix();
m.setPosition(t[0], t[1], t[2]);
newBone->setRestMatrix(m);
}
Bone *parentBone;
for(int i=0; i < bones.size(); i++) {
if(bones[i]->parentBoneId != -1) {
parentBone = bones[bones[i]->parentBoneId];
parentBone->addChildBone(bones[i]);
bones[i]->setParentBone(parentBone);
parentBone->addChild(bones[i]);
} else {
bonesEntity->addChild(bones[i]);
}
}
OSBasics::close(inFile);
}
示例15: loadCharacter
void Window::loadCharacter() {
Matrix4 temp;
Matrix4 id;
id.identity();
//Setting up Controller
temp.makeTranslate(0, 0, 10);
control = MatrixTransform(temp);
//Setting up Head
headCube = Cube(2);
headCube.setTexture(head);
headRotation = MatrixTransform(id);
headScaling = MatrixTransform(id);
temp.makeTranslate(0, 7, 0);
headTranslation = MatrixTransform(temp);
headRotation.addChild(&headCube);
headScaling.addChild(&headRotation);
headTranslation.addChild(&headScaling);
control.addChild(&headTranslation);
//Setting up body
bodyCube = Cube(1);
bodyCube.setTexture(body);
bodyRotation = MatrixTransform(id);
temp.makeScale(2, 3, 1);
bodyScaling = MatrixTransform(temp);
temp.makeTranslate(0, 4.5, 0);
bodyTranslation = MatrixTransform(temp);
bodyRotation.addChild(&bodyCube);
bodyScaling.addChild(&bodyRotation);
bodyTranslation.addChild(&bodyScaling);
control.addChild(&bodyTranslation);
//Setting up Arms
armCube = Cube(1);
armCube.setTexture(arm);
leftArmRotation = MatrixTransform(id);
rightArmRotation = MatrixTransform(id);
temp.makeScale(1, 3, 1);
leftArmScaling = MatrixTransform(temp);
rightArmScaling = MatrixTransform(temp);
temp.makeTranslate(1.5, 4.5, 0);
leftArmTranslation = MatrixTransform(temp);
temp.makeTranslate(-(1.5), 4.5, 0);
rightArmTranslation = MatrixTransform(temp);
leftArmScaling.addChild(&armCube);
rightArmScaling.addChild(&armCube);
leftArmRotation.addChild(&leftArmScaling);
rightArmRotation.addChild(&rightArmScaling);
leftArmTranslation.addChild(&leftArmRotation);
rightArmTranslation.addChild(&rightArmRotation);
control.addChild(&leftArmTranslation);
control.addChild(&rightArmTranslation);
//Setting up Legs
legCube = Cube(1);
legCube.setTexture(leg);
leftLegRotation = MatrixTransform(id);
rightLegRotation = MatrixTransform(id);
temp.makeScale(1, 3, 1);
leftLegScaling = MatrixTransform(temp);
rightLegScaling = MatrixTransform(temp);
temp.makeTranslate(.5, 1.5, 0);
leftLegTranslation = MatrixTransform(temp);
temp.makeTranslate(-.5, 1.5, 0);
rightLegTranslation = MatrixTransform(temp);
leftLegScaling.addChild(&legCube);
rightLegScaling.addChild(&legCube);
leftLegRotation.addChild(&leftLegScaling);
rightLegRotation.addChild(&rightLegScaling);
leftLegTranslation.addChild(&leftLegRotation);
rightLegTranslation.addChild(&rightLegRotation);
control.addChild(&leftLegTranslation);
control.addChild(&rightLegTranslation);
character.addChild(&control);
}