mirror of
https://github.com/overte-org/overte.git
synced 2025-08-06 12:54:30 +02:00
code review
This commit is contained in:
parent
bb96ad1346
commit
07b241c778
5 changed files with 12 additions and 21 deletions
|
@ -3,6 +3,7 @@ var shiftHeld = false;
|
||||||
|
|
||||||
Script.include([
|
Script.include([
|
||||||
"libraries/toolBars.js",
|
"libraries/toolBars.js",
|
||||||
|
"libraries/utils.js",
|
||||||
]);
|
]);
|
||||||
|
|
||||||
var isActive = false;
|
var isActive = false;
|
||||||
|
@ -23,10 +24,6 @@ function floorVector(v) {
|
||||||
return {x: Math.floor(v.x), y: Math.floor(v.y), z: Math.floor(v.z)};
|
return {x: Math.floor(v.x), y: Math.floor(v.y), z: Math.floor(v.z)};
|
||||||
}
|
}
|
||||||
|
|
||||||
function vectorToString(v){
|
|
||||||
return "{" + v.x + ", " + v.y + ", " + v.z + "}";
|
|
||||||
}
|
|
||||||
|
|
||||||
var toolBar = (function () {
|
var toolBar = (function () {
|
||||||
var that = {},
|
var that = {},
|
||||||
toolBar,
|
toolBar,
|
||||||
|
@ -251,16 +248,10 @@ function addTerrainBlock() {
|
||||||
if (alreadyThere) {
|
if (alreadyThere) {
|
||||||
// there is already a terrain block under MyAvatar.
|
// there is already a terrain block under MyAvatar.
|
||||||
// try in front of the avatar.
|
// try in front of the avatar.
|
||||||
print("alreadyThere = " + alreadyThere);
|
|
||||||
print("MyAvatar.position = " + vectorToString(MyAvatar.position));
|
|
||||||
print("baseLocation = " + vectorToString(baseLocation));
|
|
||||||
facingPosition = Vec3.sum(MyAvatar.position, Vec3.multiply(8.0, Quat.getFront(Camera.getOrientation())));
|
facingPosition = Vec3.sum(MyAvatar.position, Vec3.multiply(8.0, Quat.getFront(Camera.getOrientation())));
|
||||||
facingPosition = Vec3.sum(facingPosition, {x:8, y:8, z:8});
|
facingPosition = Vec3.sum(facingPosition, {x:8, y:8, z:8});
|
||||||
print("facingPosition = " + vectorToString(facingPosition));
|
|
||||||
baseLocation = getTerrainAlignedLocation(facingPosition);
|
baseLocation = getTerrainAlignedLocation(facingPosition);
|
||||||
print("baseLocation = " + vectorToString(baseLocation));
|
|
||||||
alreadyThere = lookupTerrainForLocation(baseLocation);
|
alreadyThere = lookupTerrainForLocation(baseLocation);
|
||||||
print("alreadyThere = " + alreadyThere);
|
|
||||||
if (alreadyThere) {
|
if (alreadyThere) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -281,8 +272,6 @@ function addTerrainBlock() {
|
||||||
var AvatarPositionInVoxelCoords = Entities.worldCoordsToVoxelCoords(polyVoxID, MyAvatar.position);
|
var AvatarPositionInVoxelCoords = Entities.worldCoordsToVoxelCoords(polyVoxID, MyAvatar.position);
|
||||||
// TODO -- how to find the avatar's feet?
|
// TODO -- how to find the avatar's feet?
|
||||||
var topY = Math.round(AvatarPositionInVoxelCoords.y) - 4;
|
var topY = Math.round(AvatarPositionInVoxelCoords.y) - 4;
|
||||||
// Entities.setAllVoxels(polyVoxID, 255);
|
|
||||||
// Entities.setVoxelsInCuboid(polyVoxID, {x:0, y:topY, z:0}, {x:16, y:64 - topY, z:16}, 0);
|
|
||||||
Entities.setVoxelsInCuboid(polyVoxID, {x:0, y:0, z:0}, {x:16, y:topY, z:16}, 255);
|
Entities.setVoxelsInCuboid(polyVoxID, {x:0, y:0, z:0}, {x:16, y:topY, z:16}, 255);
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -136,7 +136,7 @@ glm::mat4 RenderablePolyVoxEntityItem::voxelToLocalMatrix() const {
|
||||||
glm::vec3 center = getCenterPosition();
|
glm::vec3 center = getCenterPosition();
|
||||||
glm::vec3 position = getPosition();
|
glm::vec3 position = getPosition();
|
||||||
glm::vec3 positionToCenter = center - position;
|
glm::vec3 positionToCenter = center - position;
|
||||||
positionToCenter -= getDimensions() * glm::vec3(0.5f, 0.5f, 0.5f) - getSurfacePositionAdjustment();
|
positionToCenter -= getDimensions() * Vectors::HALF - getSurfacePositionAdjustment();
|
||||||
glm::mat4 centerToCorner = glm::translate(glm::mat4(), positionToCenter);
|
glm::mat4 centerToCorner = glm::translate(glm::mat4(), positionToCenter);
|
||||||
glm::mat4 scaled = glm::scale(centerToCorner, scale);
|
glm::mat4 scaled = glm::scale(centerToCorner, scale);
|
||||||
return scaled;
|
return scaled;
|
||||||
|
@ -387,8 +387,8 @@ bool RenderablePolyVoxEntityItem::findDetailedRayIntersection(const glm::vec3& o
|
||||||
glm::vec3 result3 = vec3(result);
|
glm::vec3 result3 = vec3(result);
|
||||||
|
|
||||||
AABox voxelBox;
|
AABox voxelBox;
|
||||||
voxelBox += result3 + glm::vec3(-0.5f, -0.5f, -0.5f);
|
voxelBox += result3 - Vectors::HALF;
|
||||||
voxelBox += result3 + glm::vec3(0.5f, 0.5f, 0.5f);
|
voxelBox += result3 + Vectors::HALF;
|
||||||
|
|
||||||
float voxelDistance;
|
float voxelDistance;
|
||||||
|
|
||||||
|
@ -589,9 +589,9 @@ namespace render {
|
||||||
glm::vec3 RenderablePolyVoxEntityItem::voxelCoordsToWorldCoords(glm::vec3& voxelCoords) const {
|
glm::vec3 RenderablePolyVoxEntityItem::voxelCoordsToWorldCoords(glm::vec3& voxelCoords) const {
|
||||||
glm::vec3 adjustedCoords;
|
glm::vec3 adjustedCoords;
|
||||||
if (isEdged(_voxelSurfaceStyle)) {
|
if (isEdged(_voxelSurfaceStyle)) {
|
||||||
adjustedCoords = voxelCoords + glm::vec3(0.5f, 0.5f, 0.5f);
|
adjustedCoords = voxelCoords + Vectors::HALF;
|
||||||
} else {
|
} else {
|
||||||
adjustedCoords = voxelCoords - glm::vec3(0.5f, 0.5f, 0.5f);
|
adjustedCoords = voxelCoords - Vectors::HALF;
|
||||||
}
|
}
|
||||||
return glm::vec3(voxelToWorldMatrix() * glm::vec4(adjustedCoords, 1.0f));
|
return glm::vec3(voxelToWorldMatrix() * glm::vec4(adjustedCoords, 1.0f));
|
||||||
}
|
}
|
||||||
|
@ -599,9 +599,9 @@ glm::vec3 RenderablePolyVoxEntityItem::voxelCoordsToWorldCoords(glm::vec3& voxel
|
||||||
glm::vec3 RenderablePolyVoxEntityItem::worldCoordsToVoxelCoords(glm::vec3& worldCoords) const {
|
glm::vec3 RenderablePolyVoxEntityItem::worldCoordsToVoxelCoords(glm::vec3& worldCoords) const {
|
||||||
glm::vec3 result = glm::vec3(worldToVoxelMatrix() * glm::vec4(worldCoords, 1.0f));
|
glm::vec3 result = glm::vec3(worldToVoxelMatrix() * glm::vec4(worldCoords, 1.0f));
|
||||||
if (isEdged(_voxelSurfaceStyle)) {
|
if (isEdged(_voxelSurfaceStyle)) {
|
||||||
return result - glm::vec3(0.5f, 0.5f, 0.5f);
|
return result - Vectors::HALF;
|
||||||
}
|
}
|
||||||
return result + glm::vec3(0.5f, 0.5f, 0.5f);
|
return result + Vectors::HALF;
|
||||||
}
|
}
|
||||||
|
|
||||||
glm::vec3 RenderablePolyVoxEntityItem::voxelCoordsToLocalCoords(glm::vec3& voxelCoords) const {
|
glm::vec3 RenderablePolyVoxEntityItem::voxelCoordsToLocalCoords(glm::vec3& voxelCoords) const {
|
||||||
|
@ -656,7 +656,7 @@ void RenderablePolyVoxEntityItem::setVoxelVolumeSize(glm::vec3 voxelVolumeSize)
|
||||||
|
|
||||||
bool RenderablePolyVoxEntityItem::inUserBounds(const PolyVox::SimpleVolume<uint8_t>* vol,
|
bool RenderablePolyVoxEntityItem::inUserBounds(const PolyVox::SimpleVolume<uint8_t>* vol,
|
||||||
PolyVoxEntityItem::PolyVoxSurfaceStyle surfaceStyle,
|
PolyVoxEntityItem::PolyVoxSurfaceStyle surfaceStyle,
|
||||||
int x, int y, int z) {
|
int x, int y, int z) const {
|
||||||
// x, y, z are in user voxel-coords, not adjusted-for-edge voxel-coords.
|
// x, y, z are in user voxel-coords, not adjusted-for-edge voxel-coords.
|
||||||
if (isEdged(surfaceStyle)) {
|
if (isEdged(surfaceStyle)) {
|
||||||
if (x < 0 || y < 0 || z < 0 ||
|
if (x < 0 || y < 0 || z < 0 ||
|
||||||
|
|
|
@ -141,7 +141,7 @@ private:
|
||||||
int _onCount; // how many non-zero voxels are in _volData
|
int _onCount; // how many non-zero voxels are in _volData
|
||||||
|
|
||||||
bool inUserBounds(const PolyVox::SimpleVolume<uint8_t>* vol, PolyVoxEntityItem::PolyVoxSurfaceStyle surfaceStyle,
|
bool inUserBounds(const PolyVox::SimpleVolume<uint8_t>* vol, PolyVoxEntityItem::PolyVoxSurfaceStyle surfaceStyle,
|
||||||
int x, int y, int z);
|
int x, int y, int z) const;
|
||||||
uint8_t getVoxelInternal(int x, int y, int z);
|
uint8_t getVoxelInternal(int x, int y, int z);
|
||||||
bool setVoxelInternal(int x, int y, int z, uint8_t toValue);
|
bool setVoxelInternal(int x, int y, int z, uint8_t toValue);
|
||||||
bool updateOnCount(int x, int y, int z, uint8_t toValue);
|
bool updateOnCount(int x, int y, int z, uint8_t toValue);
|
||||||
|
|
|
@ -27,6 +27,7 @@ const vec3 Vectors::MAX{ FLT_MAX };
|
||||||
const vec3 Vectors::MIN{ -FLT_MAX };
|
const vec3 Vectors::MIN{ -FLT_MAX };
|
||||||
const vec3 Vectors::ZERO{ 0.0f };
|
const vec3 Vectors::ZERO{ 0.0f };
|
||||||
const vec3 Vectors::ONE{ 1.0f };
|
const vec3 Vectors::ONE{ 1.0f };
|
||||||
|
const vec3 Vectors::HALF{ 0.5f };
|
||||||
const vec3& Vectors::RIGHT = Vectors::UNIT_X;
|
const vec3& Vectors::RIGHT = Vectors::UNIT_X;
|
||||||
const vec3& Vectors::UP = Vectors::UNIT_Y;
|
const vec3& Vectors::UP = Vectors::UNIT_Y;
|
||||||
const vec3& Vectors::FRONT = Vectors::UNIT_NEG_Z;
|
const vec3& Vectors::FRONT = Vectors::UNIT_NEG_Z;
|
||||||
|
|
|
@ -70,6 +70,7 @@ public:
|
||||||
static const vec3 MIN;
|
static const vec3 MIN;
|
||||||
static const vec3 ZERO;
|
static const vec3 ZERO;
|
||||||
static const vec3 ONE;
|
static const vec3 ONE;
|
||||||
|
static const vec3 HALF;
|
||||||
static const vec3& RIGHT;
|
static const vec3& RIGHT;
|
||||||
static const vec3& UP;
|
static const vec3& UP;
|
||||||
static const vec3& FRONT;
|
static const vec3& FRONT;
|
||||||
|
|
Loading…
Reference in a new issue