[4] | 1 | /********************************************************************************
|
---|
| 2 | * Volatile - Volume Visualization Software for SAGE
|
---|
| 3 | * Copyright (C) 2004 Electronic Visualization Laboratory,
|
---|
| 4 | * University of Illinois at Chicago
|
---|
| 5 | *
|
---|
| 6 | * All rights reserved.
|
---|
| 7 | *
|
---|
| 8 | * Redistribution and use in source and binary forms, with or without
|
---|
| 9 | * modification, are permitted provided that the following conditions are met:
|
---|
| 10 | *
|
---|
| 11 | * * Redistributions of source code must retain the above copyright
|
---|
| 12 | * notice, this list of conditions and the following disclaimer.
|
---|
| 13 | * * Redistributions in binary form must reproduce the above
|
---|
| 14 | * copyright notice, this list of conditions and the following disclaimer
|
---|
| 15 | * in the documentation and/or other materials provided with the distribution.
|
---|
| 16 | * * Neither the name of the University of Illinois at Chicago nor
|
---|
| 17 | * the names of its contributors may be used to endorse or promote
|
---|
| 18 | * products derived from this software without specific prior written permission.
|
---|
| 19 | *
|
---|
| 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
---|
| 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
---|
| 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
---|
| 23 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
---|
| 24 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
---|
| 25 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
---|
| 26 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
---|
| 27 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
---|
| 28 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
---|
| 29 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
---|
| 30 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
| 31 | *
|
---|
| 32 | * Direct questions, comments etc about Volatile to www.evl.uic.edu/cavern/forum
|
---|
| 33 | *********************************************************************************/s
|
---|
| 34 |
|
---|
| 35 | #include "vCut.h"
|
---|
| 36 | #include "MatrixMath.h"
|
---|
| 37 | #include "global.h"
|
---|
| 38 |
|
---|
| 39 | vCut::vCut() {
|
---|
| 40 | }
|
---|
| 41 |
|
---|
| 42 |
|
---|
| 43 |
|
---|
| 44 | //called from textures draw
|
---|
| 45 | void vCut::setTransform(float objectXform[]) {
|
---|
| 46 | float temp[3];
|
---|
| 47 | temp[0]=objectXform[0]*global.cut.axis[0]+
|
---|
| 48 | objectXform[4]*global.cut.axis[1]+objectXform[8]*global.cut.axis[2];
|
---|
| 49 | temp[1]=objectXform[1]*global.cut.axis[0]+
|
---|
| 50 | objectXform[5]*global.cut.axis[1]+objectXform[9]*global.cut.axis[2];
|
---|
| 51 | temp[2]=objectXform[2]*global.cut.axis[0]+
|
---|
| 52 | objectXform[6]*global.cut.axis[1]+objectXform[10]*global.cut.axis[2];
|
---|
| 53 | computeMatrix(global.cut.angle,temp,&global.cut.transform[0]);
|
---|
| 54 | }
|
---|
| 55 |
|
---|
| 56 |
|
---|
| 57 | void vCut::disable() {
|
---|
| 58 | glDisable(GL_CLIP_PLANE0);
|
---|
| 59 | }
|
---|
| 60 |
|
---|
| 61 | void vCut::enable() {
|
---|
| 62 | global.cut.user[0] = -global.cut.transform[0];
|
---|
| 63 | global.cut.user[1]=global.cut.transform[1];
|
---|
| 64 | global.cut.user[2]=-global.cut.transform[2];
|
---|
| 65 |
|
---|
| 66 | // fprintf(stderr,"cut plane %f %f %f %f\n",global.cut.user[0],global.cut.user[1],
|
---|
| 67 | // global.cut.user[2], global.cut.user[3]);
|
---|
| 68 | //create the points for the corners of the clip plane
|
---|
| 69 | for (int ii=0;ii<4;ii++){
|
---|
| 70 | plane[ii*3+0]=global.cut.transform[0]*global.cut.user[3];
|
---|
| 71 | plane[ii*3+1]=-global.cut.transform[1]*global.cut.user[3];
|
---|
| 72 | plane[ii*3+2]=global.cut.transform[2]*global.cut.user[3];
|
---|
| 73 | plane[ii*3+0]-=global.cut.transform[4]*((ii<2)?0.5f:-0.5f);
|
---|
| 74 | plane[ii*3+1] +=global.cut.transform[5]*((ii<2)?0.5f:-0.5f);
|
---|
| 75 | plane[ii*3+2]-=global.cut.transform[6]*((ii<2)?0.5f:-0.5f);
|
---|
| 76 | plane[ii*3+0]-=global.cut.transform[8]*((ii&0x1)?-0.5f:0.5f);
|
---|
| 77 | plane[ii*3+1]+=global.cut.transform[9]*((ii&0x1)?-0.5f:0.5f);
|
---|
| 78 | plane[ii*3+2]-=global.cut.transform[10]*((ii&0x1)?-0.5f:0.5f);
|
---|
| 79 | }
|
---|
| 80 |
|
---|
| 81 | //configure the clip planes
|
---|
| 82 | glClipPlane(GL_CLIP_PLANE0,global.cut.user);
|
---|
| 83 | glEnable(GL_CLIP_PLANE0);
|
---|
| 84 | }
|
---|
| 85 |
|
---|
| 86 | void vCut::draw() {
|
---|
| 87 | glEnable(GL_TEXTURE_3D);
|
---|
| 88 | glDepthMask(GL_FALSE);
|
---|
| 89 | glPolygonMode(GL_FRONT, GL_LINE);
|
---|
| 90 | glPolygonMode(GL_BACK, GL_LINE);
|
---|
| 91 | glBegin(GL_QUADS);
|
---|
| 92 | glVertex3fv(&plane[0]);
|
---|
| 93 | glVertex3fv(&plane[3]);
|
---|
| 94 | glVertex3fv(&plane[9]);
|
---|
| 95 | glVertex3fv(&plane[6]);
|
---|
| 96 | glEnd();
|
---|
| 97 | glDepthMask(GL_TRUE);
|
---|
| 98 |
|
---|
| 99 | glDisable(GL_ALPHA_TEST);
|
---|
| 100 | glDisable(GL_TEXTURE_3D);
|
---|
| 101 |
|
---|
| 102 | glBegin(GL_LINES); //draw clip plane
|
---|
| 103 | glColor3f(1.0f,0.0f,0.0f);
|
---|
| 104 | glVertex3fv(&plane[0]);
|
---|
| 105 | glVertex3fv(&plane[3]);
|
---|
| 106 | glVertex3fv(&plane[3]);
|
---|
| 107 | glVertex3fv(&plane[9]);
|
---|
| 108 | glVertex3fv(&plane[9]);
|
---|
| 109 | glVertex3fv(&plane[6]);
|
---|
| 110 | glVertex3fv(&plane[6]);
|
---|
| 111 | glVertex3fv(&plane[0]);
|
---|
| 112 | glEnd();
|
---|
| 113 | }
|
---|