Switching to new Vec3.

This commit is contained in:
Branimir Karadžić 2018-11-13 22:38:41 -08:00
parent ebc05e20d8
commit a1b4cfc06c
6 changed files with 409 additions and 506 deletions

View File

@ -554,24 +554,24 @@ public:
Sphere lightPosRadius;
float lightTime = time * m_lightAnimationSpeed * (bx::sin(light/float(m_numLights) * bx::kPiHalf ) * 0.5f + 0.5f);
lightPosRadius.m_center[0] = bx::sin( ( (lightTime + light*0.47f) + bx::kPiHalf*1.37f ) )*offset;
lightPosRadius.m_center[1] = bx::cos( ( (lightTime + light*0.69f) + bx::kPiHalf*1.49f ) )*offset;
lightPosRadius.m_center[2] = bx::sin( ( (lightTime + light*0.37f) + bx::kPiHalf*1.57f ) )*2.0f;
lightPosRadius.m_radius = 2.0f;
lightPosRadius.m_center.x = bx::sin( ( (lightTime + light*0.47f) + bx::kPiHalf*1.37f ) )*offset;
lightPosRadius.m_center.y = bx::cos( ( (lightTime + light*0.69f) + bx::kPiHalf*1.49f ) )*offset;
lightPosRadius.m_center.z = bx::sin( ( (lightTime + light*0.37f) + bx::kPiHalf*1.57f ) )*2.0f;
lightPosRadius.m_radius = 2.0f;
Aabb aabb;
toAabb(aabb, lightPosRadius);
float box[8][3] =
{
{ aabb.m_min[0], aabb.m_min[1], aabb.m_min[2] },
{ aabb.m_min[0], aabb.m_min[1], aabb.m_max[2] },
{ aabb.m_min[0], aabb.m_max[1], aabb.m_min[2] },
{ aabb.m_min[0], aabb.m_max[1], aabb.m_max[2] },
{ aabb.m_max[0], aabb.m_min[1], aabb.m_min[2] },
{ aabb.m_max[0], aabb.m_min[1], aabb.m_max[2] },
{ aabb.m_max[0], aabb.m_max[1], aabb.m_min[2] },
{ aabb.m_max[0], aabb.m_max[1], aabb.m_max[2] },
{ aabb.m_min.x, aabb.m_min.y, aabb.m_min.z },
{ aabb.m_min.x, aabb.m_min.y, aabb.m_max.z },
{ aabb.m_min.x, aabb.m_max.y, aabb.m_min.z },
{ aabb.m_min.x, aabb.m_max.y, aabb.m_max.z },
{ aabb.m_max.x, aabb.m_min.y, aabb.m_min.z },
{ aabb.m_max.x, aabb.m_min.y, aabb.m_max.z },
{ aabb.m_max.x, aabb.m_max.y, aabb.m_min.z },
{ aabb.m_max.x, aabb.m_max.y, aabb.m_max.z },
};
float xyz[3];

View File

@ -566,13 +566,10 @@ public:
_dde->setColor(0xff0000ff);
float tmp[3];
bx::vec3Mul(tmp, hit.m_normal, 0.7f);
const bx::Vec3 tmp = bx::mul(hit.m_normal, 0.7f);
const bx::Vec3 end = bx::add(hit.m_pos, tmp);
float end[3];
bx::vec3Add(end, hit.m_pos, tmp);
_dde->drawCone(hit.m_pos, end, 0.1f);
_dde->drawCone(&hit.m_pos.x, &end.x, 0.1f);
_dde->pop();
@ -702,7 +699,7 @@ public:
const float pos[] = { 0.0f, -2.0f, 0.0f };
Plane plane;
bx::calcPlane(plane.m_normal, normal, pos);
bx::calcPlane(&plane.m_normal.x, normal, pos);
dde.setColor(false
|| intersect(&dde, ray, plane)
@ -723,17 +720,17 @@ public:
dde.draw(sphere);
dde.setWireframe(false);
sphere.m_center[0] = -2.0f;
sphere.m_center.x = -2.0f;
dde.setColor(intersect(&dde, ray, sphere) ? selected : 0xc0ffc0ff);
dde.setLod(2);
dde.draw(sphere);
sphere.m_center[0] = -4.0f;
sphere.m_center.x = -4.0f;
dde.setColor(intersect(&dde, ray, sphere) ? selected : 0xa0f0ffff);
dde.setLod(1);
dde.draw(sphere);
sphere.m_center[0] = -6.0f;
sphere.m_center.x = -6.0f;
dde.setColor(intersect(&dde, ray, sphere) ? selected : 0xffc0ff00);
dde.setLod(0);
dde.draw(sphere);
@ -823,7 +820,7 @@ public:
};
float up[3] = { 0.0f, 4.0f, 0.0f };
bx::vec3MulMtx(cylinder.m_end, up, mtx);
bx::vec3MulMtx(&cylinder.m_end.x, up, mtx);
dde.setColor(intersect(&dde, ray, cylinder) ? selected : 0xffffffff);
dde.draw(cylinder);

File diff suppressed because it is too large Load Diff

View File

@ -6,37 +6,39 @@
#ifndef BOUNDS_H_HEADER_GUARD
#define BOUNDS_H_HEADER_GUARD
#include <bx/math.h>
struct Aabb
{
float m_min[3];
float m_max[3];
bx::Vec3 m_min;
bx::Vec3 m_max;
};
struct Cylinder
{
float m_pos[3];
float m_end[3];
bx::Vec3 m_pos;
bx::Vec3 m_end;
float m_radius;
};
struct Capsule
{
float m_pos[3];
float m_end[3];
bx::Vec3 m_pos;
bx::Vec3 m_end;
float m_radius;
};
struct Cone
{
float m_pos[3];
float m_end[3];
bx::Vec3 m_pos;
bx::Vec3 m_end;
float m_radius;
};
struct Disk
{
float m_center[3];
float m_normal[3];
bx::Vec3 m_center;
bx::Vec3 m_normal;
float m_radius;
};
@ -47,33 +49,33 @@ struct Obb
struct Plane
{
float m_normal[3];
bx::Vec3 m_normal;
float m_dist;
};
struct Ray
{
float m_pos[3];
float m_dir[3];
bx::Vec3 m_pos;
bx::Vec3 m_dir;
};
struct Sphere
{
float m_center[3];
bx::Vec3 m_center;
float m_radius;
};
struct Tris
{
float m_v0[3];
float m_v1[3];
float m_v2[3];
bx::Vec3 m_v0;
bx::Vec3 m_v1;
bx::Vec3 m_v2;
};
struct Hit
{
float m_pos[3];
float m_normal[3];
bx::Vec3 m_pos;
bx::Vec3 m_normal;
float m_dist;
};
@ -124,7 +126,7 @@ void calcMinBoundingSphere(Sphere& _sphere, const void* _vertices, uint32_t _num
void buildFrustumPlanes(Plane* _planes, const float* _viewProj);
/// Returns point from 3 intersecting planes.
void intersectPlanes(float _result[3], const Plane& _pa, const Plane& _pb, const Plane& _pc);
bx::Vec3 intersectPlanes(const Plane& _pa, const Plane& _pb, const Plane& _pc);
/// Make screen space ray from x, y coordinate and inverse view-projection matrix.
Ray makeRay(float _x, float _y, const float* _invVp);

View File

@ -102,15 +102,15 @@ struct Camera
m_mouseNow.m_my = 0;
m_mouseLast.m_mx = 0;
m_mouseLast.m_my = 0;
m_eye[0] = 0.0f;
m_eye[1] = 0.0f;
m_eye[2] = -35.0f;
m_at[0] = 0.0f;
m_at[1] = 0.0f;
m_at[2] = -1.0f;
m_up[0] = 0.0f;
m_up[1] = 1.0f;
m_up[2] = 0.0f;
m_eye.x = 0.0f;
m_eye.y = 0.0f;
m_eye.z = -35.0f;
m_at.x = 0.0f;
m_at.y = 0.0f;
m_at.z = -1.0f;
m_up.x = 0.0f;
m_up.y = 1.0f;
m_up.z = 0.0f;
m_horizontalAngle = 0.01f;
m_verticalAngle = 0.0f;
m_mouseSpeed = 0.0020f;
@ -164,107 +164,88 @@ struct Camera
m_keys |= gpy < -16834 ? CAMERA_KEY_FORWARD : 0;
m_keys |= gpy > 16834 ? CAMERA_KEY_BACKWARD : 0;
float direction[3] =
const bx::Vec3 direction =
{
bx::cos(m_verticalAngle) * bx::sin(m_horizontalAngle),
bx::sin(m_verticalAngle),
bx::cos(m_verticalAngle) * bx::cos(m_horizontalAngle),
};
float right[3] =
const bx::Vec3 right =
{
bx::sin(m_horizontalAngle - bx::kPiHalf),
0,
bx::cos(m_horizontalAngle - bx::kPiHalf),
};
float up[3];
bx::vec3Cross(up, right, direction);
const bx::Vec3 up = bx::cross(right, direction);
if (m_keys & CAMERA_KEY_FORWARD)
{
float pos[3];
bx::vec3Move(pos, m_eye);
const bx::Vec3 pos = m_eye;
const bx::Vec3 tmp = bx::mul(direction, _deltaTime * m_moveSpeed);
float tmp[3];
bx::vec3Mul(tmp, direction, _deltaTime * m_moveSpeed);
bx::vec3Add(m_eye, pos, tmp);
m_eye = bx::add(pos, tmp);
setKeyState(CAMERA_KEY_FORWARD, false);
}
if (m_keys & CAMERA_KEY_BACKWARD)
{
float pos[3];
bx::vec3Move(pos, m_eye);
const bx::Vec3 pos = m_eye;
const bx::Vec3 tmp = bx::mul(direction, _deltaTime * m_moveSpeed);
float tmp[3];
bx::vec3Mul(tmp, direction, _deltaTime * m_moveSpeed);
bx::vec3Sub(m_eye, pos, tmp);
m_eye = bx::sub(pos, tmp);
setKeyState(CAMERA_KEY_BACKWARD, false);
}
if (m_keys & CAMERA_KEY_LEFT)
{
float pos[3];
bx::vec3Move(pos, m_eye);
const bx::Vec3 pos = m_eye;
const bx::Vec3 tmp = bx::mul(right, _deltaTime * m_moveSpeed);
float tmp[3];
bx::vec3Mul(tmp, right, _deltaTime * m_moveSpeed);
bx::vec3Add(m_eye, pos, tmp);
m_eye = bx::add(pos, tmp);
setKeyState(CAMERA_KEY_LEFT, false);
}
if (m_keys & CAMERA_KEY_RIGHT)
{
float pos[3];
bx::vec3Move(pos, m_eye);
const bx::Vec3 pos = m_eye;
const bx::Vec3 tmp = bx::mul(right, _deltaTime * m_moveSpeed);
float tmp[3];
bx::vec3Mul(tmp, right, _deltaTime * m_moveSpeed);
bx::vec3Sub(m_eye, pos, tmp);
m_eye = bx::sub(pos, tmp);
setKeyState(CAMERA_KEY_RIGHT, false);
}
if (m_keys & CAMERA_KEY_UP)
{
float pos[3];
bx::vec3Move(pos, m_eye);
const bx::Vec3 pos = m_eye;
const bx::Vec3 tmp = bx::mul(up, _deltaTime * m_moveSpeed);
float tmp[3];
bx::vec3Mul(tmp, up, _deltaTime * m_moveSpeed);
bx::vec3Add(m_eye, pos, tmp);
m_eye = bx::add(pos, tmp);
setKeyState(CAMERA_KEY_UP, false);
}
if (m_keys & CAMERA_KEY_DOWN)
{
float pos[3];
bx::vec3Move(pos, m_eye);
const bx::Vec3 pos = m_eye;
const bx::Vec3 tmp = bx::mul(up, _deltaTime * m_moveSpeed);
float tmp[3];
bx::vec3Mul(tmp, up, _deltaTime * m_moveSpeed);
bx::vec3Sub(m_eye, pos, tmp);
m_eye = bx::sub(pos, tmp);
setKeyState(CAMERA_KEY_DOWN, false);
}
bx::vec3Add(m_at, m_eye, direction);
bx::vec3Cross(m_up, right, direction);
m_at = bx::add(m_eye, direction);
m_up = bx::cross(right, direction);
}
void getViewMtx(float* _viewMtx)
{
bx::mtxLookAt(_viewMtx, m_eye, m_at, m_up);
bx::mtxLookAt(_viewMtx, &m_eye.x, &m_at.x, &m_up.x);
}
void setPosition(const float* _pos)
{
bx::memCopy(m_eye, _pos, sizeof(float)*3);
bx::memCopy(&m_eye.x, _pos, sizeof(float)*3);
}
void setVerticalAngle(float _verticalAngle)
@ -280,9 +261,9 @@ struct Camera
MouseCoords m_mouseNow;
MouseCoords m_mouseLast;
float m_eye[3];
float m_at[3];
float m_up[3];
bx::Vec3 m_eye;
bx::Vec3 m_at;
bx::Vec3 m_up;
float m_horizontalAngle;
float m_verticalAngle;
@ -334,12 +315,12 @@ void cameraGetViewMtx(float* _viewMtx)
void cameraGetPosition(float* _pos)
{
bx::memCopy(_pos, s_camera->m_eye, 3*sizeof(float) );
bx::memCopy(_pos, &s_camera->m_eye.x, 3*sizeof(float) );
}
void cameraGetAt(float* _at)
{
bx::memCopy(_at, s_camera->m_at, 3*sizeof(float) );
bx::memCopy(_at, &s_camera->m_at.x, 3*sizeof(float) );
}
void cameraUpdate(float _deltaTime, const entry::MouseState& _mouseState)

View File

@ -1426,29 +1426,29 @@ struct DebugDrawEncoderImpl
const Attrib& attrib = m_attrib[m_stack];
if (attrib.m_wireframe)
{
moveTo(_aabb.m_min[0], _aabb.m_min[1], _aabb.m_min[2]);
lineTo(_aabb.m_max[0], _aabb.m_min[1], _aabb.m_min[2]);
lineTo(_aabb.m_max[0], _aabb.m_max[1], _aabb.m_min[2]);
lineTo(_aabb.m_min[0], _aabb.m_max[1], _aabb.m_min[2]);
moveTo(_aabb.m_min.x, _aabb.m_min.y, _aabb.m_min.z);
lineTo(_aabb.m_max.x, _aabb.m_min.y, _aabb.m_min.z);
lineTo(_aabb.m_max.x, _aabb.m_max.y, _aabb.m_min.z);
lineTo(_aabb.m_min.x, _aabb.m_max.y, _aabb.m_min.z);
close();
moveTo(_aabb.m_min[0], _aabb.m_min[1], _aabb.m_max[2]);
lineTo(_aabb.m_max[0], _aabb.m_min[1], _aabb.m_max[2]);
lineTo(_aabb.m_max[0], _aabb.m_max[1], _aabb.m_max[2]);
lineTo(_aabb.m_min[0], _aabb.m_max[1], _aabb.m_max[2]);
moveTo(_aabb.m_min.x, _aabb.m_min.y, _aabb.m_max.z);
lineTo(_aabb.m_max.x, _aabb.m_min.y, _aabb.m_max.z);
lineTo(_aabb.m_max.x, _aabb.m_max.y, _aabb.m_max.z);
lineTo(_aabb.m_min.x, _aabb.m_max.y, _aabb.m_max.z);
close();
moveTo(_aabb.m_min[0], _aabb.m_min[1], _aabb.m_min[2]);
lineTo(_aabb.m_min[0], _aabb.m_min[1], _aabb.m_max[2]);
moveTo(_aabb.m_min.x, _aabb.m_min.y, _aabb.m_min.z);
lineTo(_aabb.m_min.x, _aabb.m_min.y, _aabb.m_max.z);
moveTo(_aabb.m_max[0], _aabb.m_min[1], _aabb.m_min[2]);
lineTo(_aabb.m_max[0], _aabb.m_min[1], _aabb.m_max[2]);
moveTo(_aabb.m_max.x, _aabb.m_min.y, _aabb.m_min.z);
lineTo(_aabb.m_max.x, _aabb.m_min.y, _aabb.m_max.z);
moveTo(_aabb.m_min[0], _aabb.m_max[1], _aabb.m_min[2]);
lineTo(_aabb.m_min[0], _aabb.m_max[1], _aabb.m_max[2]);
moveTo(_aabb.m_min.x, _aabb.m_max.y, _aabb.m_min.z);
lineTo(_aabb.m_min.x, _aabb.m_max.y, _aabb.m_max.z);
moveTo(_aabb.m_max[0], _aabb.m_max[1], _aabb.m_min[2]);
lineTo(_aabb.m_max[0], _aabb.m_max[1], _aabb.m_max[2]);
moveTo(_aabb.m_max.x, _aabb.m_max.y, _aabb.m_min.z);
lineTo(_aabb.m_max.x, _aabb.m_max.y, _aabb.m_max.z);
}
else
{
@ -1460,12 +1460,12 @@ struct DebugDrawEncoderImpl
void draw(const Cylinder& _cylinder, bool _capsule)
{
drawCylinder(_cylinder.m_pos, _cylinder.m_end, _cylinder.m_radius, _capsule);
drawCylinder(&_cylinder.m_pos.x, &_cylinder.m_end.x, _cylinder.m_radius, _capsule);
}
void draw(const Disk& _disk)
{
drawCircle(_disk.m_normal, _disk.m_center, _disk.m_radius, 0.0f);
drawCircle(&_disk.m_normal.x, &_disk.m_center.x, _disk.m_radius, 0.0f);
}
void draw(const Obb& _obb)
@ -1518,9 +1518,9 @@ struct DebugDrawEncoderImpl
, 0.0f
, 0.0f
, 0.0f
, _sphere.m_center[0]
, _sphere.m_center[1]
, _sphere.m_center[2]
, _sphere.m_center.x
, _sphere.m_center.y
, _sphere.m_center.z
);
uint8_t lod = attrib.m_lod > Mesh::SphereMaxLod
? uint8_t(Mesh::SphereMaxLod)
@ -1663,39 +1663,39 @@ struct DebugDrawEncoderImpl
Plane planes[6];
buildFrustumPlanes(planes, _viewProj);
float points[24];
intersectPlanes(&points[ 0], planes[0], planes[2], planes[4]);
intersectPlanes(&points[ 3], planes[0], planes[3], planes[4]);
intersectPlanes(&points[ 6], planes[0], planes[3], planes[5]);
intersectPlanes(&points[ 9], planes[0], planes[2], planes[5]);
intersectPlanes(&points[12], planes[1], planes[2], planes[4]);
intersectPlanes(&points[15], planes[1], planes[3], planes[4]);
intersectPlanes(&points[18], planes[1], planes[3], planes[5]);
intersectPlanes(&points[21], planes[1], planes[2], planes[5]);
bx::Vec3 points[8];
points[0] = intersectPlanes(planes[0], planes[2], planes[4]);
points[1] = intersectPlanes(planes[0], planes[3], planes[4]);
points[2] = intersectPlanes(planes[0], planes[3], planes[5]);
points[3] = intersectPlanes(planes[0], planes[2], planes[5]);
points[4] = intersectPlanes(planes[1], planes[2], planes[4]);
points[5] = intersectPlanes(planes[1], planes[3], planes[4]);
points[6] = intersectPlanes(planes[1], planes[3], planes[5]);
points[7] = intersectPlanes(planes[1], planes[2], planes[5]);
moveTo(&points[ 0]);
lineTo(&points[ 3]);
lineTo(&points[ 6]);
lineTo(&points[ 9]);
moveTo(&points[0].x);
lineTo(&points[1].x);
lineTo(&points[2].x);
lineTo(&points[3].x);
close();
moveTo(&points[12]);
lineTo(&points[15]);
lineTo(&points[18]);
lineTo(&points[21]);
moveTo(&points[4].x);
lineTo(&points[5].x);
lineTo(&points[6].x);
lineTo(&points[7].x);
close();
moveTo(&points[ 0]);
lineTo(&points[12]);
moveTo(&points[0].x);
lineTo(&points[4].x);
moveTo(&points[ 3]);
lineTo(&points[15]);
moveTo(&points[1].x);
lineTo(&points[5].x);
moveTo(&points[ 6]);
lineTo(&points[18]);
moveTo(&points[2].x);
lineTo(&points[6].x);
moveTo(&points[ 9]);
lineTo(&points[21]);
moveTo(&points[3].x);
lineTo(&points[7].x);
}
void drawFrustum(const void* _viewProj)
@ -2029,11 +2029,15 @@ struct DebugDrawEncoderImpl
draw(Mesh::Enum(Mesh::Capsule0 + lod), mtx[0], 2, attrib.m_wireframe);
Sphere sphere;
bx::vec3Move(sphere.m_center, _from);
sphere.m_radius = _radius;
sphere.m_center.x = _from[0];
sphere.m_center.y = _from[1];
sphere.m_center.z = _from[2];
sphere.m_radius = _radius;
draw(sphere);
bx::vec3Move(sphere.m_center, _to);
sphere.m_center.x = _to[0];
sphere.m_center.y = _to[1];
sphere.m_center.z = _to[2];
draw(sphere);
}
else
@ -2579,7 +2583,7 @@ void DebugDrawEncoder::draw(const Sphere& _sphere)
void DebugDrawEncoder::draw(const Cone& _cone)
{
DEBUG_DRAW_ENCODER(drawCone(_cone.m_pos, _cone.m_end, _cone.m_radius) );
DEBUG_DRAW_ENCODER(drawCone(&_cone.m_pos.x, &_cone.m_end.x, _cone.m_radius) );
}
void DebugDrawEncoder::draw(GeometryHandle _handle)