mirror of
https://github.com/celisej567/source-engine-metaballs.git
synced 2026-02-25 14:36:39 +03:00
Update c_point_blob_container.cpp
This commit is contained in:
@@ -12,6 +12,8 @@
|
||||
|
||||
#include "materialsystem/imesh.h"
|
||||
|
||||
#include "mathlib/ssemath.h"
|
||||
|
||||
LINK_ENTITY_TO_CLASS(point_blob_container, C_PointBlobContainer);
|
||||
|
||||
IMPLEMENT_NETWORKCLASS_ALIASED(PointBlobContainer, DT_PointBlobContainer)
|
||||
@@ -32,20 +34,21 @@ ConVar cl_blobthreshold("cl_blobthreshold", "1", FCVAR_CLIENTDLL);
|
||||
ConVar cl_blobvaluethreshold("cl_blobvaluethreshold", "0.03", FCVAR_CLIENTDLL);
|
||||
|
||||
//why? why not! (it works better then Q_strcmp that redirects to V_strcmp that redirects to default strcmp)
|
||||
int Quake_strcmp (const char* s1, const char* s2)
|
||||
{
|
||||
while (1)
|
||||
{
|
||||
if (*s1 != *s2)
|
||||
return -1; // strings not equal
|
||||
if (!*s1)
|
||||
return 0; // strings are equal
|
||||
s1++;
|
||||
s2++;
|
||||
}
|
||||
//~ int Quake_strcmp (const char* s1, const char* s2)
|
||||
//~ {
|
||||
//~ while (1)
|
||||
//~ {
|
||||
//~ if (*s1 != *s2)
|
||||
//~ return -1; // strings not equal
|
||||
//~ if (!*s1)
|
||||
//~ return 0; // strings are equal
|
||||
//~ s1++;
|
||||
//~ s2++;
|
||||
//~ }
|
||||
|
||||
return -1;
|
||||
}
|
||||
//~ return -1;
|
||||
//~ }
|
||||
#define Quake_strcmp strcmp
|
||||
|
||||
void C_PointBlobContainer::Spawn()
|
||||
{
|
||||
@@ -106,30 +109,29 @@ int C_PointBlobContainer::DrawModel(int flags)
|
||||
#pragma omp parallel for
|
||||
for (int i = 0; i < cubeGrid.numCubes; i++)
|
||||
{
|
||||
|
||||
CUBE_GRID_CUBE& cube = cubeGrid.cubes[i];
|
||||
//calculate which vertices are inside the surface
|
||||
unsigned char cubeIndex = 0;
|
||||
if (cubeGrid.cubes[i].vertices[0]->value < threshold)
|
||||
if (cube.vertices[0]->value < threshold)
|
||||
cubeIndex |= 1;
|
||||
if (cubeGrid.cubes[i].vertices[1]->value < threshold)
|
||||
if (cube.vertices[1]->value < threshold)
|
||||
cubeIndex |= 2;
|
||||
if (cubeGrid.cubes[i].vertices[2]->value < threshold)
|
||||
if (cube.vertices[2]->value < threshold)
|
||||
cubeIndex |= 4;
|
||||
if (cubeGrid.cubes[i].vertices[3]->value < threshold)
|
||||
if (cube.vertices[3]->value < threshold)
|
||||
cubeIndex |= 8;
|
||||
if (cubeGrid.cubes[i].vertices[4]->value < threshold)
|
||||
if (cube.vertices[4]->value < threshold)
|
||||
cubeIndex |= 16;
|
||||
if (cubeGrid.cubes[i].vertices[5]->value < threshold)
|
||||
if (cube.vertices[5]->value < threshold)
|
||||
cubeIndex |= 32;
|
||||
if (cubeGrid.cubes[i].vertices[6]->value < threshold)
|
||||
if (cube.vertices[6]->value < threshold)
|
||||
cubeIndex |= 64;
|
||||
if (cubeGrid.cubes[i].vertices[7]->value < threshold)
|
||||
if (cube.vertices[7]->value < threshold)
|
||||
cubeIndex |= 128;
|
||||
|
||||
//look this value up in the edge table to see which edges to interpolate along
|
||||
int usedEdges = edgeTable[cubeIndex];
|
||||
|
||||
|
||||
//if the cube is entirely within/outside surface, no faces
|
||||
if (usedEdges == 0 || usedEdges == 255)
|
||||
continue;
|
||||
@@ -139,18 +141,33 @@ int C_PointBlobContainer::DrawModel(int flags)
|
||||
{
|
||||
if (usedEdges & 1 << currentEdge)
|
||||
{
|
||||
CUBE_GRID_VERTEX* v1 = cubeGrid.cubes[i].vertices[verticesAtEndsOfEdges[currentEdge * 2]];
|
||||
CUBE_GRID_VERTEX* v2 = cubeGrid.cubes[i].vertices[verticesAtEndsOfEdges[currentEdge * 2 + 1]];
|
||||
CUBE_GRID_VERTEX* v1 = cube.vertices[verticesAtEndsOfEdges[currentEdge * 2]];
|
||||
CUBE_GRID_VERTEX* v2 = cube.vertices[verticesAtEndsOfEdges[currentEdge * 2 + 1]];
|
||||
|
||||
float delta = (threshold - v1->value) / (v2->value - v1->value);
|
||||
//~ const float delta = (threshold - v1->value) / (v2->value - v1->value);
|
||||
fltx4 delta = ReplicateX4((threshold - v1->value) / (v2->value - v1->value));
|
||||
//edgeVertices[currentEdge].position=v1->position + delta*(v2->position - v1->position);
|
||||
edgeVertices[currentEdge].position.x = v1->position.x + delta * (v2->position.x - v1->position.x);
|
||||
edgeVertices[currentEdge].position.y = v1->position.y + delta * (v2->position.y - v1->position.y);
|
||||
edgeVertices[currentEdge].position.z = v1->position.z + delta * (v2->position.z - v1->position.z);
|
||||
|
||||
fltx4 f1 = LoadUnaligned3SIMD(v1->position.Base()), f2 = LoadUnaligned3SIMD(v2->position.Base());
|
||||
|
||||
//~ edgeVertices[currentEdge].position.x = v1->position.x + delta * (v2->position.x - v1->position.x);
|
||||
//~ edgeVertices[currentEdge].position.y = v1->position.y + delta * (v2->position.y - v1->position.y);
|
||||
//~ edgeVertices[currentEdge].position.z = v1->position.z + delta * (v2->position.z - v1->position.z);
|
||||
|
||||
StoreUnaligned3SIMD(edgeVertices[currentEdge].position.Base(),
|
||||
AddSIMD(f1, MulSIMD(delta, SubSIMD(f2, f1) )));
|
||||
|
||||
//edgeVertices[currentEdge].normal=v1->normal + delta*(v2->normal - v1->normal);
|
||||
edgeVertices[currentEdge].normal.x = v1->normal.x + delta * (v2->normal.x - v1->normal.x);
|
||||
edgeVertices[currentEdge].normal.y = v1->normal.y + delta * (v2->normal.y - v1->normal.y);
|
||||
edgeVertices[currentEdge].normal.z = v1->normal.z + delta * (v2->normal.z - v1->normal.z);
|
||||
|
||||
f1 = LoadUnaligned3SIMD(v1->normal.Base());
|
||||
f2 = LoadUnaligned3SIMD(v2->normal.Base());
|
||||
|
||||
//~ edgeVertices[currentEdge].normal.x = v1->normal.x + delta * (v2->normal.x - v1->normal.x);
|
||||
//~ edgeVertices[currentEdge].normal.y = v1->normal.y + delta * (v2->normal.y - v1->normal.y);
|
||||
//~ edgeVertices[currentEdge].normal.z = v1->normal.z + delta * (v2->normal.z - v1->normal.z);
|
||||
|
||||
StoreUnaligned3SIMD(edgeVertices[currentEdge].normal.Base(),
|
||||
AddSIMD(f1, MulSIMD(delta, SubSIMD(f2, f1) )));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -159,9 +176,13 @@ int C_PointBlobContainer::DrawModel(int flags)
|
||||
{
|
||||
//Vector pos = Vector(edgeVertices[triTable[cubeIndex][k + 0]].position.x, edgeVertices[triTable[cubeIndex][k + 0]].position.y, edgeVertices[triTable[cubeIndex][k + 0]].position.z);
|
||||
//Vector vertnormal = Vector(edgeVertices[triTable[cubeIndex][k + 0]].normal.x, edgeVertices[triTable[cubeIndex][k + 0]].normal.y, edgeVertices[triTable[cubeIndex][k + 0]].normal.z);
|
||||
|
||||
SURFACE_VERTEX &e0 = edgeVertices[triTable[cubeIndex][k + 0]],
|
||||
&e1 = edgeVertices[triTable[cubeIndex][k + 1]],
|
||||
&e2 = edgeVertices[triTable[cubeIndex][k + 2]];
|
||||
|
||||
meshBuilder.Normal3fv(edgeVertices[triTable[cubeIndex][k + 0]].normal.Base());
|
||||
meshBuilder.Position3fv(edgeVertices[triTable[cubeIndex][k + 0]].position.Base());
|
||||
meshBuilder.Normal3fv(e0.normal.Base());
|
||||
meshBuilder.Position3fv(e0.position.Base());
|
||||
meshBuilder.TexCoord2f(0, 1, 1);
|
||||
meshBuilder.Color3f(1,0,0);
|
||||
meshBuilder.AdvanceVertex();
|
||||
@@ -169,8 +190,8 @@ int C_PointBlobContainer::DrawModel(int flags)
|
||||
//pos = Vector(edgeVertices[triTable[cubeIndex][k + 1]].position.x, edgeVertices[triTable[cubeIndex][k + 1]].position.y, edgeVertices[triTable[cubeIndex][k + 1]].position.z);
|
||||
//vertnormal = Vector(edgeVertices[triTable[cubeIndex][k + 1]].normal.x, edgeVertices[triTable[cubeIndex][k + 1]].normal.y, edgeVertices[triTable[cubeIndex][k + 1]].normal.z);
|
||||
|
||||
meshBuilder.Normal3fv(edgeVertices[triTable[cubeIndex][k + 1]].normal.Base());
|
||||
meshBuilder.Position3fv(edgeVertices[triTable[cubeIndex][k + 1]].position.Base());
|
||||
meshBuilder.Normal3fv(e1.normal.Base());
|
||||
meshBuilder.Position3fv(e1.position.Base());
|
||||
meshBuilder.TexCoord2f(0, 1, 0);
|
||||
meshBuilder.Color3f(0, 1, 0);
|
||||
meshBuilder.AdvanceVertex();
|
||||
@@ -178,8 +199,8 @@ int C_PointBlobContainer::DrawModel(int flags)
|
||||
//pos = Vector(edgeVertices[triTable[cubeIndex][k + 2]].position.x, edgeVertices[triTable[cubeIndex][k + 2]].position.y, edgeVertices[triTable[cubeIndex][k + 2]].position.z);
|
||||
//vertnormal = Vector(edgeVertices[triTable[cubeIndex][k + 2]].normal.x, edgeVertices[triTable[cubeIndex][k + 2]].normal.y, edgeVertices[triTable[cubeIndex][k + 2]].normal.z);
|
||||
|
||||
meshBuilder.Normal3fv(edgeVertices[triTable[cubeIndex][k + 2]].normal.Base());
|
||||
meshBuilder.Position3fv(edgeVertices[triTable[cubeIndex][k + 2]].position.Base());
|
||||
meshBuilder.Normal3fv(e2.normal.Base());
|
||||
meshBuilder.Position3fv(e2.position.Base());
|
||||
meshBuilder.TexCoord2f(0, 0, 1);
|
||||
meshBuilder.Color3f(0, 0, 1);
|
||||
meshBuilder.AdvanceVertex();
|
||||
@@ -283,7 +304,6 @@ void C_PointBlobContainer::UpdateContainer()
|
||||
|
||||
if (cl_blobs_updatecontainers.GetBool())
|
||||
{
|
||||
|
||||
//clear the field
|
||||
for (size_t i = 0; i < cubeGrid.numVertices; i++)
|
||||
{
|
||||
@@ -317,10 +337,10 @@ void C_PointBlobContainer::Simulate()
|
||||
{
|
||||
cubeGrid.Init(GridSize, GetAbsOrigin(), GridBounds);
|
||||
|
||||
for(size_t i=0; i<6; i++)
|
||||
for(size_t i = 0; i < 6; i++)
|
||||
{
|
||||
//white[i] = Vector(RemapVal(color.GetR(), 0, 255, 0, 1) * colorBoost, RemapVal(color.GetG(), 0, 255, 0, 1) * colorBoost, RemapVal(color.GetB(), 0, 255, 0, 1) * colorBoost);
|
||||
white[i] = Vector(((float)Ambcolor.GetR()/255) * colorBoost, ((float)Ambcolor.GetG()/255) * colorBoost, ((float)Ambcolor.GetB()/255) * colorBoost);
|
||||
white[i] = Vector((Ambcolor.GetR() / 255.0f) * colorBoost, (Ambcolor.GetG() / 255.0f) * colorBoost, (Ambcolor.GetB() / 255.0f) * colorBoost);
|
||||
//white[i] = Vector((Ambcolor.GetR()/0xFF) * colorBoost, (Ambcolor.GetG()/0xFF) * colorBoost, (Ambcolor.GetB()/0xFF) * colorBoost);
|
||||
//white[i] = Vector(1 * colorBoost,1 * colorBoost,1 * colorBoost);
|
||||
}
|
||||
@@ -346,7 +366,3 @@ void C_PointBlobContainer::Simulate()
|
||||
// GridSize = cl_blobs_resolution.GetInt();
|
||||
//}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user