light: move some helper functions to common/bsputils.{h,cc}
This commit is contained in:
parent
9004bed24e
commit
1a0fb22e40
|
|
@ -23,7 +23,8 @@ set(COMMON_INCLUDES
|
|||
${CMAKE_SOURCE_DIR}/include/common/scriplib.h
|
||||
${CMAKE_SOURCE_DIR}/include/common/threads.h
|
||||
${CMAKE_SOURCE_DIR}/include/common/trilib.h
|
||||
${CMAKE_SOURCE_DIR}/include/common/wadlib.h)
|
||||
${CMAKE_SOURCE_DIR}/include/common/wadlib.h
|
||||
${CMAKE_SOURCE_DIR}/include/common/bsputils.h)
|
||||
|
||||
find_package (Threads)
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,63 @@
|
|||
/* Copyright (C) 1996-1997 Id Software, Inc.
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
See file, 'COPYING', for details.
|
||||
*/
|
||||
|
||||
#include <common/bsputils.h>
|
||||
#include <assert.h>
|
||||
|
||||
/* small helper that just retrieves the correct vertex from face->surfedge->edge lookups */
|
||||
int GetSurfaceVertex(const bsp2_t *bsp, const bsp2_dface_t *f, int v)
|
||||
{
|
||||
int edge = f->firstedge + v;
|
||||
edge = bsp->dsurfedges[edge];
|
||||
if (edge < 0)
|
||||
return bsp->dedges[-edge].v[1];
|
||||
return bsp->dedges[edge].v[0];
|
||||
}
|
||||
|
||||
static void
|
||||
Vertex_GetPos(const bsp2_t *bsp, int num, vec3_t out)
|
||||
{
|
||||
assert(num >= 0 && num < bsp->numvertexes);
|
||||
const dvertex_t *v = &bsp->dvertexes[num];
|
||||
|
||||
for (int i=0; i<3; i++)
|
||||
out[i] = v->point[i];
|
||||
}
|
||||
|
||||
void
|
||||
Face_Normal(const bsp2_t *bsp, const bsp2_dface_t *f, vec3_t norm)
|
||||
{
|
||||
if (f->side)
|
||||
VectorSubtract(vec3_origin, bsp->dplanes[f->planenum].normal, norm);
|
||||
else
|
||||
VectorCopy(bsp->dplanes[f->planenum].normal, norm);
|
||||
}
|
||||
|
||||
plane_t
|
||||
Face_Plane(const bsp2_t *bsp, const bsp2_dface_t *f)
|
||||
{
|
||||
const int vertnum = GetSurfaceVertex(bsp, f, 0);
|
||||
vec3_t vertpos;
|
||||
Vertex_GetPos(bsp, vertnum, vertpos);
|
||||
|
||||
plane_t res;
|
||||
Face_Normal(bsp, f, res.normal);
|
||||
res.dist = DotProduct(vertpos, res.normal);
|
||||
return res;
|
||||
}
|
||||
|
|
@ -0,0 +1,38 @@
|
|||
/* Copyright (C) 1996-1997 Id Software, Inc.
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
See file, 'COPYING', for details.
|
||||
*/
|
||||
|
||||
#ifndef __COMMON_BSPUTILS_H__
|
||||
#define __COMMON_BSPUTILS_H__
|
||||
|
||||
#include <common/bspfile.h>
|
||||
#include <common/mathlib.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
int GetSurfaceVertex(const bsp2_t *bsp, const bsp2_dface_t *f, int v);
|
||||
void Face_Normal(const bsp2_t *bsp, const bsp2_dface_t *f, vec3_t norm);
|
||||
plane_t Face_Plane(const bsp2_t *bsp, const bsp2_dface_t *f);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __COMMON_BSPUTILS_H__ */
|
||||
|
|
@ -655,10 +655,7 @@ lockable_setting_t *FindSetting(std::string name);
|
|||
void SetGlobalSetting(std::string name, std::string value, bool cmdline);
|
||||
void GetFileSpace(byte **lightdata, byte **colordata, byte **deluxdata, int size);
|
||||
const modelinfo_t *ModelInfoForFace(const bsp2_t *bsp, int facenum);
|
||||
int GetSurfaceVertex(const bsp2_t *bsp, const bsp2_dface_t *f, int v);
|
||||
void Face_Normal(const bsp2_t *bsp, const bsp2_dface_t *f, vec3_t norm);
|
||||
const vec_t *GetSurfaceVertexNormal(const bsp2_t *bsp, const bsp2_dface_t *f, const int v);
|
||||
plane_t Face_Plane(const bsp2_t *bsp, const bsp2_dface_t *f);
|
||||
const bsp2_dface_t *Face_EdgeIndexSmoothed(const bsp2_t *bsp, const bsp2_dface_t *f, const int edgeindex);
|
||||
const std::vector<bouncelight_t> &BounceLights();
|
||||
bool Leaf_HasSky(const bsp2_t *bsp, const bsp2_dleaf_t *leaf);
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ set(LIGHT_SOURCES
|
|||
${CMAKE_SOURCE_DIR}/common/log.c
|
||||
${CMAKE_SOURCE_DIR}/common/threads.c
|
||||
${CMAKE_SOURCE_DIR}/common/polylib.c
|
||||
${CMAKE_SOURCE_DIR}/common/bsputils.cc
|
||||
${COMMON_INCLUDES}
|
||||
${LIGHT_INCLUDES})
|
||||
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@
|
|||
#include <light/ltface.hh>
|
||||
|
||||
#include <common/polylib.h>
|
||||
#include <common/bsputils.h>
|
||||
|
||||
#ifdef HAVE_EMBREE
|
||||
#include <xmmintrin.h>
|
||||
|
|
@ -454,24 +455,6 @@ AddTriangleNormals(std::map<int, vec3_struct_t> &smoothed_normals, const vec_t *
|
|||
weight = AngleBetweenPoints(p1, p3, p2);
|
||||
VectorMA(smoothed_normals[v3].v, weight, norm, smoothed_normals[v3].v);
|
||||
}
|
||||
/* small helper that just retrieves the correct vertex from face->surfedge->edge lookups */
|
||||
int GetSurfaceVertex(const bsp2_t *bsp, const bsp2_dface_t *f, int v)
|
||||
{
|
||||
int edge = f->firstedge + v;
|
||||
edge = bsp->dsurfedges[edge];
|
||||
if (edge < 0)
|
||||
return bsp->dedges[-edge].v[1];
|
||||
return bsp->dedges[edge].v[0];
|
||||
}
|
||||
|
||||
void
|
||||
Face_Normal(const bsp2_t *bsp, const bsp2_dface_t *f, vec3_t norm)
|
||||
{
|
||||
if (f->side)
|
||||
VectorSubtract(vec3_origin, bsp->dplanes[f->planenum].normal, norm);
|
||||
else
|
||||
VectorCopy(bsp->dplanes[f->planenum].normal, norm);
|
||||
}
|
||||
|
||||
/* access the final phong-shaded vertex normal */
|
||||
const vec_t *GetSurfaceVertexNormal(const bsp2_t *bsp, const bsp2_dface_t *f, const int vertindex)
|
||||
|
|
@ -495,29 +478,6 @@ FacesOnSamePlane(const std::vector<const bsp2_dface_t *> &faces)
|
|||
return true;
|
||||
}
|
||||
|
||||
static void
|
||||
Vertex_GetPos(const bsp2_t *bsp, int num, vec3_t out)
|
||||
{
|
||||
assert(num >= 0 && num < bsp->numvertexes);
|
||||
const dvertex_t *v = &bsp->dvertexes[num];
|
||||
|
||||
for (int i=0; i<3; i++)
|
||||
out[i] = v->point[i];
|
||||
}
|
||||
|
||||
plane_t
|
||||
Face_Plane(const bsp2_t *bsp, const bsp2_dface_t *f)
|
||||
{
|
||||
const int vertnum = GetSurfaceVertex(bsp, f, 0);
|
||||
vec3_t vertpos;
|
||||
Vertex_GetPos(bsp, vertnum, vertpos);
|
||||
|
||||
plane_t res;
|
||||
Face_Normal(bsp, f, res.normal);
|
||||
res.dist = DotProduct(vertpos, res.normal);
|
||||
return res;
|
||||
}
|
||||
|
||||
const bsp2_dface_t *
|
||||
Face_EdgeIndexSmoothed(const bsp2_t *bsp, const bsp2_dface_t *f, const int edgeindex)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -22,6 +22,8 @@
|
|||
#include <light/trace.hh>
|
||||
#include <light/ltface.hh>
|
||||
|
||||
#include <common/bsputils.h>
|
||||
|
||||
#include <cassert>
|
||||
|
||||
static void
|
||||
|
|
|
|||
Loading…
Reference in New Issue