Loading...
Searching...
No Matches
gsd_cplane.c
Go to the documentation of this file.
/*!
\file lib/ogsf/gsd_cplane.c
\brief OGSF library - manipulating surfaces (lower level functions)
GRASS OpenGL gsurf OGSF Library
(C) 1999-2008 by the GRASS Development Team
This program is free software under the
GNU General Public License (>=v2).
Read the file COPYING that comes with GRASS
for details.
\author Bill Brown USACERL, GMSL/University of Illinois (January 1993)
\author Doxygenized by Martin Landa <landa.martin gmail.com> (May 2008)
*/
#include <grass/ogsf.h>
#include "rowcol.h"
static void init_cplane(void);
static float Cp_pt[4], Cp_norm[MAX_CPLANES][4];
static float Cp_trans[MAX_CPLANES][3], Cp_rot[MAX_CPLANES][3];
static int Cp_ison[MAX_CPLANES]; /* also need isdef? */
static void init_cplane(void)
{
int i;
gs_get_datacenter(Cp_pt);
gs_get_data_avg_zmax(&(Cp_pt[Z]));
for (i = 0; i < MAX_CPLANES; i++) {
Cp_ison[i] = 0;
Cp_norm[i][X] = 1.0;
Cp_norm[i][Y] = Cp_norm[i][Z] = 0.0;
Cp_norm[i][W] = 1.;
Cp_rot[i][X] = Cp_trans[i][X] = 0.0;
Cp_rot[i][Y] = Cp_trans[i][Y] = 0.0;
Cp_rot[i][Z] = Cp_trans[i][Z] = 0.0;
}
return;
}
/*!
\brief Define cplace
\param num
\param pt
\param norm
*/
void gsd_def_cplane(int num, float *pt, float *norm)
{
float sx, sy, sz, ppt[3];
double params[4];
float zmin, zmax;
GS_get_scale(&sx, &sy, &sz, 1);
/* Something's still wrong with the zexag - DONT USE TILT */
GS_get_zrange(&zmin, &zmax, 0);
ppt[0] = (pt[0] + Cp_pt[0]) * sx;
ppt[1] = (pt[1] + Cp_pt[1]) * sy;
ppt[2] = (pt[2] + Cp_pt[2] - zmin) * sz;
params[0] = norm[0] * sx;
params[1] = norm[1] * sy;
params[2] = norm[2] * sz;
GS_dv3norm(params);
params[3] = -ppt[0] * params[0] - ppt[1] * params[1] - ppt[2] * params[2];
gsd_def_clipplane(num, params);
return;
}
/*!
\brief Update cplaces
Called when viewing matrix changes
*/
void gsd_update_cplanes(void)
{
int i;
for (i = 0; i < MAX_CPLANES; i++) {
if (Cp_ison[i]) {
gsd_def_cplane(i, Cp_trans[i], Cp_norm[i]);
}
}
return;
}
/*!
\brief ADD
\param num
*/
void gsd_cplane_on(int num)
{
static int first = 1;
if (first) {
first = 0;
init_cplane();
gsd_def_cplane(num, Cp_trans[num], Cp_norm[num]);
}
gsd_set_clipplane(num, 1);
Cp_ison[num] = 1;
return;
}
/*!
\brief Turn off clip plane
\param num cplane id
*/
void gsd_cplane_off(int num)
{
gsd_set_clipplane(num, 0);
Cp_ison[num] = 0;
return;
}
/*!
\brief Get cplane state
<i>onstate</i> MUST be big enough to hold MAX_CPLANES ints
\param onstate
*/
void gsd_get_cplanes_state(int *onstate)
{
int i;
for (i = 0; i < MAX_CPLANES; i++) {
onstate[i] = Cp_ison[i];
}
return;
}
/*!
\brief Get cplaces
Planes MUST be big enough to hold MAX_CPLANES Point4s
\param planes surface coordinates, normal pointing away from visible side
\return ADD
*/
int gsd_get_cplanes(Point4 *planes)
{
int i, ons;
Point3 thru;
for (ons = i = 0; i < MAX_CPLANES; i++) {
if (Cp_ison[i]) {
thru[X] = Cp_pt[X] + Cp_trans[ons][X];
thru[Y] = Cp_pt[Y] + Cp_trans[ons][Y];
thru[Z] = Cp_pt[Z] + Cp_trans[ons][Z];
planes[ons][X] = -Cp_norm[ons][X];
planes[ons][Y] = -Cp_norm[ons][Y];
planes[ons][Z] = -Cp_norm[ons][Z];
planes[ons][W] = -(DOT3(planes[ons], thru));
ons++;
}
}
return (ons);
}
/*!
\brief ADD
\param num
*/
void gsd_update_cpnorm(int num)
{
float v[1][4];
v[0][X] = v[0][W] = 1.0;
v[0][Y] = v[0][Z] = 0.0;
P_pushmatrix();
P_rot(Cp_rot[num][Z], 'z');
P_rot(Cp_rot[num][Y], 'y');
P_rot(Cp_rot[num][X], 'x');
P_transform(1, v, &Cp_norm[num]);
P_popmatrix();
return;
}
/*!
\brief ADD
\param num
\param rx,ry,rz
*/
void gsd_cplane_setrot(int num, float rx, float ry, float rz)
{
Cp_rot[num][X] = rx;
Cp_rot[num][Y] = ry;
Cp_rot[num][Z] = rz;
gsd_update_cpnorm(num);
gsd_def_cplane(num, Cp_trans[num], Cp_norm[num]);
return;
}
/*!
\brief ADD
\param num
\param tx,ty,tz
*/
void gsd_cplane_settrans(int num, float tx, float ty, float tz)
{
Cp_trans[num][X] = tx;
Cp_trans[num][Y] = ty;
Cp_trans[num][Z] = tz;
gsd_def_cplane(num, Cp_trans[num], Cp_norm[num]);
return;
}
/*!
\brief ADD
\param surf1 first surface (geosurf)
\param surf2 second surface (geosurf) [unused]
\param cpnum
*/
void gsd_draw_cplane_fence(geosurf *surf1, geosurf *surf2 G_UNUSED, int cpnum)
{
int was_on;
float len, dir[3], bgn[2], end[2], px, py, fencenorm[3];
/* temporarily turn this plane off */
if ((was_on = Cp_ison[cpnum])) {
gsd_set_clipplane(cpnum, 0);
}
/* line on surface (assuming NO TILT) is (-A,B)->(A,-B),
extended thru Cp_pt */
dir[X] = -Cp_norm[cpnum][Y];
dir[Y] = Cp_norm[cpnum][X];
dir[Z] = 0.0;
GS_v3norm(dir);
px = Cp_trans[cpnum][X] + Cp_pt[X];
py = Cp_trans[cpnum][Y] + Cp_pt[Y];
/* TODO: make line from point & direction, clip to region */
/* for now, to test: */
bgn[X] = px;
bgn[Y] = py;
end[X] = px;
end[Y] = 3 * VROW2Y(surf1, 0);
len = GS_P2distance(bgn, end) - 1;
bgn[X] = px + len * dir[X];
bgn[Y] = py + len * dir[Y];
end[X] = px - len * dir[X];
end[Y] = py - len * dir[Y];
fencenorm[X] = -Cp_norm[cpnum][X];
fencenorm[Y] = -Cp_norm[cpnum][Y];
fencenorm[Z] = -Cp_norm[cpnum][Z];
gsd_wall(bgn, end, fencenorm);
/* turn this plane back on */
if (was_on) {
gsd_set_clipplane(cpnum, 1);
}
return;
}
/*!
\brief Draw cplane
\param num
*/
void gsd_draw_cplane(int num)
{
float size, cpv[3];
int i;
float scalez;
unsigned long colr;
/* turn off all clipping planes */
for (i = 0; i < MAX_CPLANES; i++) {
if (Cp_ison[i]) {
gsd_set_clipplane(i, 0);
}
}
GS_get_longdim(&size);
size /= 2.;
cpv[X] = 0.0;
gsd_blend(1);
gsd_zwritemask(0x0);
gsd_pushmatrix();
gsd_do_scale(1);
gsd_translate(Cp_pt[X] + Cp_trans[num][X], Cp_pt[Y] + Cp_trans[num][Y],
Cp_pt[Z] + Cp_trans[num][Z]);
gsd_rot(Cp_rot[num][Z], 'z');
gsd_rot(Cp_rot[num][Y], 'y');
gsd_rot(Cp_rot[num][X], 'x');
if ((scalez = GS_global_exag())) {
gsd_scale(1.0, 1.0, 1. / scalez);
}
colr = (GS_default_draw_color() | 0xff000000) & 0x33ffffff;
gsd_color_func(colr);
gsd_bgnpolygon();
cpv[Y] = size;
cpv[Z] = size;
gsd_vert_func(cpv);
cpv[Y] = -size;
gsd_vert_func(cpv);
cpv[Z] = -size;
gsd_vert_func(cpv);
cpv[Y] = size;
gsd_vert_func(cpv);
gsd_endpolygon();
gsd_popmatrix();
gsd_blend(0);
gsd_zwritemask(0xffffffff);
/* turn on clipping planes */
for (i = 0; i < MAX_CPLANES; i++) {
if (Cp_ison[i]) {
gsd_set_clipplane(i, 1);
}
}
return;
}
GS_default_draw_color
unsigned int GS_default_draw_color(void)
Get default draw color.
Definition gs2.c:2439
GS_get_zrange
int GS_get_zrange(float *min, float *max, int doexag)
Get z-extent for all loaded surfaces.
Definition gs2.c:2688
GS_get_scale
void GS_get_scale(float *sx, float *sy, float *sz, int doexag)
Get axis scale.
Definition gs2.c:3239
GS_get_longdim
int GS_get_longdim(float *dim)
Get largest dimension.
Definition gs2.c:140
GS_global_exag
float GS_global_exag(void)
Get global z-exag value.
Definition gs2.c:2000
gs_get_datacenter
int gs_get_datacenter(float *cen)
Get data center point.
Definition gs.c:1230
gs_get_data_avg_zmax
int gs_get_data_avg_zmax(float *azmax)
Get average z-max value.
Definition gs.c:1201
GS_dv3norm
int GS_dv3norm(double *dv1)
Changes v1 so that it is a unit vector.
Definition gs_util.c:295
GS_v3norm
int GS_v3norm(float *v1)
Change v1 so that it is a unit vector (3D).
Definition gs_util.c:246
GS_P2distance
float GS_P2distance(float *from, float *to)
Calculate distance in plane.
Definition gs_util.c:160
gsd_cplane_off
void gsd_cplane_off(int num)
Turn off clip plane.
Definition gsd_cplane.c:126
gsd_get_cplanes_state
void gsd_get_cplanes_state(int *onstate)
Get cplane state.
Definition gsd_cplane.c:142
gsd_cplane_settrans
void gsd_cplane_settrans(int num, float tx, float ty, float tz)
ADD.
Definition gsd_cplane.c:229
gsd_get_cplanes
int gsd_get_cplanes(Point4 *planes)
Get cplaces.
Definition gsd_cplane.c:162
gsd_draw_cplane_fence
void gsd_draw_cplane_fence(geosurf *surf1, geosurf *surf2, int cpnum)
ADD.
Definition gsd_cplane.c:247
gsd_draw_cplane
void gsd_draw_cplane(int num)
Draw cplane.
Definition gsd_cplane.c:296
gsd_cplane_setrot
void gsd_cplane_setrot(int num, float rx, float ry, float rz)
ADD.
Definition gsd_cplane.c:211
gsd_update_cpnorm
void gsd_update_cpnorm(int num)
ADD.
Definition gsd_cplane.c:188
gsd_cplane_on
void gsd_cplane_on(int num)
ADD.
Definition gsd_cplane.c:104
gsd_def_cplane
void gsd_def_cplane(int num, float *pt, float *norm)
Define cplace.
Definition gsd_cplane.c:55
gsd_update_cplanes
void gsd_update_cplanes(void)
Update cplaces.
Definition gsd_cplane.c:86
gsd_set_clipplane
void gsd_set_clipplane(int num, int able)
Set clip plane.
Definition gsd_prim.c:1041
gsd_pushmatrix
void gsd_pushmatrix(void)
Push the current matrix stack.
Definition gsd_prim.c:511
gsd_zwritemask
void gsd_zwritemask(unsigned long n)
Write out z-mask.
Definition gsd_prim.c:241
gsd_vert_func
void gsd_vert_func(float *pt)
ADD.
Definition gsd_prim.c:686
gsd_bgnpolygon
void gsd_bgnpolygon(void)
Delimit the vertices of a primitive or a group of like primitives.
Definition gsd_prim.c:372
gsd_blend
void gsd_blend(int yesno)
Specify pixel arithmetic.
Definition gsd_prim.c:994
gsd_popmatrix
void gsd_popmatrix(void)
Pop the current matrix stack.
Definition gsd_prim.c:501
gsd_def_clipplane
void gsd_def_clipplane(int num, double *params)
Define clip plane.
Definition gsd_prim.c:1014
gsd_rot
void gsd_rot(float angle, char axis)
ADD.
Definition gsd_prim.c:605
gsd_scale
void gsd_scale(float xs, float ys, float zs)
Multiply the current matrix by a general scaling matrix.
Definition gsd_prim.c:525
gsd_translate
void gsd_translate(float dx, float dy, float dz)
Multiply the current matrix by a translation matrix.
Definition gsd_prim.c:539
gsd_color_func
void gsd_color_func(unsigned int col)
Set current color.
Definition gsd_prim.c:698
gsd_endpolygon
void gsd_endpolygon(void)
Delimit the vertices of a primitive or a group of like primitives.
Definition gsd_prim.c:387
gsd_wall
int gsd_wall(float *bgn, float *end, float *norm)
ADD.
Definition gsd_surf.c:1710
gsd_do_scale
void gsd_do_scale(int doexag)
Set current scale.
Definition gsd_views.c:355
rowcol.h
VROW2Y
#define VROW2Y(gs, vrow)
Definition rowcol.h:39
P_popmatrix
int P_popmatrix(void)
Pop top of matrix stack, placing it into the current transformation matrix.
Definition trans.c:188
P_transform
void P_transform(int num_vert, float(*in)[4], float(*out)[4])
Transform array of vectors using current T matrix.
Definition trans.c:107
P_rot
void P_rot(float angle, char axis)
Rotate matrix.
Definition trans.c:208
P_pushmatrix
int P_pushmatrix(void)
Push current transformation matrix onto matrix stack.
Definition trans.c:167
X
#define X(j)
Y
#define Y(j)