| 1 |
/* |
| 2 |
* |
| 3 |
* Copyright (C) 2000 Silicon Graphics, Inc. All Rights Reserved. |
| 4 |
* |
| 5 |
* This library is free software; you can redistribute it and/or |
| 6 |
* modify it under the terms of the GNU Lesser General Public |
| 7 |
* License as published by the Free Software Foundation; either |
| 8 |
* version 2.1 of the License, or (at your option) any later version. |
| 9 |
* |
| 10 |
* This library is distributed in the hope that it will be useful, |
| 11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 |
* Lesser General Public License for more details. |
| 14 |
* |
| 15 |
* Further, this software is distributed without any warranty that it is |
| 16 |
* free of the rightful claim of any third person regarding infringement |
| 17 |
* or the like. Any license provided herein, whether implied or |
| 18 |
* otherwise, applies only to this software file. Patent licenses, if |
| 19 |
* any, provided herein do not apply to combinations of this program with |
| 20 |
* other software, or any other product whatsoever. |
| 21 |
* |
| 22 |
* You should have received a copy of the GNU Lesser General Public |
| 23 |
* License along with this library; if not, write to the Free Software |
| 24 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 25 |
* |
| 26 |
* Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy, |
| 27 |
* Mountain View, CA 94043, or: |
| 28 |
* |
| 29 |
* http://www.sgi.com |
| 30 |
* |
| 31 |
* For further information regarding this notice, see: |
| 32 |
* |
| 33 |
* http://oss.sgi.com/projects/GenInfo/NoticeExplan/ |
| 34 |
* |
| 35 |
*/ |
| 36 |
|
| 37 |
/* |
| 38 |
* Copyright (C) 1990-93 Silicon Graphics, Inc. |
| 39 |
* |
| 40 |
_______________________________________________________________________ |
| 41 |
______________ S I L I C O N G R A P H I C S I N C . ____________ |
| 42 |
| |
| 43 |
| $Revision: 1.1.1.1 $ |
| 44 |
| |
| 45 |
| Classes: |
| 46 |
| SoEnvironmentV1 |
| 47 |
| |
| 48 |
| Author(s): Paul S. Strauss, Gavin Bell, David Mott |
| 49 |
| |
| 50 |
______________ S I L I C O N G R A P H I C S I N C . ____________ |
| 51 |
_______________________________________________________________________ |
| 52 |
*/ |
| 53 |
|
| 54 |
#include "Util.h" |
| 55 |
#include "SoEnvironmentV1.h" |
| 56 |
#include <Inventor/nodes/SoEnvironment.h> |
| 57 |
|
| 58 |
SO_NODE_SOURCE(SoEnvironmentV1); |
| 59 |
|
| 60 |
//////////////////////////////////////////////////////////////////////// |
| 61 |
// |
| 62 |
// Description: |
| 63 |
// Default constructor |
| 64 |
// |
| 65 |
// Use: public |
| 66 |
|
| 67 |
SoEnvironmentV1::SoEnvironmentV1() |
| 68 |
// |
| 69 |
//////////////////////////////////////////////////////////////////////// |
| 70 |
{ |
| 71 |
SO_NODE_CONSTRUCTOR(SoEnvironmentV1); |
| 72 |
|
| 73 |
SO_NODE_ADD_FIELD(ambientIntensity, (0.2)); |
| 74 |
SO_NODE_ADD_FIELD(ambientColor, (1.0, 1.0, 1.0)); |
| 75 |
SO_NODE_ADD_FIELD(attenuation, (0.0, 0.0, 1.0)); |
| 76 |
SO_NODE_ADD_FIELD(fogType, (NONE)); |
| 77 |
SO_NODE_ADD_FIELD(fogComputed, (PER_VERTEX)); |
| 78 |
SO_NODE_ADD_FIELD(fogColor, (1.0, 1.0, 1.0)); |
| 79 |
SO_NODE_ADD_FIELD(fogDensity, (0.0)); |
| 80 |
SO_NODE_ADD_FIELD(fogNearDistance, (1.0)); |
| 81 |
SO_NODE_ADD_FIELD(fogFarDistance, (10.0)); |
| 82 |
|
| 83 |
// Set up static info for enumerated type fields |
| 84 |
SO_NODE_DEFINE_ENUM_VALUE(Type, NONE); |
| 85 |
SO_NODE_DEFINE_ENUM_VALUE(Type, LINEAR); |
| 86 |
SO_NODE_DEFINE_ENUM_VALUE(Type, EXPONENTIAL); |
| 87 |
SO_NODE_DEFINE_ENUM_VALUE(Type, EXPONENTIAL_SQUARED); |
| 88 |
SO_NODE_DEFINE_ENUM_VALUE(Computed, PER_VERTEX); |
| 89 |
SO_NODE_DEFINE_ENUM_VALUE(Computed, PER_PIXEL); |
| 90 |
|
| 91 |
// Set up info in enumerated type fields |
| 92 |
SO_NODE_SET_SF_ENUM_TYPE(fogType, Type); |
| 93 |
SO_NODE_SET_SF_ENUM_TYPE(fogComputed, Computed); |
| 94 |
|
| 95 |
isBuiltIn = TRUE; |
| 96 |
} |
| 97 |
|
| 98 |
//////////////////////////////////////////////////////////////////////// |
| 99 |
// |
| 100 |
// Description: |
| 101 |
// This initializes the SoEnvironment class. |
| 102 |
// |
| 103 |
// Use: internal |
| 104 |
|
| 105 |
void |
| 106 |
SoEnvironmentV1::initClass() |
| 107 |
// |
| 108 |
//////////////////////////////////////////////////////////////////////// |
| 109 |
{ |
| 110 |
SO__NODE_INIT_CLASS(SoEnvironmentV1, "Environment", SoNode); |
| 111 |
} |
| 112 |
|
| 113 |
//////////////////////////////////////////////////////////////////////// |
| 114 |
// |
| 115 |
// Description: |
| 116 |
// Copy version 1.0 fields from the passed 2.0 node. |
| 117 |
// |
| 118 |
// Use: public |
| 119 |
// |
| 120 |
SoNode * |
| 121 |
SoEnvironmentV1::downgrade(SoEnvironment *env2) |
| 122 |
// |
| 123 |
//////////////////////////////////////////////////////////////////////// |
| 124 |
{ |
| 125 |
SoEnvironmentV1 *env1 = new SoEnvironmentV1; |
| 126 |
|
| 127 |
// Convert from 2.0 enum to 1.0 enum |
| 128 |
if (! env2->fogType.isDefault()) { |
| 129 |
switch ((Type) env2->fogType.getValue()) { |
| 130 |
case SoEnvironment::NONE: |
| 131 |
env1->fogType = NONE; |
| 132 |
break; |
| 133 |
case SoEnvironment::HAZE: |
| 134 |
env1->fogType = LINEAR; |
| 135 |
break; |
| 136 |
case SoEnvironment::SMOKE: |
| 137 |
env1->fogType = EXPONENTIAL; |
| 138 |
break; |
| 139 |
case SoEnvironment::FOG: |
| 140 |
env1->fogType = EXPONENTIAL_SQUARED; |
| 141 |
break; |
| 142 |
} |
| 143 |
} |
| 144 |
|
| 145 |
// fogComputed is ignored totally in 2.0 |
| 146 |
|
| 147 |
// Set other fields as is |
| 148 |
COPY_FIELD(env1, env2, ambientIntensity); |
| 149 |
COPY_FIELD(env1, env2, ambientColor); |
| 150 |
COPY_FIELD(env1, env2, attenuation); |
| 151 |
COPY_FIELD(env1, env2, fogColor); |
| 152 |
|
| 153 |
// Convert visibility to density |
| 154 |
if (! env2->fogVisibility.isDefault()) { |
| 155 |
if (env2->fogType.getValue() == SoEnvironment::SMOKE) |
| 156 |
env1->fogDensity = 2.0 / env2->fogVisibility.getValue(); |
| 157 |
else |
| 158 |
env1->fogDensity = 4.0 / env2->fogVisibility.getValue(); |
| 159 |
|
| 160 |
if (env2->fogVisibility.isIgnored()) |
| 161 |
env1->fogDensity.setIgnored(TRUE); |
| 162 |
} |
| 163 |
|
| 164 |
// Near and far distances are ignored, since they now (typically) |
| 165 |
// use the camera planes |
| 166 |
|
| 167 |
return env1; |
| 168 |
} |