本文整理汇总了C++中math::Vector3d::x方法的典型用法代码示例。如果您正苦于以下问题:C++ Vector3d::x方法的具体用法?C++ Vector3d::x怎么用?C++ Vector3d::x使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类math::Vector3d
的用法示例。
在下文中一共展示了Vector3d::x方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
void Lua_V2::WorldToScreen() {
lua_Object xObj = lua_getparam(1);
lua_Object yObj = lua_getparam(2);
lua_Object zObj = lua_getparam(3);
if (!lua_isnumber(xObj) || !lua_isnumber(yObj) || !lua_isnumber(zObj)) {
lua_pushnumber(0.0);
lua_pushnumber(0.0);
return;
}
float x = lua_getnumber(xObj);
float y = lua_getnumber(yObj);
float z = lua_getnumber(zObj);
Math::Vector3d pos = Math::Vector3d(x, y, z);
const Set::Setup *setup = g_emi->getCurrSet()->getCurrSetup();
const Math::Vector3d interest = setup->_interest;
const float roll = setup->_roll;
const Math::Quaternion quat = Math::Quaternion(interest.x(), interest.y(), interest.z(), roll);
Math::Matrix4 view = quat.toMatrix();
view.transpose();
pos -= setup->_pos;
pos = view.getRotation() * pos;
pos.z() = -pos.z();
Math::Matrix4 proj = GfxBase::makeProjMatrix(setup->_fov, setup->_nclip, setup->_fclip);
proj.transpose();
Math::Vector4d screen = proj * Math::Vector4d(pos.x(), pos.y(), pos.z(), 1.0);
screen /= screen.w();
lua_pushnumber((screen.x() + 1) * 320);
lua_pushnumber((1 - screen.y()) * 240);
}
示例2:
void TinyGLRenderer::drawTexturedRect3D(const Math::Vector3d &topLeft, const Math::Vector3d &bottomLeft,
const Math::Vector3d &topRight, const Math::Vector3d &bottomRight, Texture *texture) {
TinyGLTexture *glTexture = static_cast<TinyGLTexture *>(texture);
const float w = glTexture->width / (float)glTexture->internalWidth;
const float h = glTexture->height / (float)glTexture->internalHeight;
tglBlendFunc(TGL_SRC_ALPHA, TGL_ONE_MINUS_SRC_ALPHA);
tglEnable(TGL_BLEND);
tglDepthMask(TGL_FALSE);
tglBindTexture(TGL_TEXTURE_2D, glTexture->id);
tglBegin(TGL_TRIANGLE_STRIP);
tglTexCoord2f(0, 0);
tglVertex3f(-topLeft.x(), topLeft.y(), topLeft.z());
tglTexCoord2f(0, h);
tglVertex3f(-bottomLeft.x(), bottomLeft.y(), bottomLeft.z());
tglTexCoord2f(w, 0);
tglVertex3f(-topRight.x(), topRight.y(), topRight.z());
tglTexCoord2f(w, h);
tglVertex3f(-bottomRight.x(), bottomRight.y(), bottomRight.z());
tglEnd();
tglDisable(TGL_BLEND);
tglDepthMask(TGL_TRUE);
}
示例3: isPointInSector
bool Sector::isPointInSector(const Math::Vector3d &point) const {
// Calculate the distance of the point from the plane of the sector.
// Return false if it isn't within a margin.
if (_height < 9000.f) { // No need to check when height is 9999.
// The plane has equation ax + by + cz + d = 0
float a = _normal.x();
float b = _normal.y();
float c = _normal.z();
float d = -_vertices[0].x() * a - _vertices[0].y() * b - _vertices[0].z() * c;
float dist = (a * point.x() + b * point.y() + c * point.z() + d) /
sqrt(a * a + b * b + c * c);
// dist is positive if it is above the plain, negative if it is
// below and 0 if it is on the plane.
if (fabsf(dist) > _height + 0.01) // Add an error margin
return false;
}
// On the plane, so check if it is inside the polygon.
for (int i = 0; i < _numVertices; i++) {
Math::Vector3d edge = _vertices[i + 1] - _vertices[i];
Math::Vector3d delta = point - _vertices[i];
if (edge.x() * delta.y() < edge.y() * delta.x())
return false;
}
return true;
}
示例4: getCurrentCostume
Math::Vector3d Actor::getTangentPos(const Math::Vector3d &pos, const Math::Vector3d &dest) const {
if (_collisionMode == CollisionOff) {
return dest;
}
Model *model = getCurrentCostume()->getModel();
Math::Vector3d p = _pos + model->_insertOffset;
float size = model->_radius * _collisionScale;
Math::Vector2d p1(pos.x(), pos.y());
Math::Vector2d p2(dest.x(), dest.y());
Math::Segment2d segment(p1, p2);
// TODO: collision with Box
// if (_collisionMode == CollisionSphere) {
Math::Vector2d center(p.x(), p.y());
Math::Vector2d inter;
float distance = segment.getLine().getDistanceTo(center, &inter);
if (distance < size && segment.containsPoint(inter)) {
Math::Vector2d v(inter - center);
v.normalize();
v *= size;
v += center;
return Math::Vector3d(v.getX(), v.getY(), dest.z());
}
// } else {
// }
return dest;
}
示例5:
// Find the closest point on the walkplane to the given point
Math::Vector3d Sector::getClosestPoint(const Math::Vector3d &point) const {
// First try to project to the plane
Math::Vector3d p2 = point;
p2 -= (Math::Vector3d::dotProduct(_normal, p2 - _vertices[0])) * _normal;
if (isPointInSector(p2))
return p2;
// Now try to project to some edge
for (int i = 0; i < _numVertices; i++) {
Math::Vector3d edge = _vertices[i + 1] - _vertices[i];
Math::Vector3d delta = point - _vertices[i];
float scalar = Math::Vector3d::dotProduct(delta, edge) / Math::Vector3d::dotProduct(edge, edge);
if (scalar >= 0 && scalar <= 1 && delta.x() * edge.y() > delta.y() * edge.x())
// That last test is just whether the z-component
// of delta cross edge is positive; we don't
// want to return opposite edges.
return _vertices[i] + scalar * edge;
}
// Otherwise, just find the closest vertex
float minDist = (point - _vertices[0]).getMagnitude();
int index = 0;
for (int i = 1; i < _numVertices; i++) {
float currDist = (point - _vertices[i]).getMagnitude();
if (currDist < minDist) {
minDist = currDist;
index = i;
}
}
return _vertices[index];
}
示例6: sizeof
void ShaderRenderer::drawTexturedRect3D(const Math::Vector3d &topLeft, const Math::Vector3d &bottomLeft,
const Math::Vector3d &topRight, const Math::Vector3d &bottomRight, Texture *texture) {
OpenGLTexture *glTexture = static_cast<OpenGLTexture *>(texture);
const float w = glTexture->width / (float)glTexture->internalWidth;
const float h = glTexture->height / (float)glTexture->internalHeight;
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND);
glDepthMask(GL_FALSE);
glBindTexture(GL_TEXTURE_2D, glTexture->id);
const GLfloat vertices[] = {
// S T X Y Z
0, 0, -topLeft.x(), topLeft.y(), topLeft.z(),
0, h, -bottomLeft.x(), bottomLeft.y(), bottomLeft.z(),
w, 0, -topRight.x(), topRight.y(), topRight.z(),
w, h, -bottomRight.x(), bottomRight.y(), bottomRight.z(),
};
_rect3dShader->use();
_rect3dShader->setUniform1f("texScale", 1.0f);
_rect3dShader->setUniform("mvpMatrix", _mvpMatrix);
glBindBuffer(GL_ARRAY_BUFFER, _rect3dVBO);
glBufferSubData(GL_ARRAY_BUFFER, 0, 20 * sizeof(float), vertices);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
glDisable(GL_BLEND);
glDepthMask(GL_TRUE);
}
示例7: getYawTo
Math::Angle Actor::getYawTo(const Math::Vector3d &p) const {
Math::Vector3d dpos = p - _pos;
if (g_grim->getGameType() == GType_MONKEY4) {
dpos.y() = dpos.z();
}
if (dpos.x() == 0 && dpos.y() == 0)
return 0;
else
return Math::Angle::arcTangent2(-dpos.x(), dpos.y());
}
示例8: screenPosToDirection
void ShaderRenderer::screenPosToDirection(const Common::Point screen, float &pitch, float &heading) {
double x, y, z;
x = screen.x;
y = kOriginalHeight - screen.y;
z = 0.9f;
const Math::Vector2d tl = _viewport.getTopLeft();
x = 2 * double(x - tl.getX()) / _viewport.getWidth() - 1.0f;
y = 2 * double(y - tl.getY()) / _viewport.getHeight() - 1.0f;
z = 2 * z - 1.0f;
// Screen coords to 3D coords
Math::Vector4d point = Math::Vector4d(x, y, z, 1.0f);
point = _mvpMatrix * point;
// 3D coords to polar coords
Math::Vector3d v = Math::Vector3d(point.x(), point.y(), point.z());
v.normalize();
Math::Vector2d horizontalProjection = Math::Vector2d(v.x(), v.z());
horizontalProjection.normalize();
pitch = 90 - Math::Angle::arcCosine(v.y()).getDegrees();
heading = Math::Angle::arcCosine(horizontalProjection.getY()).getDegrees();
if (horizontalProjection.getX() > 0.0)
heading = 360 - heading;
}
示例9: getactor
void Lua_V2::GetActorPuckVector() {
lua_Object actorObj = lua_getparam(1);
lua_Object addObj = lua_getparam(2);
if (!lua_isuserdata(actorObj) || lua_tag(actorObj) != MKTAG('A','C','T','R')) {
lua_pushnil();
return;
}
Actor *actor = getactor(actorObj);
// Note: The wear chore of dumbshadow.cos is only started from Lua if
// GetActorPuckVector returns a non-nil value. The original engine seems
// to return nil for all actors that have never followed walkboxes.
if (!actor || !actor->hasFollowedBoxes()) {
lua_pushnil();
return;
}
Math::Vector3d result = actor->getPuckVector();
if (!lua_isnil(addObj))
result += actor->getPos();
lua_pushnumber(result.x());
lua_pushnumber(result.y());
lua_pushnumber(result.z());
}
示例10: shouldDrawShadow
bool Actor::shouldDrawShadow(int shadowId) {
Shadow *shadow = &_shadowArray[shadowId];
if (!shadow->active)
return false;
// Don't draw a shadow if the shadow caster and the actor are on different sides
// of the the shadow plane.
Sector *sector = shadow->planeList.front().sector;
Math::Vector3d n = sector->getNormal();
Math::Vector3d p = sector->getVertices()[0];
float d = -(n.x() * p.x() + n.y() * p.y() + n.z() * p.z());
p = getPos();
// Move the tested point a bit above ground level.
if (g_grim->getGameType() == GType_MONKEY4)
p.y() += 0.01;
else
p.z() += 0.01;
bool actorSide = n.x() * p.x() + n.y() * p.y() + n.z() * p.z() + d < 0.f;
p = shadow->pos;
bool shadowSide = n.x() * p.x() + n.y() * p.y() + n.z() * p.z() + d < 0.f;
if (actorSide == shadowSide)
return true;
return false;
}
示例11: distanceToPoint
float Sector::distanceToPoint(const Math::Vector3d &point) const {
// The plane has equation ax + by + cz + d = 0
float a = _normal.x();
float b = _normal.y();
float c = _normal.z();
float d = -_vertices[0].x() * a - _vertices[0].y() * b - _vertices[0].z() * c;
// dist is positive if it is above the plain, negative if it is
// below and 0 if it is on the plane.
float dist = (a * point.x() + b * point.y() + c * point.z() + d);
dist /= sqrt(a * a + b * b + c * c);
return dist;
}
示例12: isInside
bool Frustum::isInside(const Math::AABB &aabb) const {
Math::Vector3d min = aabb.getMin();
Math::Vector3d max = aabb.getMax();
for (int i = 0; i < 6; ++i) {
const Plane &plane = _planes[i];
Math::Vector3d positive = min;
if (plane._normal.x() >= 0.0f)
positive.x() = max.x();
if (plane._normal.y() >= 0.0f)
positive.y() = max.y();
if (plane._normal.z() >= 0.0f)
positive.z() = max.z();
float dist = _planes[i].getSignedDistance(positive);
if (dist < 0.0f)
return false;
}
return true;
}
示例13: isPointInside
bool FloorFace::isPointInside(const Math::Vector3d &point) const {
// Compute the barycentric coordinates of the point in the triangle
float area = 1.0 / 2.0
* (-_vertices[1].y() * _vertices[2].x()
+ _vertices[0].y() * (-_vertices[1].x() + _vertices[2].x())
+ _vertices[0].x() * (_vertices[1].y() - _vertices[2].y())
+ _vertices[1].x() * _vertices[2].y());
int32 sign = area < 0 ? -1 : 1;
float s = (_vertices[0].y() * _vertices[2].x() - _vertices[0].x() * _vertices[2].y()
+ (_vertices[2].y() - _vertices[0].y()) * point.x()
+ (_vertices[0].x() - _vertices[2].x()) * point.y())
* sign;
float t = (_vertices[0].x() * _vertices[1].y() - _vertices[0].y() * _vertices[1].x()
+ (_vertices[0].y() - _vertices[1].y()) * point.x()
+ (_vertices[1].x() - _vertices[0].x()) * point.y())
* sign;
// Check the coordinates are in the triangle
return s > 0 && t > 0 && (s + t) < 2.0 * area * sign;
}
示例14: computePointHeight
void FloorFace::computePointHeight(Math::Vector3d &point) const {
// Compute the barycentric coordinates of the point in the triangle
float area = 1.0 / 2.0
* (-_vertices[1].y() * _vertices[2].x()
+ _vertices[0].y() * (-_vertices[1].x() + _vertices[2].x())
+ _vertices[0].x() * (_vertices[1].y() - _vertices[2].y())
+ _vertices[1].x() * _vertices[2].y());
float s = (_vertices[0].y() * _vertices[2].x() - _vertices[0].x() * _vertices[2].y()
+ (_vertices[2].y() - _vertices[0].y()) * point.x()
+ (_vertices[0].x() - _vertices[2].x()) * point.y())
/ (2.0 * area);
float t = (_vertices[0].x() * _vertices[1].y() - _vertices[0].y() * _vertices[1].x()
+ (_vertices[0].y() - _vertices[1].y()) * point.x()
+ (_vertices[1].x() - _vertices[0].x()) * point.y())
/ (2.0 * area);
// Compute the Z coordinate of the point
float pointZ = (1.0 - s - t) * _vertices[0].z() + s * _vertices[1].z() + t * _vertices[2].z();
point.setValue(2, pointZ);
}
示例15: getExitInfo
void Sector::getExitInfo(const Math::Vector3d &s, const Math::Vector3d &dirVec, struct ExitInfo *result) const {
Math::Vector3d start = getProjectionToPlane(s);
Math::Vector3d dir = getProjectionToPuckVector(dirVec);
// First find the edge the ray exits through: this is where
// the z-component of (v_i - start) x dir changes sign from
// positive to negative.
// First find a vertex such that the cross product has
// positive z-component.
int i;
for (i = 0; i < _numVertices; i++) {
Math::Vector3d delta = _vertices[i] - start;
if (delta.x() * dir.y() > delta.y() * dir.x())
break;
}
// Now continue until the cross product has negative
// z-component.
while (i < _numVertices) {
i++;
Math::Vector3d delta = _vertices[i] - start;
if (delta.x() * dir.y() <= delta.y() * dir.x())
break;
}
result->edgeDir = _vertices[i] - _vertices[i - 1];
result->angleWithEdge = Math::Vector3d::angle(dir, result->edgeDir);
result->edgeVertex = i - 1;
Math::Vector3d edgeNormal(result->edgeDir.y(), -result->edgeDir.x(), 0);
float d = Math::Vector3d::dotProduct(dir, edgeNormal);
// This is 0 for the albinizod monster in the at set
if (!d)
d = 1.f;
result->exitPoint = start + (Math::Vector3d::dotProduct(_vertices[i] - start, edgeNormal) / d ) * dir;
}