本文整理汇总了C++中Vec4类的典型用法代码示例。如果您正苦于以下问题:C++ Vec4类的具体用法?C++ Vec4怎么用?C++ Vec4使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Vec4类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: setOpacity
void Marker::setOpacity(float opacity)
{
Vec4 color = _shapeDrawable->getColor();
color.set(color[0], color[1], color[2], opacity);
setColor(color);
}
示例2: VEC4_CONST
void FastClusterFit::Compress4( void* block )
{
Vec4 const one = VEC4_CONST(1.0f);
Vec4 const zero = VEC4_CONST(0.0f);
Vec4 const half = VEC4_CONST(0.5f);
Vec4 const two = VEC4_CONST(2.0);
Vec4 const onethird = VEC4_CONST( 1.0f/3.0f );
Vec4 const twothirds = VEC4_CONST( 2.0f/3.0f );
// declare variables
Vec4 beststart = VEC4_CONST( 0.0f );
Vec4 bestend = VEC4_CONST( 0.0f );
Vec4 besterror = VEC4_CONST( FLT_MAX );
Vec4 x0 = zero;
int b0 = 0, b1 = 0, b2 = 0;
int i = 0;
// check all possible clusters for this total order
for( int c0 = 0; c0 <= 16; c0++)
{
Vec4 x1 = zero;
for( int c1 = 0; c1 <= 16-c0; c1++)
{
Vec4 x2 = zero;
for( int c2 = 0; c2 <= 16-c0-c1; c2++)
{
Vec4 const constants = Vec4((const float *)&s_fourElement[i]);
Vec4 const alpha2_sum = constants.SplatX();
Vec4 const beta2_sum = constants.SplatY();
Vec4 const alphabeta_sum = constants.SplatZ();
Vec4 const factor = constants.SplatW();
i++;
Vec4 const alphax_sum = x0 + MultiplyAdd(x1, twothirds, x2 * onethird);
Vec4 const betax_sum = m_xsum - alphax_sum;
Vec4 a = NegativeMultiplySubtract(betax_sum, alphabeta_sum, alphax_sum*beta2_sum) * factor;
Vec4 b = NegativeMultiplySubtract(alphax_sum, alphabeta_sum, betax_sum*alpha2_sum) * factor;
// clamp the output to [0, 1]
a = Min( one, Max( zero, a ) );
b = Min( one, Max( zero, b ) );
// clamp to the grid
Vec4 const grid( 31.0f, 63.0f, 31.0f, 0.0f );
Vec4 const gridrcp( 0.03227752766457f, 0.01583151765563f, 0.03227752766457f, 0.0f );
a = Truncate( MultiplyAdd( grid, a, half ) ) * gridrcp;
b = Truncate( MultiplyAdd( grid, b, half ) ) * gridrcp;
// compute the error
Vec4 e1 = MultiplyAdd( a, alphax_sum, b*betax_sum );
Vec4 e2 = MultiplyAdd( a*a, alpha2_sum, b*b*beta2_sum );
Vec4 e3 = MultiplyAdd( a*b*alphabeta_sum - e1, two, e2 );
// apply the metric to the error term
Vec4 e4 = e3 * m_metricSqr;
Vec4 error = e4.SplatX() + e4.SplatY() + e4.SplatZ();
// keep the solution if it wins
if( CompareAnyLessThan( error, besterror ) )
{
besterror = error;
beststart = a;
bestend = b;
b0 = c0;
b1 = c1;
b2 = c2;
}
x2 += m_unweighted[c0+c1+c2];
}
x1 += m_unweighted[c0+c1];
}
x0 += m_unweighted[c0];
}
// save the block if necessary
if( CompareAnyLessThan( besterror, m_besterror ) )
{
// compute indices from cluster sizes.
/*uint bestindices = 0;
{
int i = b0;
for(; i < b0+b1; i++) {
bestindices = 2 << (2 * m_order[i]);
}
for(; i < b0+b1+b2; i++) {
bestindices = 3 << (2 * m_order[i]);
}
for(; i < 16; i++) {
bestindices = 1 << (2 * m_order[i]);
}
}*/
u8 bestindices[16];
{
//.........这里部分代码省略.........
示例3: saveObject
QString Cube::saveObject()
{
QString obj;
QString aux;
obj += "c ";
Vec4 parameters;
//translacao
parameters = transform.getTranslateSeted();
obj += aux.sprintf("%.3f %.3f %.3f ",parameters.x(),parameters.y(),parameters.z());
//escala
parameters = transform.getScaleSeted();
obj += aux.sprintf("%.3f %.3f %.3f ",parameters.x(),parameters.y(),parameters.z());
//rotação
parameters = transform.getRotationSeted();
obj += aux.sprintf("%.3f %.3f %.3f ",parameters.x(),parameters.y(),parameters.z());
obj += aux.sprintf("%d ",this->getIdMaterial());
parameters = this->getMesh()->getMaterialM()->getAmbiente();
obj += aux.sprintf("%.3f %.3f %.3f ",parameters.x(),parameters.y(),parameters.z());
parameters = this->getMesh()->getMaterialM()->getDiffuse();
obj += aux.sprintf("%.3f %.3f %.3f ",parameters.x(),parameters.y(),parameters.z());
parameters = this->getMesh()->getMaterialM()->getSpecular();
obj += aux.sprintf("%.3f %.3f %.3f ",parameters.x(),parameters.y(),parameters.z());
obj += aux.sprintf("%.3f ",this->getMesh()->getMaterialM()->getShininess());
obj += aux.sprintf("%.3f ",this->getMesh()->getMaterialM()->getReflection());
obj += aux.sprintf("%.3f ",this->getMesh()->getMaterialM()->getRefraction());
obj += aux.sprintf("%.3f %.3f ",this->getMesh()->getMaterialM()->getGlossyReflection(),this->getMesh()->getMaterialM()->getGlossyRefraction());
obj += aux.sprintf("%.3f %.3f %.3f ",motion.x(),motion.y(),motion.z());
if (this->enabled)
obj += "t ";
else
obj += "f ";
if (this->selected)
obj += "t ";
else
obj += "f ";
obj +=this->name+"\n";
return obj;
}
示例4: setVec4Parameter
void setVec4Parameter(const std::string name,
const Vec4 value,
bool isShaderConstant = true)
{ setColorParameter(name,
Color(value.x(), value.y(), value.z(), value.w()),
isShaderConstant); }
示例5: BuildJenga
void BuildJenga (osgViewer::Viewer* const viewer, osg::newtonWorld* const world, const Vec3& location, int high)
{
dAssert (viewer->getSceneData());
Group* const rootGroup = viewer->getSceneData()->asGroup();
dAssert (rootGroup);
Vec3 blockBoxSize (0.4f, 0.4f * 3.0f, 0.2f);
// find the floor position
Vec4 start(Vec4(location, 0.0f) + Vec4 (0.0f, 0.0f, 10.0f, 1.0f));
Vec4 end (start - Vec4 (0.0f, 0.0f, 20.0f, 1.0f));
newtonRayCast raycaster(world, DemoExample::m_rayCast);
raycaster.CastRay (start, end);
Vec4 position (raycaster.m_contact + Vec4 (0.0f, 0.0f, blockBoxSize.z() * 0.5f, 1.0f));
Matrix baseMatrix;
baseMatrix.setTrans (position.x(), position.y(), position.z());
// set realistic mass and inertia matrix for each block
dFloat mass = 5.0f;
// create a 90 degree rotation matrix
Matrix rotMatrix (Quat (90.0f * 3.141592f / 180.0f, Vec3 (0.0f, 0.0f, 1.0f)));
dFloat collisionPenetration = 1.0f / 256.0f;
// make a box collision shape
dNewtonCollisionBox boxShape (world, blockBoxSize.x(), blockBoxSize.y(), blockBoxSize.z(), DemoExample::m_all);
// create a visual for visual representation
newtonMesh boxMesh (&boxShape);
boxMesh.Triangulate();
// create a texture and apply uv to this mesh
ref_ptr<Texture2D> texture = new Texture2D;
ref_ptr<Image> image = osgDB::readImageFile("images\\crate.tga");
texture->setImage (image.get());
texture->setWrap(Texture::WRAP_S, Texture::REPEAT);
texture->setWrap(Texture::WRAP_R, Texture::REPEAT);
texture->setWrap(Texture::WRAP_T, Texture::REPEAT);
int materialId = boxMesh.AddMaterial(texture);
// apply uv to this mesh
boxMesh.ApplyBoxMapping (materialId, materialId, materialId);
// create a manual object for rendering
ref_ptr<Geode> geometryNode = boxMesh.CreateGeodeNode();
for (int i = 0; i < high; i ++) {
Matrix matrix(baseMatrix);
Vec3 step_x (Matrix::transform3x3 (Vec3(1.0f, 0.0f, 0.0f), matrix));
step_x = step_x * blockBoxSize.x();
matrix.setTrans (matrix.getTrans() - step_x);
for (int j = 0; j < 3; j ++) {
ref_ptr<MatrixTransform> transformNode = new MatrixTransform(matrix);
transformNode->addChild(geometryNode.get());
rootGroup->addChild(transformNode.get());
new newtonDynamicBody (world, mass, &boxShape, transformNode.get(), matrix);
matrix.setTrans (matrix.getTrans() + step_x);
}
baseMatrix = rotMatrix * baseMatrix;
Vec3 step_y (Matrix::transform3x3 (Vec3(0.0f, 0.0f, 1.0f), matrix));
step_y = step_y * (blockBoxSize.z() - collisionPenetration);
baseMatrix.setTrans (baseMatrix.getTrans() + step_y);
}
}
示例6: vConstants
//--------------------------------------------------------------------------------------
// The Taylor Series smooths and removes jitter based on a taylor series expansion
//--------------------------------------------------------------------------------------
void FilterTaylorSeries::Update( const SKinSkeletonRawData& pSkeletonData, const float fDeltaTime )
{
const float fJitterRadius = 0.05f;
const float fAlphaCoef = 1.0f - m_fSmoothing;
const float fBetaCoeff = (fAlphaCoef * fAlphaCoef ) / ( 2 - fAlphaCoef );
Vec4 vRawPos;
// Velocity, acceleration and Jolt are 1st, 2nd and 3rd degree derivatives of position respectively.
Vec4 vCurFilteredPos, vEstVelocity, vEstAccelaration, vEstJolt;
Vec4 vPrevFilteredPos, vPrevEstVelocity, vPrevEstAccelaration, vPrevEstJolt;
Vec4 vDiff;
float fDiff;
Vec4 vPredicted, vError;
Vec4 vConstants(0.0f, 1.0f, 0.5f, 0.1667f);
for (int i = 0; i < KIN_SKELETON_POSITION_COUNT; i++)
{
vRawPos = pSkeletonData.vSkeletonPositions[i];
vPrevFilteredPos = m_History[i].vPos;
vPrevEstVelocity = m_History[i].vEstVelocity;
vPrevEstAccelaration = m_History[i].vEstAccelaration;
vPrevEstJolt = m_History[i].vEstJolt;
if (!JointPositionIsValid(vPrevFilteredPos))
{
vCurFilteredPos = vRawPos;
vEstVelocity = Vec4(0,0,0,0);
vEstAccelaration = Vec4(0,0,0,0);
vEstJolt = Vec4(0,0,0,0);
}
else if (!JointPositionIsValid(vRawPos))
{
vCurFilteredPos = vPrevFilteredPos;
vEstVelocity = vPrevEstVelocity;
vEstAccelaration = vPrevEstAccelaration;
vEstJolt = vPrevEstJolt;
}
else
{
// If the current and previous frames have valid data, perform interpolation
vDiff = vPrevFilteredPos - vRawPos;
fDiff = fabs(vDiff.GetLength());
if (fDiff <= fJitterRadius)
{
vCurFilteredPos = vRawPos * fDiff/fJitterRadius + vPrevFilteredPos * (1.0f - fDiff/fJitterRadius);
}
else
{
vCurFilteredPos = vRawPos;
}
vPredicted = vPrevFilteredPos + vPrevEstVelocity;
vPredicted = vPredicted + vPrevEstAccelaration * (vConstants.y * vConstants.y * vConstants.z);
vPredicted = vPredicted + vPrevEstJolt * (vConstants.y * vConstants.y * vConstants.y * vConstants.w);
vError = vCurFilteredPos - vPredicted;
vCurFilteredPos = vPredicted + vError * fAlphaCoef;
vEstVelocity = vPrevEstVelocity + vError * fBetaCoeff;
vEstAccelaration = vEstVelocity - vPrevEstVelocity;
vEstJolt = vEstAccelaration - vPrevEstAccelaration;
}
// Update the state
m_History[i].vPos = vCurFilteredPos;
m_History[i].vEstVelocity = vEstVelocity;
m_History[i].vEstAccelaration = vEstAccelaration;
m_History[i].vEstJolt = vEstJolt;
// Output the data
m_FilteredJoints[i] = vCurFilteredPos;
m_FilteredJoints[i].w = 1.0f;
}
}
示例7: setPlane
//==============================================================================
static void setPlane(const Vec4& abcd, Plane& p)
{
Vec4 n = abcd.xyz0();
F32 len = n.getLength();
p = Plane(n / len, -abcd.w() / len);
}
示例8: direction
Vec4 SpotLight::calculateColor(Vec4 pit, Vec4 n,Vec4 viewer, Material *m,Vec4 pos,Vec4 texColor,int mode_texture)
{
if(mode_texture==TYPE_ONLY_TEXTURE){
Vec4 direction(direction_light->x1,direction_light->x2,direction_light->x3);
Vec4 position(position_light->x1,position_light->x2,position_light->x3);
Vec4 l = (position-pit)/(position-pit).module();
float fator = fmax((n*l)/(n.module()*l.module()),0);
Vec4 Diffuse;
Diffuse.x1 = (texColor.x() * diffuse_light->x1)*fator;
Diffuse.x2 = (texColor.y() * diffuse_light->x2)*fator;
Diffuse.x3 = (texColor.z() * diffuse_light->x3)*fator;
l = l.unitary();
Vec4 r = (n*((l*n)*2) - l);
Vec4 v = (viewer-pit)/(viewer-pit).module();
r = (r+v)/(r+v).module();
float fator2 = fmax(pow((r*v),m->shininess*128),0);
if(r*n<0) fator2 = 0;
Vec4 especular;
especular.x1 = (texColor.x() * specular_light->x1)*fator2;
especular.x2 = (texColor.y() * specular_light->x2)*fator2;
especular.x3 = (texColor.z() * specular_light->x3)*fator2;
Vec4 ambiente;
ambiente.x1 = texColor.x() * ambient_light->x1;
ambiente.x2 = texColor.y() * ambient_light->x2;
ambiente.x3 = texColor.z() * ambient_light->x3;
Vec4 color = ((Diffuse+especular))*isInDualConeSpot(pit)*pow(direction*(l*-1),expoent_light)*attenuation((position-viewer).module());
return color;
}else if(mode_texture==TYPE_REPLACE_TEXTURE){
Vec4 direction(direction_light->x1,direction_light->x2,direction_light->x3);
//calculo da contribuição difusa
Vec4 position(position_light->x1,position_light->x2,position_light->x3);
if ((position-pit).unitary()*n<=0) return Vec4();
//direction = (direction)/(direction).module();
Vec4 l = (position-pit)/(position-pit).module();
float fator = fmax((n*l)/(n.module()*l.module()),0);
Vec4 Diffuse;
Diffuse.x1 = (m->diffuse[0] * diffuse_light->x1)*fator;
Diffuse.x2 = (m->diffuse[1] * diffuse_light->x2)*fator;
Diffuse.x3 = (m->diffuse[2] * diffuse_light->x3)*fator;
//calculo da contribuicao especular
l = l.unitary();
Vec4 r = (n*((l*n)*2) - l);
Vec4 v = (viewer-pit)/(viewer-pit).module();
r = (r+v)/(r+v).module();
float fator2 = fmax(pow((r*v),m->shininess*128),0);
if(r*n<0) fator2 = 0;
Vec4 especular;
especular.x1 = (m->specular[0] * specular_light->x1)*fator2;
especular.x2 = (m->specular[1] * specular_light->x2)*fator2;
especular.x3 = (m->specular[2] * specular_light->x3)*fator2;
//calculo da contribuição ambiente
Vec4 ambiente;
ambiente.x1 = m->ambient[0] * ambient_light->x1;
ambiente.x2 = m->ambient[1] * ambient_light->x2;
ambiente.x3 = m->ambient[2] * ambient_light->x3;
Vec4 color = texColor.mult(((Diffuse+especular))*isInDualConeSpot(pit)*pow(direction*(l*-1),expoent_light)*attenuation((position-viewer).module()));
return color;
}else{
Vec4 direction(direction_light->x1,direction_light->x2,direction_light->x3);
//calculo da contribuição difusa
Vec4 position(position_light->x1,position_light->x2,position_light->x3);
if ((position-pit).unitary()*n<=0) return Vec4();
//direction = (direction)/(direction).module();
Vec4 l = (position-pit)/(position-pit).module();
float fator = fmax((n*l)/(n.module()*l.module()),0);
Vec4 Diffuse;
Diffuse.x1 = (m->diffuse[0] * diffuse_light->x1)*fator;
Diffuse.x2 = (m->diffuse[1] * diffuse_light->x2)*fator;
Diffuse.x3 = (m->diffuse[2] * diffuse_light->x3)*fator;
//calculo da contribuicao especular
l = l.unitary();
Vec4 r = (n*((l*n)*2) - l);
Vec4 v = (viewer-pit)/(viewer-pit).module();
r = (r+v)/(r+v).module();
float fator2 = fmax(pow((r*v),m->shininess*128),0);
if(r*n<0) fator2 = 0;
Vec4 especular;
especular.x1 = (m->specular[0] * specular_light->x1)*fator2;
especular.x2 = (m->specular[1] * specular_light->x2)*fator2;
especular.x3 = (m->specular[2] * specular_light->x3)*fator2;
//calculo da contribuição ambiente
Vec4 ambiente;
ambiente.x1 = m->ambient[0] * ambient_light->x1;
ambiente.x2 = m->ambient[1] * ambient_light->x2;
ambiente.x3 = m->ambient[2] * ambient_light->x3;
//.........这里部分代码省略.........
示例9: Vec4
void SpotLight::setPosition(Vec4 pos)
{
position_light = new Vec4(pos.x(),pos.y(),pos.z());
}
示例10: Vector
Vector(const Vec4& vector) :
detail::VectorType<4>(vector.x(), vector.y(), vector.z(), 0.0f)
{
}
示例11: getStartTime
//==============================================================================
void FollowPathEvent::update(F32 prevUpdateTime, F32 crntTime)
{
MoveComponent& move = movableSceneNode->getComponent<MoveComponent>();
I pointA = 0;
I pointB = 0;
// Calculate the current distance. Clamp it to max distance
F32 crntDistance = distPerTime * (crntTime - getStartTime());
ANKI_ASSERT(crntDistance >= 0.0);
crntDistance = std::min(crntDistance, path->getDistance());
const I pointsCount = path->getPoints().size();
ANKI_ASSERT(pointsCount > 1);
// Find the points that we lie between
for(I i = 1; i < pointsCount; i++)
{
const PathPoint& ppa = path->getPoints()[i - 1];
const PathPoint& ppb = path->getPoints()[i];
if(crntDistance > ppa.getDistanceFromFirst()
&& crntDistance <= ppb.getDistanceFromFirst())
{
pointA = i - 1;
pointB = i;
break;
}
}
ANKI_ASSERT(pointA < pointsCount && pointB < pointsCount);
I preA = std::max((I)0, pointA - 1);
I postB = std::min(pointsCount - 1, pointB + 1);
/*I pminus2 = std::max((I)0, pointA - 2);
I pminus1 = std::max((I)0, pointA - 1);*/
// Calculate the u [0.0, 1.0]
F32 u = path->getPoints()[pointB].getDistance() + getEpsilon<F32>();
ANKI_ASSERT(u != 0.0);
const F32 c = crntDistance
- path->getPoints()[pointA].getDistanceFromFirst();
u = c / u;
// Calculate and set new position and rotation for the movable
/*Vec3 newPos = cubicInterpolate(
path->getPoints()[preA].getPosition(),
path->getPoints()[pointA].getPosition(),
path->getPoints()[pointB].getPosition(),
path->getPoints()[postB].getPosition(),
u);*/
Vec3 newPos = interpolate(
path->getPoints()[pointA].getPosition(),
path->getPoints()[pointB].getPosition(),
u);
{
F32 u2 = u * u;
Vec4 us(1, u, u2, u2 * u);
F32 t = 0.7;
Mat4 tentionMat(
0.0, 1.0, 0.0, 0.0,
-t, 0.0, t, 0.0,
2.0 * t, t - 3.0, 3.0 - 2.0 * t, -t,
-t, 2.0 - t, t - 2.0, t);
Vec4 tmp = us * tentionMat;
Mat4 posMat;
posMat.setRows(
Vec4(path->getPoints()[preA].getPosition(), 1.0),
Vec4(path->getPoints()[pointA].getPosition(), 1.0),
Vec4(path->getPoints()[pointB].getPosition(), 1.0),
Vec4(path->getPoints()[postB].getPosition(), 1.0));
Vec4 finalPos = tmp * posMat;
newPos = finalPos.xyz();
}
Quat newRot = path->getPoints()[pointA].getRotation().slerp(
path->getPoints()[pointB].getRotation(),
u);
F32 scale = move.getLocalTransform().getScale();
Transform trf;
trf.setOrigin(newPos);
trf.setRotation(Mat3(newRot));
trf.setScale(scale);
move.setLocalTransform(trf);
}
示例12: DrawTrack
// This method needs to be broken up
void tcHookInfo::DrawTrack(long anID)
{
std::string s;
char zBuff[128];
float ftextx = 10.0f;
float ftexty = 22.0f;
UINT8 nOwnAlliance = mpUserInfo->GetOwnAlliance();
Vec4 color;
tcSensorMapTrack* pSMTrack = mpSS->mcSensorMap.GetSensorMapTrack(anID, nOwnAlliance);
if (pSMTrack == 0) return;
const tcTrack *pTrack = pSMTrack->GetTrack();
// classification
ClassificationToString(pTrack->mnClassification, zBuff);
strcat(zBuff, " track");
color.set(0.4f, 1.0f, 0.4f, 1.0f);
if (!pSMTrack->IsIdentified())
{
DrawTextR(zBuff, ftextx-2.0f, ftexty, defaultFont.get(),
color, fontSizeLarge, LEFT_BASE_LINE);
ftexty += 20.0f;
}
else // track is identified, look up class name
{
if (tcDatabaseObject* databaseObj = database->GetObject(pSMTrack->GetDatabaseId()))
{
s = databaseObj->GetDisplayName();
}
else // error, not found in database
{
s = "Error";
}
DrawTextR(s.c_str(), ftextx-2.0f, ftexty,
defaultFont.get(), color, fontSizeLarge, LEFT_BASE_LINE);
ftexty += 15.0f;
DrawTextR(zBuff, ftextx, ftexty,
defaultFont.get(), color, fontSize, LEFT_BASE_LINE);
ftexty += 20.0f;
}
// speed, heading, altitude, terrain info
s = "";
if (pTrack->mnFlags & TRACK_HEADING_VALID)
{
//if (heading_deg < 0) heading_deg += 360;
if (pTrack->mnFlags & TRACK_BEARING_ONLY)
{
int bearing_deg(C_180OVERPI*pTrack->bearing_rad + 0.5f);
bearing_deg = bearing_deg + int(bearing_deg < 0)*360;
sprintf(zBuff,"BRG %03d ", bearing_deg);
}
else
{
int heading_deg(C_180OVERPI*pTrack->mfHeading_rad + 0.5f);
heading_deg = heading_deg + int(heading_deg < 0)*360;
sprintf(zBuff,"HDG %03d ", heading_deg);
}
s += zBuff;
}
if (pTrack->mnFlags & TRACK_SPEED_VALID)
{
sprintf(zBuff," SPD %s ", units->GetUserSpeedString(pTrack->mfSpeed_kts));
s += zBuff;
}
if ((pTrack->mnClassification & (PTYPE_AIR | PTYPE_MISSILE))
&&(pTrack->mnFlags & TRACK_ALT_VALID))
{
sprintf(zBuff," ALT %s", units->GetUserAltitudeString(pTrack->mfAlt_m));
s += zBuff;
}
DrawTextR(s.c_str(), ftextx, ftexty, defaultFont.get(), color, fontSize, LEFT_BASE_LINE);
ftexty += 15;
// Draw reporting platform info
size_t nContributors = pSMTrack->GetContributorCount();
s = "Detected by: ";
for (size_t k=0; k<nContributors; k++)
{
s += std::string(pSMTrack->GetContributorName(k));
if (k < nContributors-1) s += ",";
}
if (s.size() > 35)
{
s = s.substr(0, 35);
}
DrawTextR(s.c_str(), ftextx, ftexty, defaultFont.get(), color, fontSize, LEFT_BASE_LINE);
ftexty += 15;
// Draw contact update time
double t = mpSS->GetTime();
//.........这里部分代码省略.........
示例13: DrawOwn
void tcHookInfo::DrawOwn(tcGameObject *pHookedObj)
{
std::string s;
char zBuff[128];
float ftextx = 10.0f;
float ftexty = 22.0f;
Vec4 color;
if (pHookedObj == NULL) {return;}
s = pHookedObj->mzUnit.c_str();
color.set(0.4f, 1.0f, 0.4f, 1.0f);
DrawTextR(s.c_str(), ftextx-2.0f, ftexty, defaultFont.get(), color, fontSizeLarge, LEFT_BASE_LINE,
180.0f);
ftexty += 20.0f;
sprintf(zBuff, "%s (id %d)", pHookedObj->GetDisplayClassName(), pHookedObj->mnID);
s = zBuff;
DrawTextR(s.c_str(), ftextx, ftexty, defaultFont.get(), color, fontSize, LEFT_BASE_LINE);
ftexty += 20.0f;
/*** mnClassID, mnModelType, mnType (classification) ***/
GetObjectInfo(s, pHookedObj->mpDBObject, pHookedObj);
DrawTextR(s.c_str(), ftextx, ftexty, defaultFont.get(), color, fontSize, LEFT_BASE_LINE);
ftexty += 15.0f;
// speed, heading, altitude, terrain info
tcKinematics *pkin = &pHookedObj->mcKin;
int heading_deg = int(C_180OVERPI*pkin->mfHeading_rad + 0.5f);
heading_deg = heading_deg + (int(heading_deg < 0) - int(heading_deg >= 360))*360;
sprintf(zBuff,"%s, hdg %03d, alt %s",
units->GetUserSpeedString(pkin->mfSpeed_kts), heading_deg,
units->GetUserAltitudeString(pkin->mfAlt_m));
s = zBuff;
DrawTextR(s.c_str(), ftextx, ftexty, defaultFont.get(), color, fontSize, LEFT_BASE_LINE);
ftexty += 15;
sprintf(zBuff, "Terrain %s", units->GetUserAltitudeString(pHookedObj->mcTerrain.mfHeight_m));
s = zBuff;
DrawTextR(s.c_str(), ftextx, ftexty, defaultFont.get(), color, fontSize, LEFT_BASE_LINE);
ftexty+=15;
// lat, lon
LonLatToStringB(C_180OVERPI*(float)pkin->mfLon_rad,C_180OVERPI*(float)pkin->mfLat_rad,s);
DrawTextR(s.c_str(), ftextx, ftexty, defaultFont.get(), color, fontSize, LEFT_BASE_LINE);
ftexty += 15;
/*** damage ***/
float damageLevelPercent = 100.0f * pHookedObj->GetDamageLevel();
if (damageLevelPercent > 100.0f) damageLevelPercent = 100.0f;
if (damageLevelPercent == 0)
{
strcpy(zBuff,"Damage: none");
}
else if (damageLevelPercent >= 50.0f)
{
color.set(1.0f, 0.4f, 0.4f, 1.0f);
sprintf(zBuff, "Damage: %2.0f%%", damageLevelPercent);
}
else
{
color.set(1.0f, 1.0f, 0.4f, 1.0f);
sprintf(zBuff, "Damage: %2.0f%%", damageLevelPercent);
}
s = zBuff;
DrawTextR(s.c_str(), ftextx, ftexty, defaultFont.get(), color, fontSize, LEFT_BASE_LINE);
ftexty += 15;
color.set(0.4f, 1.0f, 0.4f, 1.0f);
// multiplayer info
if (mpSS->IsMultiplayerActive())
{
const std::string& controller = pHookedObj->GetController();
if (controller.size())
{
s = "Controlled by ";
s += controller;
}
else
{
s = "No controller";
}
DrawTextR(s.c_str(), ftextx, ftexty, defaultFont.get(), color, fontSize, LEFT_BASE_LINE);
ftexty += 15;
color.set(0.4f, 1.0f, 0.4f, 1.0f);
}
// AI action text for platform objects
tcPlatformObject* pPlatformObj = dynamic_cast<tcPlatformObject*>(pHookedObj);
if (pPlatformObj != NULL)
//.........这里部分代码省略.........
示例14: Vec4
//--------------------------------------------------------------------------------------
// Name: CombiJointFilter()
// Desc: A filter for the positional data. This filter uses a combination of velocity
// position history to filter the joint positions.
//--------------------------------------------------------------------------------------
void FilterCombination::Update( const SKinSkeletonRawData& pSkeletonData, const float fDeltaTime )
{
// Process each joint
for ( uint32 nJoint = 0; nJoint < KIN_SKELETON_POSITION_COUNT; ++nJoint )
{
// Remember where the camera thinks this joint should be
m_History[ nJoint ].m_vWantedPos = pSkeletonData.vSkeletonPositions[ nJoint ];
Vec4 vDelta;
vDelta = m_History[ nJoint ].m_vWantedPos - m_History[ nJoint ].m_vLastWantedPos;
{
Vec4 vBlended;
// Calculate the vBlended value - could optimize this by remembering the running total and
// subtracting the oldest value and then adding the newest. Saves adding them all up on each frame.
vBlended = Vec4(0,0,0,0);
for( uint32 k = 0; k < m_nUseTaps; ++k)
{
vBlended = vBlended + m_History[ nJoint ].m_vPrevDeltas[k];
}
vBlended = vBlended / ((float)m_nUseTaps);
vBlended.w = 0.0f;
vDelta.w = 0.0f;
float fDeltaLength = vDelta.GetLength();
float fBlendedLength = vBlended.GetLength();
m_History[ nJoint ].m_fWantedLocalBlendRate = m_fDefaultApplyRate;
m_History[ nJoint ].m_bActive[0] = false;
m_History[ nJoint ].m_bActive[1] = false;
m_History[ nJoint ].m_bActive[2] = false;
// Does the current velocity and history have a reasonable magnitude?
if( fDeltaLength >= m_fDeltaLengthThreshold &&
fBlendedLength >= m_fBlendedLengthThreshold )
{
float fDotProd;
float fConfidence;
if( m_bDotProdNormalize )
{
Vec4 vDeltaOne = vDelta;
vDeltaOne.Normalize();
Vec4 vBlendedOne = vBlended;
vBlendedOne.Normalize();
fDotProd = vDeltaOne.Dot( vBlendedOne );
}
else
{
fDotProd = vDelta.Dot(vBlended);
}
// Is the current frame aligned to the recent history?
if( fDotProd >= m_fDotProdThreshold )
{
fConfidence = fDotProd;
m_History[ nJoint ].m_fWantedLocalBlendRate = min( fConfidence, 1.0f );
m_History[ nJoint ].m_bActive[0] = true;
}
}
assert( m_History[ nJoint ].m_fWantedLocalBlendRate <= 1.0f );
}
// Push the previous deltas down the history
for( int j = m_nUseTaps-2; j >= 0; --j )
{
m_History[ nJoint ].m_vPrevDeltas[j+1] = m_History[ nJoint ].m_vPrevDeltas[j];
}
// Store the current history
m_History[ nJoint ].m_vPrevDeltas[0] = vDelta;
// Remember where the camera thought this joint was on the this frame
m_History[ nJoint ].m_vLastWantedPos = m_History[ nJoint ].m_vWantedPos;
}
// Secondary and tertiary blending
for ( uint32 pass = 0; pass < 2; ++pass )
{
for ( uint32 bone = 0; bone < g_numBones; ++bone )
{
float fRate1;
float fRate2;
fRate1 = m_History[ g_Bones[bone].startJoint ].m_fWantedLocalBlendRate;
fRate2 = m_History[ g_Bones[bone].endJoint ].m_fWantedLocalBlendRate;
// Blend down? Start to end
if( (fRate1 * m_fDownBlendRate) > fRate2)
{
// Yes, apply
m_History[ g_Bones[bone].endJoint ].m_fWantedLocalBlendRate = ( fRate1 * m_fDownBlendRate );
//.........这里部分代码省略.........
示例15: JointPositionIsValid
void FilterDoubleExponential::Update( const SKinSkeletonRawData& pSkeletonData, uint32 i, const KIN_TRANSFORM_SMOOTH_PARAMETERS& smoothingParams )
{
Vec4 vPrevRawPosition;
Vec4 vPrevFilteredPosition;
Vec4 vPrevTrend;
Vec4 vRawPosition;
Vec4 vFilteredPosition;
Vec4 vPredictedPosition;
Vec4 vDiff;
Vec4 vTrend;
Vec4 vLength;
float fDiff;
BOOL bJointIsValid;
const Vec4* __restrict pJointPositions = pSkeletonData.vSkeletonPositions;
vRawPosition = pJointPositions[i];
vPrevFilteredPosition = m_History[i].m_vFilteredPosition;
vPrevTrend = m_History[i].m_vTrend;
vPrevRawPosition = m_History[i].m_vRawPosition;
bJointIsValid = JointPositionIsValid(vRawPosition);
// If joint is invalid, reset the filter
if (!bJointIsValid)
{
m_History[i].m_dwFrameCount = 0;
}
// Initial start values
if (m_History[i].m_dwFrameCount == 0)
{
vFilteredPosition = vRawPosition;
vTrend = Vec4(0,0,0,0);
m_History[i].m_dwFrameCount++;
}
else if (m_History[i].m_dwFrameCount == 1)
{
vFilteredPosition = (vRawPosition + vPrevRawPosition) * 0.5f;
vDiff = vFilteredPosition - vPrevFilteredPosition;
vTrend = (vDiff * smoothingParams.m_fCorrection) + (vPrevTrend * (1.0f - smoothingParams.m_fCorrection));
m_History[i].m_dwFrameCount++;
}
else
{
// First apply jitter filter
vDiff = vRawPosition - vPrevFilteredPosition;
fDiff = fabs(vDiff.GetLength());
if (fDiff <= smoothingParams.m_fJitterRadius)
{
vFilteredPosition = vRawPosition * (fDiff/smoothingParams.m_fJitterRadius) + vPrevFilteredPosition * (1.0f - fDiff/smoothingParams.m_fJitterRadius);
}
else
{
vFilteredPosition = vRawPosition;
}
// Now the double exponential smoothing filter
vFilteredPosition = vFilteredPosition * (1.0f - smoothingParams.m_fSmoothing) + (vPrevFilteredPosition + vPrevTrend) * smoothingParams.m_fSmoothing;
vDiff = vFilteredPosition - vPrevFilteredPosition;
vTrend = vDiff * smoothingParams.m_fCorrection + vPrevTrend * (1.0f - smoothingParams.m_fCorrection);
}
// Predict into the future to reduce latency
vPredictedPosition = vFilteredPosition + (vTrend * smoothingParams.m_fPrediction);
// Check that we are not too far away from raw data
vDiff = vPredictedPosition - vRawPosition;
fDiff = fabs(vDiff.GetLength());
if (fDiff > smoothingParams.m_fMaxDeviationRadius)
{
vPredictedPosition = vPredictedPosition * smoothingParams.m_fMaxDeviationRadius/fDiff + vRawPosition * (1.0f - smoothingParams.m_fMaxDeviationRadius/fDiff);
}
// Save the data from this frame
m_History[i].m_vRawPosition = vRawPosition;
m_History[i].m_vFilteredPosition = vFilteredPosition;
m_History[i].m_vTrend = vTrend;
// Output the data
m_FilteredJoints[i] = vPredictedPosition;
m_FilteredJoints[i].w = 1.0f;
}