Merge branch 'master' into physics3d-material
This commit is contained in:
@@ -8,11 +8,11 @@
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
Constraint2D::Constraint2D(PhysWorld2D& world, cpConstraint* constraint) :
|
||||
Constraint2D::Constraint2D(Nz::PhysWorld2D* world, cpConstraint* constraint) :
|
||||
m_constraint(constraint)
|
||||
{
|
||||
cpConstraintSetUserData(m_constraint, this);
|
||||
cpSpaceAddConstraint(world.GetHandle(), m_constraint);
|
||||
cpSpaceAddConstraint(world->GetHandle(), m_constraint);
|
||||
}
|
||||
|
||||
Constraint2D::Constraint2D(Constraint2D&& rhs) :
|
||||
@@ -105,320 +105,319 @@ namespace Nz
|
||||
}
|
||||
|
||||
|
||||
DampedSpring2D::DampedSpring2D(PhysWorld2D& world, RigidBody2D& first, const Vector2f& firstAnchor, RigidBody2D& second, const Vector2f& secondAnchor, float restLength, float stiffness, float damping) :
|
||||
Constraint2D(world, cpDampedSpringNew(first.GetHandle(), second.GetHandle(), cpv(firstAnchor.x, firstAnchor.y), cpv(secondAnchor.x, secondAnchor.y), restLength, stiffness, damping))
|
||||
DampedSpringConstraint2D::DampedSpringConstraint2D(RigidBody2D& first, RigidBody2D& second, const Vector2f& firstAnchor, const Vector2f& secondAnchor, float restLength, float stiffness, float damping) :
|
||||
Constraint2D(first.GetWorld(), cpDampedSpringNew(first.GetHandle(), second.GetHandle(), cpv(firstAnchor.x, firstAnchor.y), cpv(secondAnchor.x, secondAnchor.y), restLength, stiffness, damping))
|
||||
{
|
||||
}
|
||||
|
||||
float DampedSpring2D::GetDamping() const
|
||||
float DampedSpringConstraint2D::GetDamping() const
|
||||
{
|
||||
return float(cpDampedSpringGetDamping(m_constraint));
|
||||
}
|
||||
|
||||
Vector2f DampedSpring2D::GetFirstAnchor() const
|
||||
Vector2f DampedSpringConstraint2D::GetFirstAnchor() const
|
||||
{
|
||||
cpVect anchor = cpDampedSpringGetAnchorA(m_constraint);
|
||||
return Vector2f(static_cast<float>(anchor.x), static_cast<float>(anchor.y));
|
||||
}
|
||||
|
||||
float DampedSpring2D::GetRestLength() const
|
||||
float DampedSpringConstraint2D::GetRestLength() const
|
||||
{
|
||||
return float(cpDampedSpringGetRestLength(m_constraint));
|
||||
}
|
||||
|
||||
Vector2f DampedSpring2D::GetSecondAnchor() const
|
||||
Vector2f DampedSpringConstraint2D::GetSecondAnchor() const
|
||||
{
|
||||
cpVect anchor = cpDampedSpringGetAnchorB(m_constraint);
|
||||
return Vector2f(static_cast<float>(anchor.x), static_cast<float>(anchor.y));
|
||||
}
|
||||
|
||||
float DampedSpring2D::GetStiffness() const
|
||||
float DampedSpringConstraint2D::GetStiffness() const
|
||||
{
|
||||
return float(cpDampedSpringGetStiffness(m_constraint));
|
||||
}
|
||||
|
||||
void DampedSpring2D::SetDamping(float newDamping)
|
||||
void DampedSpringConstraint2D::SetDamping(float newDamping)
|
||||
{
|
||||
cpDampedSpringSetDamping(m_constraint, newDamping);
|
||||
}
|
||||
|
||||
void DampedSpring2D::SetFirstAnchor(const Vector2f& firstAnchor)
|
||||
void DampedSpringConstraint2D::SetFirstAnchor(const Vector2f& firstAnchor)
|
||||
{
|
||||
cpDampedSpringSetAnchorA(m_constraint, cpv(firstAnchor.x, firstAnchor.y));
|
||||
}
|
||||
|
||||
void DampedSpring2D::SetRestLength(float newLength)
|
||||
void DampedSpringConstraint2D::SetRestLength(float newLength)
|
||||
{
|
||||
cpDampedSpringSetRestLength(m_constraint, newLength);
|
||||
}
|
||||
|
||||
void DampedSpring2D::SetSecondAnchor(const Vector2f& firstAnchor)
|
||||
void DampedSpringConstraint2D::SetSecondAnchor(const Vector2f& firstAnchor)
|
||||
{
|
||||
cpDampedSpringSetAnchorB(m_constraint, cpv(firstAnchor.x, firstAnchor.y));
|
||||
}
|
||||
|
||||
void DampedSpring2D::SetStiffness(float newStiffness)
|
||||
void DampedSpringConstraint2D::SetStiffness(float newStiffness)
|
||||
{
|
||||
cpDampedSpringSetStiffness(m_constraint, newStiffness);
|
||||
}
|
||||
|
||||
|
||||
DampedRotarySpring2D::DampedRotarySpring2D(PhysWorld2D& world, RigidBody2D& first, RigidBody2D& second, float restAngle, float stiffness, float damping) :
|
||||
Constraint2D(world, cpDampedRotarySpringNew(first.GetHandle(), second.GetHandle(), restAngle, stiffness, damping))
|
||||
DampedRotarySpringConstraint2D::DampedRotarySpringConstraint2D(RigidBody2D& first, RigidBody2D& second, float restAngle, float stiffness, float damping) :
|
||||
Constraint2D(first.GetWorld(), cpDampedRotarySpringNew(first.GetHandle(), second.GetHandle(), restAngle, stiffness, damping))
|
||||
{
|
||||
}
|
||||
|
||||
float DampedRotarySpring2D::GetDamping() const
|
||||
float DampedRotarySpringConstraint2D::GetDamping() const
|
||||
{
|
||||
return float(cpDampedRotarySpringGetDamping(m_constraint));
|
||||
}
|
||||
|
||||
float DampedRotarySpring2D::GetRestAngle() const
|
||||
float DampedRotarySpringConstraint2D::GetRestAngle() const
|
||||
{
|
||||
return float(cpDampedRotarySpringGetRestAngle(m_constraint));
|
||||
}
|
||||
|
||||
float DampedRotarySpring2D::GetStiffness() const
|
||||
float DampedRotarySpringConstraint2D::GetStiffness() const
|
||||
{
|
||||
return float(cpDampedRotarySpringGetStiffness(m_constraint));
|
||||
}
|
||||
|
||||
void DampedRotarySpring2D::SetDamping(float newDamping)
|
||||
void DampedRotarySpringConstraint2D::SetDamping(float newDamping)
|
||||
{
|
||||
cpDampedSpringSetDamping(m_constraint, newDamping);
|
||||
}
|
||||
|
||||
void DampedRotarySpring2D::SetRestAngle(float newAngle)
|
||||
void DampedRotarySpringConstraint2D::SetRestAngle(float newAngle)
|
||||
{
|
||||
cpDampedRotarySpringSetRestAngle(m_constraint, newAngle);
|
||||
}
|
||||
|
||||
void DampedRotarySpring2D::SetStiffness(float newStiffness)
|
||||
void DampedRotarySpringConstraint2D::SetStiffness(float newStiffness)
|
||||
{
|
||||
cpDampedRotarySpringSetStiffness(m_constraint, newStiffness);
|
||||
}
|
||||
|
||||
|
||||
GearJoint2D::GearJoint2D(PhysWorld2D& world, RigidBody2D& first, RigidBody2D& second, float phase, float ratio) :
|
||||
Constraint2D(world, cpGearJointNew(first.GetHandle(), second.GetHandle(), phase, ratio))
|
||||
GearConstraint2D::GearConstraint2D(RigidBody2D& first, RigidBody2D& second, float phase, float ratio) :
|
||||
Constraint2D(first.GetWorld(), cpGearJointNew(first.GetHandle(), second.GetHandle(), phase, ratio))
|
||||
{
|
||||
}
|
||||
|
||||
float GearJoint2D::GetPhase() const
|
||||
float GearConstraint2D::GetPhase() const
|
||||
{
|
||||
return float(cpGearJointGetPhase(m_constraint));
|
||||
}
|
||||
|
||||
float GearJoint2D::GetRatio() const
|
||||
float GearConstraint2D::GetRatio() const
|
||||
{
|
||||
return float(cpGearJointGetRatio(m_constraint));
|
||||
}
|
||||
|
||||
void GearJoint2D::SetPhase(float phase)
|
||||
void GearConstraint2D::SetPhase(float phase)
|
||||
{
|
||||
cpGearJointSetPhase(m_constraint, phase);
|
||||
}
|
||||
|
||||
void GearJoint2D::SetRatio(float ratio)
|
||||
void GearConstraint2D::SetRatio(float ratio)
|
||||
{
|
||||
cpGearJointSetRatio(m_constraint, ratio);
|
||||
}
|
||||
|
||||
|
||||
MotorJoint2D::MotorJoint2D(PhysWorld2D& world, RigidBody2D& first, RigidBody2D& second, float rate) :
|
||||
Constraint2D(world, cpSimpleMotorNew(first.GetHandle(), second.GetHandle(), rate))
|
||||
MotorConstraint2D::MotorConstraint2D(RigidBody2D& first, RigidBody2D& second, float rate) :
|
||||
Constraint2D(first.GetWorld(), cpSimpleMotorNew(first.GetHandle(), second.GetHandle(), rate))
|
||||
{
|
||||
}
|
||||
|
||||
float MotorJoint2D::GetRate() const
|
||||
float MotorConstraint2D::GetRate() const
|
||||
{
|
||||
return float(cpSimpleMotorGetRate(m_constraint));
|
||||
}
|
||||
|
||||
void MotorJoint2D::SetRate(float rate)
|
||||
void MotorConstraint2D::SetRate(float rate)
|
||||
{
|
||||
cpSimpleMotorSetRate(m_constraint, rate);
|
||||
}
|
||||
|
||||
|
||||
PinJoint2D::PinJoint2D(PhysWorld2D& world, RigidBody2D& first, const Vector2f& firstAnchor, RigidBody2D& second, const Vector2f& secondAnchor) :
|
||||
Constraint2D(world, cpPinJointNew(first.GetHandle(), second.GetHandle(), cpv(firstAnchor.x, firstAnchor.y), cpv(secondAnchor.x, secondAnchor.y)))
|
||||
PinConstraint2D::PinConstraint2D(RigidBody2D& first, RigidBody2D& second, const Vector2f& firstAnchor, const Vector2f& secondAnchor) :
|
||||
Constraint2D(first.GetWorld(), cpPinJointNew(first.GetHandle(), second.GetHandle(), cpv(firstAnchor.x, firstAnchor.y), cpv(secondAnchor.x, secondAnchor.y)))
|
||||
{
|
||||
}
|
||||
|
||||
float PinJoint2D::GetDistance() const
|
||||
float PinConstraint2D::GetDistance() const
|
||||
{
|
||||
return float(cpPinJointGetDist(m_constraint));
|
||||
}
|
||||
|
||||
Vector2f PinJoint2D::GetFirstAnchor() const
|
||||
Vector2f PinConstraint2D::GetFirstAnchor() const
|
||||
{
|
||||
cpVect anchor = cpPinJointGetAnchorA(m_constraint);
|
||||
return Vector2f(static_cast<float>(anchor.x), static_cast<float>(anchor.y));
|
||||
}
|
||||
|
||||
Vector2f PinJoint2D::GetSecondAnchor() const
|
||||
Vector2f PinConstraint2D::GetSecondAnchor() const
|
||||
{
|
||||
cpVect anchor = cpPinJointGetAnchorB(m_constraint);
|
||||
return Vector2f(static_cast<float>(anchor.x), static_cast<float>(anchor.y));
|
||||
}
|
||||
|
||||
void PinJoint2D::SetDistance(float newDistance)
|
||||
void PinConstraint2D::SetDistance(float newDistance)
|
||||
{
|
||||
cpPinJointSetDist(m_constraint, newDistance);
|
||||
}
|
||||
|
||||
void PinJoint2D::SetFirstAnchor(const Vector2f& firstAnchor)
|
||||
void PinConstraint2D::SetFirstAnchor(const Vector2f& firstAnchor)
|
||||
{
|
||||
cpPinJointSetAnchorA(m_constraint, cpv(firstAnchor.x, firstAnchor.y));
|
||||
}
|
||||
|
||||
void PinJoint2D::SetSecondAnchor(const Vector2f& firstAnchor)
|
||||
void PinConstraint2D::SetSecondAnchor(const Vector2f& firstAnchor)
|
||||
{
|
||||
cpPinJointSetAnchorB(m_constraint, cpv(firstAnchor.x, firstAnchor.y));
|
||||
}
|
||||
|
||||
|
||||
PivotJoint2D::PivotJoint2D(PhysWorld2D& world, RigidBody2D& first, RigidBody2D& second, const Vector2f& anchor) :
|
||||
Constraint2D(world, cpPivotJointNew(first.GetHandle(), second.GetHandle(), cpv(anchor.x, anchor.y)))
|
||||
PivotConstraint2D::PivotConstraint2D(RigidBody2D& first, RigidBody2D& second, const Vector2f& anchor) :
|
||||
Constraint2D(first.GetWorld(), cpPivotJointNew(first.GetHandle(), second.GetHandle(), cpv(anchor.x, anchor.y)))
|
||||
{
|
||||
}
|
||||
|
||||
PivotJoint2D::PivotJoint2D(PhysWorld2D& world, RigidBody2D& first, const Vector2f& firstAnchor, RigidBody2D& second, const Vector2f& secondAnchor) :
|
||||
Constraint2D(world, cpPivotJointNew2(first.GetHandle(), second.GetHandle(), cpv(firstAnchor.x, firstAnchor.y), cpv(secondAnchor.x, secondAnchor.y)))
|
||||
PivotConstraint2D::PivotConstraint2D(RigidBody2D& first, RigidBody2D& second, const Vector2f& firstAnchor, const Vector2f& secondAnchor) :
|
||||
Constraint2D(first.GetWorld(), cpPivotJointNew2(first.GetHandle(), second.GetHandle(), cpv(firstAnchor.x, firstAnchor.y), cpv(secondAnchor.x, secondAnchor.y)))
|
||||
{
|
||||
}
|
||||
|
||||
Vector2f PivotJoint2D::GetFirstAnchor() const
|
||||
Vector2f PivotConstraint2D::GetFirstAnchor() const
|
||||
{
|
||||
cpVect anchor = cpPivotJointGetAnchorA(m_constraint);
|
||||
return Vector2f(static_cast<float>(anchor.x), static_cast<float>(anchor.y));
|
||||
}
|
||||
|
||||
Vector2f PivotJoint2D::GetSecondAnchor() const
|
||||
Vector2f PivotConstraint2D::GetSecondAnchor() const
|
||||
{
|
||||
cpVect anchor = cpPivotJointGetAnchorB(m_constraint);
|
||||
return Vector2f(static_cast<float>(anchor.x), static_cast<float>(anchor.y));
|
||||
}
|
||||
|
||||
void PivotJoint2D::SetFirstAnchor(const Vector2f& firstAnchor)
|
||||
void PivotConstraint2D::SetFirstAnchor(const Vector2f& firstAnchor)
|
||||
{
|
||||
cpPivotJointSetAnchorA(m_constraint, cpv(firstAnchor.x, firstAnchor.y));
|
||||
}
|
||||
|
||||
void PivotJoint2D::SetSecondAnchor(const Vector2f& firstAnchor)
|
||||
void PivotConstraint2D::SetSecondAnchor(const Vector2f& firstAnchor)
|
||||
{
|
||||
cpPivotJointSetAnchorB(m_constraint, cpv(firstAnchor.x, firstAnchor.y));
|
||||
}
|
||||
|
||||
|
||||
RatchetJoint2D::RatchetJoint2D(PhysWorld2D& world, RigidBody2D& first, RigidBody2D& second, float phase, float ratchet) :
|
||||
Constraint2D(world, cpRatchetJointNew(first.GetHandle(), second.GetHandle(), phase, ratchet))
|
||||
RatchetConstraint2D::RatchetConstraint2D(RigidBody2D& first, RigidBody2D& second, float phase, float ratchet) :
|
||||
Constraint2D(first.GetWorld(), cpRatchetJointNew(first.GetHandle(), second.GetHandle(), phase, ratchet))
|
||||
{
|
||||
}
|
||||
|
||||
float RatchetJoint2D::GetAngle() const
|
||||
float RatchetConstraint2D::GetAngle() const
|
||||
{
|
||||
return float(cpRatchetJointGetAngle(m_constraint));
|
||||
}
|
||||
|
||||
float RatchetJoint2D::GetPhase() const
|
||||
float RatchetConstraint2D::GetPhase() const
|
||||
{
|
||||
return float(cpRatchetJointGetPhase(m_constraint));
|
||||
}
|
||||
|
||||
float RatchetJoint2D::GetRatchet() const
|
||||
float RatchetConstraint2D::GetRatchet() const
|
||||
{
|
||||
return float(cpRatchetJointGetRatchet(m_constraint));
|
||||
}
|
||||
|
||||
void RatchetJoint2D::SetAngle(float angle)
|
||||
void RatchetConstraint2D::SetAngle(float angle)
|
||||
{
|
||||
cpRatchetJointSetAngle(m_constraint, angle);
|
||||
}
|
||||
|
||||
void RatchetJoint2D::SetPhase(float phase)
|
||||
void RatchetConstraint2D::SetPhase(float phase)
|
||||
{
|
||||
cpRatchetJointSetPhase(m_constraint, phase);
|
||||
}
|
||||
|
||||
void RatchetJoint2D::SetRatchet(float ratchet)
|
||||
void RatchetConstraint2D::SetRatchet(float ratchet)
|
||||
{
|
||||
cpRatchetJointSetRatchet(m_constraint, ratchet);
|
||||
}
|
||||
|
||||
|
||||
RotaryLimitJoint2D::RotaryLimitJoint2D(PhysWorld2D& world, RigidBody2D& first, RigidBody2D& second, float minAngle, float maxAngle) :
|
||||
Constraint2D(world, cpRotaryLimitJointNew(first.GetHandle(), second.GetHandle(), minAngle, maxAngle))
|
||||
RotaryLimitConstraint2D::RotaryLimitConstraint2D(RigidBody2D& first, RigidBody2D& second, float minAngle, float maxAngle) :
|
||||
Constraint2D(first.GetWorld(), cpRotaryLimitJointNew(first.GetHandle(), second.GetHandle(), minAngle, maxAngle))
|
||||
{
|
||||
}
|
||||
|
||||
float RotaryLimitJoint2D::GetMaxAngle() const
|
||||
float RotaryLimitConstraint2D::GetMaxAngle() const
|
||||
{
|
||||
return float(cpRotaryLimitJointGetMax(m_constraint));
|
||||
}
|
||||
|
||||
float RotaryLimitJoint2D::GetMinAngle() const
|
||||
float RotaryLimitConstraint2D::GetMinAngle() const
|
||||
{
|
||||
return float(cpRotaryLimitJointGetMax(m_constraint));
|
||||
}
|
||||
|
||||
void RotaryLimitJoint2D::SetMaxAngle(float maxAngle)
|
||||
void RotaryLimitConstraint2D::SetMaxAngle(float maxAngle)
|
||||
{
|
||||
cpRotaryLimitJointSetMax(m_constraint, maxAngle);
|
||||
}
|
||||
|
||||
void RotaryLimitJoint2D::SetMinAngle(float minAngle)
|
||||
void RotaryLimitConstraint2D::SetMinAngle(float minAngle)
|
||||
{
|
||||
cpRotaryLimitJointSetMin(m_constraint, minAngle);
|
||||
}
|
||||
|
||||
|
||||
SlideJoint2D::SlideJoint2D(PhysWorld2D& world, RigidBody2D& first, const Vector2f& firstAnchor, RigidBody2D& second, const Vector2f& secondAnchor, float min, float max) :
|
||||
Constraint2D(world, cpSlideJointNew(first.GetHandle(), second.GetHandle(), cpv(firstAnchor.x, firstAnchor.y), cpv(secondAnchor.x, secondAnchor.y), min, max))
|
||||
SlideConstraint2D::SlideConstraint2D(RigidBody2D& first, RigidBody2D& second, const Vector2f& firstAnchor, const Vector2f& secondAnchor, float min, float max) :
|
||||
Constraint2D(first.GetWorld(), cpSlideJointNew(first.GetHandle(), second.GetHandle(), cpv(firstAnchor.x, firstAnchor.y), cpv(secondAnchor.x, secondAnchor.y), min, max))
|
||||
{
|
||||
}
|
||||
|
||||
Vector2f SlideJoint2D::GetFirstAnchor() const
|
||||
Vector2f SlideConstraint2D::GetFirstAnchor() const
|
||||
{
|
||||
cpVect anchor = cpSlideJointGetAnchorA(m_constraint);
|
||||
return Vector2f(static_cast<float>(anchor.x), static_cast<float>(anchor.y));
|
||||
}
|
||||
|
||||
float SlideJoint2D::GetMaxDistance() const
|
||||
float SlideConstraint2D::GetMaxDistance() const
|
||||
{
|
||||
return float(cpSlideJointGetMax(m_constraint));
|
||||
}
|
||||
|
||||
float SlideJoint2D::GetMinDistance() const
|
||||
float SlideConstraint2D::GetMinDistance() const
|
||||
{
|
||||
return float(cpSlideJointGetMin(m_constraint));
|
||||
}
|
||||
|
||||
Vector2f SlideJoint2D::GetSecondAnchor() const
|
||||
Vector2f SlideConstraint2D::GetSecondAnchor() const
|
||||
{
|
||||
cpVect anchor = cpSlideJointGetAnchorB(m_constraint);
|
||||
return Vector2f(static_cast<float>(anchor.x), static_cast<float>(anchor.y));
|
||||
}
|
||||
|
||||
void SlideJoint2D::SetFirstAnchor(const Vector2f& firstAnchor)
|
||||
void SlideConstraint2D::SetFirstAnchor(const Vector2f& firstAnchor)
|
||||
{
|
||||
cpSlideJointSetAnchorA(m_constraint, cpv(firstAnchor.x, firstAnchor.y));
|
||||
}
|
||||
|
||||
void SlideJoint2D::SetMaxDistance(float newMaxDistance)
|
||||
void SlideConstraint2D::SetMaxDistance(float newMaxDistance)
|
||||
{
|
||||
cpSlideJointSetMax(m_constraint, newMaxDistance);
|
||||
}
|
||||
|
||||
void SlideJoint2D::SetMinDistance(float newMinDistance)
|
||||
void SlideConstraint2D::SetMinDistance(float newMinDistance)
|
||||
{
|
||||
cpSlideJointSetMin(m_constraint, newMinDistance);
|
||||
}
|
||||
|
||||
void SlideJoint2D::SetSecondAnchor(const Vector2f& firstAnchor)
|
||||
void SlideConstraint2D::SetSecondAnchor(const Vector2f& firstAnchor)
|
||||
{
|
||||
cpSlideJointSetAnchorB(m_constraint, cpv(firstAnchor.x, firstAnchor.y));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -227,35 +227,41 @@ namespace Nz
|
||||
|
||||
if (p < 0)
|
||||
{
|
||||
p += static_cast<int>(m_positions.size() - 1);
|
||||
p += static_cast<int>(m_positions.size());
|
||||
if (p < 0)
|
||||
{
|
||||
Error("Vertex index out of range (" + String::Number(p) + " < 0");
|
||||
error = true;
|
||||
break;
|
||||
}
|
||||
|
||||
++p;
|
||||
}
|
||||
|
||||
if (n < 0)
|
||||
{
|
||||
n += static_cast<int>(m_normals.size() - 1);
|
||||
n += static_cast<int>(m_normals.size());
|
||||
if (n < 0)
|
||||
{
|
||||
Error("Normal index out of range (" + String::Number(n) + " < 0");
|
||||
error = true;
|
||||
break;
|
||||
}
|
||||
|
||||
++n;
|
||||
}
|
||||
|
||||
if (t < 0)
|
||||
{
|
||||
t += static_cast<int>(m_texCoords.size() - 1);
|
||||
t += static_cast<int>(m_texCoords.size());
|
||||
if (t < 0)
|
||||
{
|
||||
Error("Texture coordinates index out of range (" + String::Number(t) + " < 0");
|
||||
error = true;
|
||||
break;
|
||||
}
|
||||
|
||||
++t;
|
||||
}
|
||||
|
||||
if (static_cast<std::size_t>(p) > m_positions.size())
|
||||
|
||||
@@ -161,6 +161,38 @@ namespace Nz
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SaveJPEG(const Image& image, const ImageParams& parameters, Stream& stream)
|
||||
{
|
||||
Image tempImage(image); //< We're using COW here to prevent Image copy unless required
|
||||
|
||||
int componentCount = ConvertToIntegerFormat(tempImage);
|
||||
if (componentCount == 0)
|
||||
{
|
||||
NazaraError("Failed to convert image to suitable format");
|
||||
return false;
|
||||
}
|
||||
|
||||
long long imageQuality;
|
||||
if (parameters.custom.GetIntegerParameter("NativeJPEGSaver_Quality", &imageQuality))
|
||||
{
|
||||
if (imageQuality <= 0 || imageQuality > 100)
|
||||
{
|
||||
NazaraError("NativeJPEGSaver_Quality value (" + Nz::String::Number(imageQuality) + ") does not fit in bounds ]0, 100], clamping...");
|
||||
imageQuality = Nz::Clamp(imageQuality, 1LL, 100LL);
|
||||
}
|
||||
}
|
||||
else
|
||||
imageQuality = 100;
|
||||
|
||||
if (!stbi_write_jpg_to_func(&WriteToStream, &stream, tempImage.GetWidth(), tempImage.GetHeight(), componentCount, tempImage.GetConstPixels(), int(imageQuality)))
|
||||
{
|
||||
NazaraError("Failed to write JPEG to stream");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SaveHDR(const Image& image, const ImageParams& parameters, Stream& stream)
|
||||
{
|
||||
NazaraUnused(parameters);
|
||||
@@ -232,10 +264,12 @@ namespace Nz
|
||||
{
|
||||
void RegisterSTBSaver()
|
||||
{
|
||||
s_formatHandlers["bmp"] = &SaveBMP;
|
||||
s_formatHandlers["hdr"] = &SaveHDR;
|
||||
s_formatHandlers["png"] = &SavePNG;
|
||||
s_formatHandlers["tga"] = &SaveTGA;
|
||||
s_formatHandlers["bmp"] = &SaveBMP;
|
||||
s_formatHandlers["hdr"] = &SaveHDR;
|
||||
s_formatHandlers["jpg"] = &SaveJPEG;
|
||||
s_formatHandlers["jpeg"] = &SaveJPEG;
|
||||
s_formatHandlers["png"] = &SavePNG;
|
||||
s_formatHandlers["tga"] = &SaveTGA;
|
||||
|
||||
ImageSaver::RegisterSaver(FormatQuerier, SaveToStream);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user