Disabled external gits

This commit is contained in:
2022-04-07 18:46:57 +02:00
parent 88cb3426ad
commit 15e7120d6d
5316 changed files with 4563444 additions and 6 deletions

View File

@@ -0,0 +1,147 @@
# Copyright (c) 2005-2020 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# The original source for this example is
# Copyright (c) 1994-2008 John E. Stone
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# 3. The name of the author may not be used to endorse or promote products
# derived from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
# Common Makefile that builds and runs example.
# Trying to find if icl.exe is set
CXX1 = $(TBB_CXX)-
CXX2 = $(CXX1:icl.exe-=icl.exe)
CXX = $(CXX2:-=cl.exe)
# Uncomment one of next lines to choose user interface type (console, gdiplus, direct draw)
#UI = con
UI = gdi
#UI = dd
# Machine architecture, auto-detected from TBB_TARGET_ARCH by default
# Use XARCH variable to change it. See index.html for more information
ARCH0 = $(TBB_TARGET_ARCH)-
ARCH1 = $(ARCH0:ia32-=x86)
ARCH2 = $(ARCH1:intel64-=AMD64)
XARCH = $(ARCH2:-=x86)
# The default runtime arguments
DATASET = balls
override ARGS := dat\$(DATASET).dat $(ARGS)
PERF_RUN_ARGS = silent dat\balls3.dat
LIGHT_ARGS = dat\model2.dat
# Add these for tbb/tbb1d release builds
# /GL is a workaround to prevent run-time crash when built by VS2010
CXXFLAGS_TBB_NDEBUG = $(CXXFLAGS) /GL
LIBS_TBB_NDEBUG = tbb.lib $(LIBS)
# Add these for tbb/tbb1d debug builds
CXXFLAGS_TBB_DEBUG = $(CXXFLAGS) /D TBB_USE_DEBUG
LIBS_TBB_DEBUG = tbb_debug.lib $(LIBS)
MAKEINC = ../../common/gui/Makefile.win
# scr/main.cpp src/tachyon_video.cpp cannot be included to the SOURCE_COMMON list since it depends on UI and /subsystem which is not specified for common SOURCE build
SOURCE = src/main.cpp src/tachyon_video.cpp
SOURCE_COMMON = src/pthread.cpp src/api.cpp src/apigeom.cpp src/apitrigeom.cpp src/bndbox.cpp src/box.cpp src/camera.cpp src/coordsys.cpp src/cylinder.cpp src/extvol.cpp src/global.cpp src/grid.cpp src/imageio.cpp src/imap.cpp src/intersect.cpp src/jpeg.cpp src/light.cpp src/objbound.cpp src/parse.cpp src/plane.cpp src/ppm.cpp src/quadric.cpp src/render.cpp src/ring.cpp src/shade.cpp src/sphere.cpp src/texture.cpp src/tgafile.cpp src/trace_rest.cpp src/triangle.cpp src/ui.cpp src/util.cpp src/vector.cpp src/vol.cpp
# Targets
all: build run
release: build
debug: build_debug
test: run
build: build_serial build_tbb1d build_tbb
build_debug: build_serial_debug build_tbb1d_debug build_tbb_debug
run: run_serial run_tbb1d run_tbb
serial: build_serial run_serial
serial_debug: build_serial_debug run_serial
tbb: build_tbb run_tbb
tbb_debug: build_tbb_debug run_tbb
tbb1d: build_tbb1d run_tbb1d
tbb1d_debug: build_tbb1d_debug run_tbb1d
CXXFLAGS_COMMON = /c /nologo /EHsc /Zc:forScope /D WIN32 /D _MBCS /D _CRT_SECURE_NO_DEPRECATE /Foobj/ /MP $(CXXFLAGS)
CXXFLAGS_NDEBUG = /MD /O2 /Ot /Gy /D NDEBUG
CXXFLAGS_DEBUG = /MDd /Od /Zi /D _DEBUG
LIB_LINK_FLAGS = /nologo /machine:$(XARCH)
tachyon_common.lib:
@cmd.exe /C if not exist obj mkdir obj
$(CXX) $(CXXFLAGS_NDEBUG) $(CXXFLAGS_COMMON) $(SOURCE_COMMON)
LIB $(LIB_LINK_FLAGS) obj/*.obj /OUT:$@
@cmd.exe /C if exist obj rmdir /S /Q obj
tachyon_common_debug.lib:
@cmd.exe /C if not exist obj mkdir obj
$(CXX) $(CXXFLAGS_DEBUG) $(CXXFLAGS_COMMON) $(SOURCE_COMMON)
LIB $(LIB_LINK_FLAGS) obj/*.obj /OUT:$@
@cmd.exe /C if exist obj rmdir /S /Q obj
build_serial: tachyon_common.lib
@$(MAKE) -f $(MAKEINC) SOURCE="src/trace.serial.cpp $(SOURCE) tachyon_common.lib" EXE=tachyon.serial.exe RCNAME=gui UI=$(UI) CXX="$(CXX)" CXXFLAGS="/GL $(CXXFLAGS)" XARCH=$(XARCH) build_one
build_serial_debug: tachyon_common_debug.lib
@$(MAKE) -f $(MAKEINC) SOURCE="src/trace.serial.cpp $(SOURCE) tachyon_common_debug.lib" EXE=tachyon.serial.exe RCNAME=gui UI=$(UI) DEBUG=_debug CXX="$(CXX)" CXXFLAGS=$(CXXFLAGS) XARCH=$(XARCH) build_one
run_serial:
-.\tachyon.serial.exe $(ARGS)
build_tbb: tachyon_common.lib
@$(MAKE) -f $(MAKEINC) SOURCE="src/trace.tbb.cpp $(SOURCE) tachyon_common.lib" EXE=tachyon.tbb.exe RCNAME=gui UI=$(UI) CXX="$(CXX)" CXXFLAGS="$(CXXFLAGS_TBB_NDEBUG)" LFLAGS="$(LIBS_TBB_NDEBUG)" XARCH=$(XARCH) build_one
build_tbb_debug: tachyon_common_debug.lib
@$(MAKE) -f $(MAKEINC) SOURCE="src/trace.tbb.cpp $(SOURCE) tachyon_common_debug.lib" EXE=tachyon.tbb.exe RCNAME=gui UI=$(UI) DEBUG=_debug CXX="$(CXX)" CXXFLAGS="$(CXXFLAGS_TBB_DEBUG)" LFLAGS="$(LIBS_TBB_DEBUG)" XARCH=$(XARCH) build_one
run_tbb:
-.\tachyon.tbb.exe $(ARGS)
build_tbb1d: tachyon_common.lib
@$(MAKE) -f $(MAKEINC) SOURCE="src/trace.tbb1d.cpp $(SOURCE) tachyon_common.lib" EXE=tachyon.tbb1d.exe RCNAME=gui UI=$(UI) CXX="$(CXX)" CXXFLAGS="$(CXXFLAGS_TBB_NDEBUG)" LFLAGS="$(LIBS_TBB_NDEBUG)" XARCH=$(XARCH) build_one
build_tbb1d_debug: tachyon_common_debug.lib
@$(MAKE) -f $(MAKEINC) SOURCE="src/trace.tbb1d.cpp $(SOURCE) tachyon_common_debug.lib" EXE=tachyon.tbb1d.exe RCNAME=gui UI=$(UI) DEBUG=_debug CXX="$(CXX)" CXXFLAGS="$(CXXFLAGS_TBB_DEBUG)" LFLAGS="$(LIBS_TBB_DEBUG)" XARCH=$(XARCH) build_one
run_tbb1d:
-.\tachyon.tbb1d.exe $(ARGS)
clean:
@cmd.exe /C del tachyon.* *.manifest *.obj *.lib msvs\gui.res *.?db
perf_build: tachyon_common.lib
@$(MAKE) -f $(MAKEINC) SOURCE="src/trace.tbb.cpp $(SOURCE) tachyon_common.lib" EXE=tachyon.tbb.exe RCNAME=gui UI=con CXX="$(CXX)" CXXFLAGS="$(CXXFLAGS_TBB_NDEBUG)" LFLAGS="$(LIBS_TBB_NDEBUG)" XARCH=$(XARCH) build_one
perf_run:
-.\tachyon.tbb.exe $(PERF_RUN_ARGS)
light_test:
-.\tachyon.tbb.exe $(LIGHT_ARGS)

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,104 @@
BEGIN_SCENE
OUTFILE /dev/null
RESOLUTION 512 512
VERBOSE 0
CAMERA
ZOOM 1.0
ASPECTRATIO 1.0
ANTIALIASING 1
RAYDEPTH 12
CENTER 0.0 0.0 -5.0
VIEWDIR 0.0 0.0 1.0
UPDIR 0.0 1.0 0.0
END_CAMERA
LIGHT
CENTER -5.0 0.0 -4.0
RAD 0.2
COLOR 1.0 0.1 0.0
LIGHT
CENTER 4.0 5.0 -4.0
RAD 0.2
COLOR 0.0 0.1 1.0
LIGHT
CENTER 4.0 1.5 3.0
RAD 0.2
COLOR 0.5 0.5 0.5
TRI
V0 0.0 -4.0 12.0
V1 4.0 -4.0 8.0
V2 -4.0 -4.0 8.0
TEXTURE
AMBIENT 0.1 DIFFUSE 0.2 SPECULAR 0.7 OPACITY 1.0
COLOR 1.0 1.0 1.0
TEXFUNC 0
SPHERE
CENTER 0.0 0.0 5.0
RAD 1.3
TEXTURE
AMBIENT 0.1 DIFFUSE 0.0 SPECULAR 0.9 OPACITY 1.0
COLOR 1.0 1.0 1.0
TEXFUNC 0
SPHERE
CENTER 1.0 0.0 4.3
RAD 0.8
TEXTURE
AMBIENT 0.1 DIFFUSE 0.9 SPECULAR 0.0 OPACITY 1.0
COLOR 0.3 0.3 1.0
TEXFUNC 3
CENTER 1.0 0.0 4.3
ROTATE 0. 0.0 0.0
SCALE 1.0 1.0 1.0
SPHERE
CENTER 0.0 2.0 8.0
RAD 1.0
TEXTURE
AMBIENT 0.1 DIFFUSE 0.9 SPECULAR 0.0 OPACITY 1.0
COLOR 1.0 0.0 1.0
TEXFUNC 4
CENTER 0.0 1.0 8.0
ROTATE 0. 0.0 0.0
SCALE 1.0 1.0 1.0
SPHERE
CENTER -1.0 -0.5 5.0
RAD 1.0
TEXTURE
AMBIENT 0.1 DIFFUSE 0.9 SPECULAR 0.0 OPACITY 1.0
COLOR 1.0 1.0 0.5
TEXFUNC 6
CENTER -1.0 -0.5 5.0
ROTATE 0. 0.0 0.0
SCALE 1.0 1.0 1.0
PLANE
CENTER 0.0 -5.0 0.0
NORMAL 0.0 1.0 0.0
TEXTURE
AMBIENT 0.1 DIFFUSE 0.9 SPECULAR 0.0 OPACITY 1.0
COLOR 1.0 1.0 1.0
TEXFUNC 1
CENTER 0.0 -5.0 0.0
ROTATE 0. 0.0 0.0
SCALE 1.0 1.0 1.0
PLANE
CENTER 0.0 0.0 15.0
NORMAL 0.0 0.0 -1.0
TEXTURE
AMBIENT 0.1 DIFFUSE 0.9 SPECULAR 0.0 OPACITY 1.0
COLOR 1.0 1.0 1.0
TEXFUNC 3
CENTER 0.0 0.0 15.0
ROTATE 0. 0.0 0.0
SCALE 1.0 1.0 1.0
END_SCENE

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,538 @@
BEGIN_SCENE
OUTFILE /dev/null
RESOLUTION 768 768
VERBOSE 0
CAMERA
ZOOM 1.0
ASPECTRATIO 1.0
ANTIALIASING 0
RAYDEPTH 4
CENTER 15.0 20.0 -50.0
VIEWDIR 0.0 0.0 1.0
UPDIR 0.0 1.0 0.0
END_CAMERA
LIGHT
CENTER 40.0 50.0 -40.0
RAD 0.2
COLOR 0.5 0.5 0.5
LIGHT
CENTER -40.0 20.0 -40.0
RAD 0.2
COLOR 0.5 0.5 0.5
TEXDEF O AMBIENT 0.1 DIFFUSE 0.9 SPECULAR 0.0 OPACITY 1.0
PHONG PLASTIC 0.5 PHONG_SIZE 24.8
COLOR 1.0 0.0 0.0 TEXFUNC 0
TEXALIAS OH O
TEXALIAS OD1 O
TEXALIAS OD2 O
TEXALIAS OE1 O
TEXALIAS OE2 O
TEXALIAS OG O
TEXALIAS OG1 O
TEXALIAS OG2 O
TEXALIAS OXT O
TEXDEF C AMBIENT 0.1 DIFFUSE 0.5 SPECULAR 0.0 OPACITY 1.0
PHONG PLASTIC 0.5 PHONG_SIZE 24.8
COLOR 0.5 0.5 0.5 TEXFUNC 0
TEXALIAS CA C
TEXALIAS CB C
TEXALIAS CD C
TEXALIAS CD1 C
TEXALIAS CD2 C
TEXALIAS CE C
TEXALIAS CE1 C
TEXALIAS CE2 C
TEXALIAS CG C
TEXALIAS CG1 C
TEXALIAS CG2 C
TEXALIAS CZ C
TEXDEF N AMBIENT 0.1 DIFFUSE 0.9 SPECULAR 0.0 OPACITY 1.0
PHONG PLASTIC 0.5 PHONG_SIZE 24.8
COLOR 0.5 0.5 1.0 TEXFUNC 0
TEXALIAS ND2 N
TEXALIAS NH1 N
TEXALIAS NH2 N
TEXALIAS NE N
TEXALIAS NE2 N
TEXALIAS NZ N
TEXDEF SD AMBIENT 0.1 DIFFUSE 0.9 SPECULAR 0.0 OPACITY 1.0
PHONG METAL 0.5 PHONG_SIZE 24.8
COLOR 1.0 1.0 1.0 TEXFUNC 0
TEXDEF SG AMBIENT 0.1 DIFFUSE 0.9 SPECULAR 0.0 OPACITY 1.0
PHONG PLASTIC 0.5 PHONG_SIZE 24.8
COLOR 1.0 1.0 1.0 TEXFUNC 0
SPHERE CENTER 26.465000 27.452000 -2.490000 RAD 1.0 N
SPHERE CENTER 25.497000 26.862000 -1.573000 RAD 1.0 CA
SPHERE CENTER 26.193001 26.179001 -0.437000 RAD 1.0 C
SPHERE CENTER 27.270000 25.549000 -0.624000 RAD 1.0 O
SPHERE CENTER 24.583000 25.804001 -2.239000 RAD 1.0 CB
SPHERE CENTER 25.091000 24.375000 -2.409000 RAD 1.0 CG
SPHERE CENTER 24.018999 23.427999 -2.996000 RAD 1.0 CD
SPHERE CENTER 23.591000 24.028000 -4.287000 RAD 1.0 NE
SPHERE CENTER 24.299000 23.972000 -5.389000 RAD 1.0 CZ
SPHERE CENTER 25.431999 23.261000 -5.440000 RAD 1.0 NH1
SPHERE CENTER 23.721001 24.372999 -6.467000 RAD 1.0 NH2
SPHERE CENTER 25.667000 26.396000 0.708000 RAD 1.0 N
SPHERE CENTER 26.222000 25.760000 1.891000 RAD 1.0 CA
SPHERE CENTER 26.207001 24.242001 1.830000 RAD 1.0 C
SPHERE CENTER 25.400000 23.576000 1.139000 RAD 1.0 O
SPHERE CENTER 25.260000 26.207001 3.033000 RAD 1.0 CB
SPHERE CENTER 24.511999 27.427999 2.493000 RAD 1.0 CG
SPHERE CENTER 24.606001 27.382000 0.978000 RAD 1.0 CD
SPHERE CENTER 27.170000 23.634001 2.462000 RAD 1.0 N
SPHERE CENTER 27.284000 22.163000 2.498000 RAD 1.0 CA
SPHERE CENTER 26.042999 21.506001 3.085000 RAD 1.0 C
SPHERE CENTER 25.752001 20.350000 2.705000 RAD 1.0 O
SPHERE CENTER 28.424999 21.747000 3.461000 RAD 1.0 CB
SPHERE CENTER 29.791000 21.886000 2.787000 RAD 1.0 CG
SPHERE CENTER 29.875000 22.104000 1.543000 RAD 1.0 OD1
SPHERE CENTER 30.806000 21.500999 3.431000 RAD 1.0 OD2
SPHERE CENTER 25.393999 22.184000 4.041000 RAD 1.0 N
SPHERE CENTER 24.172001 21.584999 4.618000 RAD 1.0 CA
SPHERE CENTER 23.009001 21.375000 3.624000 RAD 1.0 C
SPHERE CENTER 22.082001 20.603001 3.921000 RAD 1.0 O
SPHERE CENTER 23.691999 22.330999 5.862000 RAD 1.0 CB
SPHERE CENTER 23.191999 23.778999 5.639000 RAD 1.0 CG
SPHERE CENTER 21.961000 24.002001 5.060000 RAD 1.0 CD1
SPHERE CENTER 23.951000 24.841000 6.050000 RAD 1.0 CD2
SPHERE CENTER 21.497000 25.281000 4.869000 RAD 1.0 CE1
SPHERE CENTER 23.510000 26.124001 5.854000 RAD 1.0 CE2
SPHERE CENTER 22.277000 26.363001 5.249000 RAD 1.0 CZ
SPHERE CENTER 23.094999 22.004000 2.522000 RAD 1.0 N
SPHERE CENTER 22.106001 21.863001 1.467000 RAD 1.0 CA
SPHERE CENTER 22.191999 20.518000 0.830000 RAD 1.0 C
SPHERE CENTER 21.230000 20.068001 0.167000 RAD 1.0 O
SPHERE CENTER 22.358000 22.903999 0.371000 RAD 1.0 CB
SPHERE CENTER 22.145000 24.591999 0.888000 RAD 1.0 SG
SPHERE CENTER 23.326000 19.826000 1.008000 RAD 1.0 N
SPHERE CENTER 23.436001 18.459999 0.459000 RAD 1.0 CA
SPHERE CENTER 22.958000 17.365000 1.407000 RAD 1.0 C
SPHERE CENTER 22.938000 16.180000 0.999000 RAD 1.0 O
SPHERE CENTER 24.898001 18.084000 0.131000 RAD 1.0 CB
SPHERE CENTER 25.572001 19.129000 -0.776000 RAD 1.0 CG
SPHERE CENTER 27.037001 18.695000 -1.116000 RAD 1.0 CD1
SPHERE CENTER 24.791000 19.488001 -2.049000 RAD 1.0 CD2
SPHERE CENTER 22.545000 17.716000 2.628000 RAD 1.0 N
SPHERE CENTER 22.039000 16.646000 3.528000 RAD 1.0 CA
SPHERE CENTER 20.615999 16.285000 3.113000 RAD 1.0 C
SPHERE CENTER 19.860001 17.136000 2.576000 RAD 1.0 O
SPHERE CENTER 21.764000 17.216999 4.920000 RAD 1.0 CB
SPHERE CENTER 22.813999 18.035000 5.647000 RAD 1.0 CG
SPHERE CENTER 22.152000 18.707001 6.870000 RAD 1.0 CD
SPHERE CENTER 22.980000 19.100000 7.718000 RAD 1.0 OE1
SPHERE CENTER 21.086000 19.403999 6.779000 RAD 1.0 OE2
SPHERE CENTER 20.254000 15.031000 3.334000 RAD 1.0 N
SPHERE CENTER 18.892000 14.554000 3.034000 RAD 1.0 CA
SPHERE CENTER 17.954000 15.160000 4.079000 RAD 1.0 C
SPHERE CENTER 18.443001 15.606000 5.146000 RAD 1.0 O
SPHERE CENTER 18.910000 13.045000 3.274000 RAD 1.0 CB
SPHERE CENTER 20.226000 12.742000 4.021000 RAD 1.0 CG
SPHERE CENTER 21.107000 14.009000 3.934000 RAD 1.0 CD
SPHERE CENTER 16.681999 15.232000 3.767000 RAD 1.0 N
SPHERE CENTER 15.690000 15.852000 4.661000 RAD 1.0 CA
SPHERE CENTER 15.550000 15.006000 5.916000 RAD 1.0 C
SPHERE CENTER 15.693000 13.769000 5.836000 RAD 1.0 O
SPHERE CENTER 14.367000 15.707000 3.867000 RAD 1.0 CB
SPHERE CENTER 14.571000 14.716000 2.710000 RAD 1.0 CG
SPHERE CENTER 16.090000 14.597000 2.574000 RAD 1.0 CD
SPHERE CENTER 15.365000 15.630000 7.042000 RAD 1.0 N
SPHERE CENTER 15.310000 14.908000 8.298000 RAD 1.0 CA
SPHERE CENTER 13.953000 15.177000 8.952000 RAD 1.0 C
SPHERE CENTER 13.699000 16.320000 9.382000 RAD 1.0 O
SPHERE CENTER 16.532000 15.383000 9.122000 RAD 1.0 CB
SPHERE CENTER 16.608000 14.781000 10.525000 RAD 1.0 CG
SPHERE CENTER 17.132000 13.535000 10.707000 RAD 1.0 CD1
SPHERE CENTER 16.155001 15.523000 11.588000 RAD 1.0 CD2
SPHERE CENTER 17.216000 12.999000 11.982000 RAD 1.0 CE1
SPHERE CENTER 16.266001 14.985000 12.862000 RAD 1.0 CE2
SPHERE CENTER 16.808001 13.746000 13.047000 RAD 1.0 CZ
SPHERE CENTER 16.878000 13.192000 14.372000 RAD 1.0 OH
SPHERE CENTER 13.161000 14.146000 9.088000 RAD 1.0 N
SPHERE CENTER 11.802000 14.321000 9.642000 RAD 1.0 CA
SPHERE CENTER 11.855000 14.484000 11.146000 RAD 1.0 C
SPHERE CENTER 11.105000 15.314000 11.759000 RAD 1.0 O
SPHERE CENTER 10.963000 13.105000 9.273000 RAD 1.0 CB
SPHERE CENTER 10.706000 13.192000 7.854000 RAD 1.0 OG1
SPHERE CENTER 9.611000 13.152000 10.045000 RAD 1.0 CG2
SPHERE CENTER 12.789000 13.760000 11.726000 RAD 1.0 N
SPHERE CENTER 13.002000 13.922000 13.198000 RAD 1.0 CA
SPHERE CENTER 12.107000 12.944000 13.909000 RAD 1.0 C
SPHERE CENTER 11.333000 12.212000 13.239000 RAD 1.0 O
SPHERE CENTER 12.235000 12.905000 15.210000 RAD 1.0 N
SPHERE CENTER 11.516000 11.958000 16.066999 RAD 1.0 CA
SPHERE CENTER 10.094000 12.319000 16.468000 RAD 1.0 C
SPHERE CENTER 9.440000 11.442000 17.052000 RAD 1.0 O
SPHERE CENTER 12.272000 11.936000 17.370001 RAD 1.0 CB
SPHERE CENTER 13.164000 13.172000 17.399000 RAD 1.0 CG
SPHERE CENTER 13.281000 13.627000 15.925000 RAD 1.0 CD
SPHERE CENTER 9.629000 13.519000 16.214001 RAD 1.0 N
SPHERE CENTER 8.290000 13.980000 16.615999 RAD 1.0 CA
SPHERE CENTER 7.268000 13.720000 15.515000 RAD 1.0 C
SPHERE CENTER 7.672000 13.397000 14.387000 RAD 1.0 O
SPHERE CENTER 8.279000 15.441000 16.966999 RAD 1.0 CB
SPHERE CENTER 9.221000 15.735000 18.490000 RAD 1.0 SG
SPHERE CENTER 6.027000 13.680000 15.869000 RAD 1.0 N
SPHERE CENTER 5.005000 13.220000 14.945000 RAD 1.0 CA
SPHERE CENTER 3.964000 14.283000 14.630000 RAD 1.0 C
SPHERE CENTER 2.777000 13.949000 14.377000 RAD 1.0 O
SPHERE CENTER 4.310000 11.998000 15.592000 RAD 1.0 CB
SPHERE CENTER 5.273000 10.848000 15.913000 RAD 1.0 CG
SPHERE CENTER 5.781000 10.034000 14.702000 RAD 1.0 CD
SPHERE CENTER 6.855000 9.016000 15.126000 RAD 1.0 CE
SPHERE CENTER 7.357000 8.291000 13.953000 RAD 1.0 NZ
SPHERE CENTER 4.325000 15.549000 14.618000 RAD 1.0 N
SPHERE CENTER 3.513000 16.639999 14.122000 RAD 1.0 CA
SPHERE CENTER 3.561000 16.615000 12.586000 RAD 1.0 C
SPHERE CENTER 4.270000 15.752000 12.023000 RAD 1.0 O
SPHERE CENTER 3.984000 17.995001 14.670000 RAD 1.0 CB
SPHERE CENTER 2.781000 17.424999 11.943000 RAD 1.0 N
SPHERE CENTER 2.700000 17.355000 10.457000 RAD 1.0 CA
SPHERE CENTER 2.875000 18.731001 9.887000 RAD 1.0 C
SPHERE CENTER 1.878000 19.469999 9.653000 RAD 1.0 O
SPHERE CENTER 1.320000 16.787001 9.970000 RAD 1.0 CB
SPHERE CENTER 1.186000 15.339000 10.395000 RAD 1.0 CG
SPHERE CENTER -0.170000 14.751000 9.963000 RAD 1.0 CD
SPHERE CENTER -1.132000 15.455000 10.801000 RAD 1.0 NE
SPHERE CENTER -1.531000 14.913000 11.939000 RAD 1.0 CZ
SPHERE CENTER -1.172000 13.658000 12.165000 RAD 1.0 NH1
SPHERE CENTER -2.202000 15.647000 12.795000 RAD 1.0 NH2
SPHERE CENTER 4.154000 19.110001 9.817000 RAD 1.0 N
SPHERE CENTER 4.595000 20.444000 9.391000 RAD 1.0 CA
SPHERE CENTER 5.249000 20.388000 8.012000 RAD 1.0 C
SPHERE CENTER 6.193000 19.612000 7.834000 RAD 1.0 O
SPHERE CENTER 5.590000 20.988001 10.452000 RAD 1.0 CB
SPHERE CENTER 4.792000 21.062000 11.815000 RAD 1.0 CG1
SPHERE CENTER 5.985000 22.451000 10.085000 RAD 1.0 CG2
SPHERE CENTER 5.689000 21.535999 12.955000 RAD 1.0 CD1
SPHERE CENTER 4.586000 20.955999 7.035000 RAD 1.0 N
SPHERE CENTER 5.154000 20.879000 5.697000 RAD 1.0 CA
SPHERE CENTER 6.286000 21.912001 5.572000 RAD 1.0 C
SPHERE CENTER 6.156000 23.146000 5.785000 RAD 1.0 O
SPHERE CENTER 4.095000 21.205000 4.648000 RAD 1.0 CB
SPHERE CENTER 2.836000 20.316999 4.886000 RAD 1.0 CG1
SPHERE CENTER 4.655000 20.930000 3.250000 RAD 1.0 CG2
SPHERE CENTER 3.122000 18.813999 4.850000 RAD 1.0 CD1
SPHERE CENTER 7.451000 21.372000 5.297000 RAD 1.0 N
SPHERE CENTER 8.602000 22.257000 5.060000 RAD 1.0 CA
SPHERE CENTER 9.150000 21.950001 3.673000 RAD 1.0 C
SPHERE CENTER 8.840000 20.896000 3.088000 RAD 1.0 O
SPHERE CENTER 9.698000 21.896999 6.092000 RAD 1.0 CB
SPHERE CENTER 9.226000 22.299999 7.493000 RAD 1.0 CG
SPHERE CENTER 9.248000 23.850000 7.622000 RAD 1.0 CD
SPHERE CENTER 8.810000 24.311001 8.962000 RAD 1.0 NE
SPHERE CENTER 9.575000 24.336000 10.075000 RAD 1.0 CZ
SPHERE CENTER 10.888000 24.077000 10.044000 RAD 1.0 NH1
SPHERE CENTER 9.050000 24.893000 11.170000 RAD 1.0 NH2
SPHERE CENTER 10.178000 22.695000 3.318000 RAD 1.0 N
SPHERE CENTER 10.959000 22.444000 2.085000 RAD 1.0 CA
SPHERE CENTER 12.407000 22.010000 2.386000 RAD 1.0 C
SPHERE CENTER 12.987000 22.511999 3.378000 RAD 1.0 O
SPHERE CENTER 10.997000 23.770000 1.282000 RAD 1.0 CB
SPHERE CENTER 9.641000 24.038000 0.627000 RAD 1.0 CG
SPHERE CENTER 8.639000 24.591999 1.399000 RAD 1.0 CD1
SPHERE CENTER 9.451000 23.725000 -0.691000 RAD 1.0 CD2
SPHERE CENTER 7.403000 24.861000 0.831000 RAD 1.0 CE1
SPHERE CENTER 8.213000 23.993000 -1.249000 RAD 1.0 CE2
SPHERE CENTER 7.215000 24.576000 -0.494000 RAD 1.0 CZ
SPHERE CENTER 5.879000 24.768999 -1.060000 RAD 1.0 OH
SPHERE CENTER 12.977000 21.141001 1.535000 RAD 1.0 N
SPHERE CENTER 14.449000 20.892000 1.626000 RAD 1.0 CA
SPHERE CENTER 15.018000 21.045000 0.237000 RAD 1.0 C
SPHERE CENTER 14.250000 20.837000 -0.740000 RAD 1.0 O
SPHERE CENTER 14.664000 19.434999 2.142000 RAD 1.0 CB
SPHERE CENTER 14.283000 18.275999 1.191000 RAD 1.0 CG
SPHERE CENTER 15.290000 17.639000 0.506000 RAD 1.0 CD1
SPHERE CENTER 12.962000 17.907000 0.976000 RAD 1.0 CD2
SPHERE CENTER 14.981000 16.632000 -0.392000 RAD 1.0 CE1
SPHERE CENTER 12.638000 16.909000 0.061000 RAD 1.0 CE2
SPHERE CENTER 13.673000 16.261999 -0.626000 RAD 1.0 CZ
SPHERE CENTER 16.336000 21.281000 0.152000 RAD 1.0 N
SPHERE CENTER 16.948000 21.292000 -1.153000 RAD 1.0 CA
SPHERE CENTER 17.365000 19.888000 -1.542000 RAD 1.0 C
SPHERE CENTER 18.009001 19.184000 -0.744000 RAD 1.0 O
SPHERE CENTER 18.188000 22.194000 -1.071000 RAD 1.0 CB
SPHERE CENTER 18.906000 22.263000 -2.442000 RAD 1.0 CG
SPHERE CENTER 20.089001 21.621000 -2.663000 RAD 1.0 CD1
SPHERE CENTER 18.361000 23.033001 -3.436000 RAD 1.0 CD2
SPHERE CENTER 20.733000 21.778999 -3.896000 RAD 1.0 CE1
SPHERE CENTER 18.990999 23.184999 -4.662000 RAD 1.0 CE2
SPHERE CENTER 20.184999 22.562000 -4.864000 RAD 1.0 CZ
SPHERE CENTER 20.826000 22.768000 -6.115000 RAD 1.0 OH
SPHERE CENTER 16.913000 19.452999 -2.726000 RAD 1.0 N
SPHERE CENTER 17.295000 18.160000 -3.291000 RAD 1.0 CA
SPHERE CENTER 18.406000 18.332001 -4.341000 RAD 1.0 C
SPHERE CENTER 18.166000 18.843000 -5.464000 RAD 1.0 O
SPHERE CENTER 16.052000 17.558001 -3.946000 RAD 1.0 CB
SPHERE CENTER 16.354000 16.226999 -4.626000 RAD 1.0 CG
SPHERE CENTER 17.531000 15.754000 -4.725000 RAD 1.0 OD1
SPHERE CENTER 15.234000 15.549000 -4.870000 RAD 1.0 ND2
SPHERE CENTER 19.655001 18.124001 -3.871000 RAD 1.0 N
SPHERE CENTER 20.851000 18.420000 -4.681000 RAD 1.0 CA
SPHERE CENTER 20.920000 17.650000 -6.010000 RAD 1.0 C
SPHERE CENTER 21.385000 18.257000 -6.997000 RAD 1.0 O
SPHERE CENTER 22.112000 18.070999 -3.866000 RAD 1.0 CB
SPHERE CENTER 20.333000 16.480000 -6.081000 RAD 1.0 N
SPHERE CENTER 20.243999 15.784000 -7.383000 RAD 1.0 CA
SPHERE CENTER 19.287001 16.482000 -8.327000 RAD 1.0 C
SPHERE CENTER 19.478001 16.368999 -9.556000 RAD 1.0 O
SPHERE CENTER 19.732000 14.353000 -7.259000 RAD 1.0 CB
SPHERE CENTER 20.799999 13.485000 -6.626000 RAD 1.0 CG
SPHERE CENTER 20.299000 12.037000 -6.533000 RAD 1.0 CD
SPHERE CENTER 21.386999 11.067000 -6.033000 RAD 1.0 CE
SPHERE CENTER 21.820999 11.437000 -4.681000 RAD 1.0 NZ
SPHERE CENTER 18.212999 17.041000 -7.772000 RAD 1.0 N
SPHERE CENTER 17.181999 17.617001 -8.631000 RAD 1.0 CA
SPHERE CENTER 17.468000 19.070000 -8.921000 RAD 1.0 C
SPHERE CENTER 16.909000 19.707001 -9.863000 RAD 1.0 O
SPHERE CENTER 15.833000 17.423000 -7.901000 RAD 1.0 CB
SPHERE CENTER 18.299000 19.622000 -8.061000 RAD 1.0 N
SPHERE CENTER 18.625999 21.035999 -8.237000 RAD 1.0 CA
SPHERE CENTER 17.587999 22.051001 -7.738000 RAD 1.0 C
SPHERE CENTER 17.702000 23.257999 -8.056000 RAD 1.0 O
SPHERE CENTER 16.632000 21.566000 -6.970000 RAD 1.0 N
SPHERE CENTER 15.576000 22.431999 -6.478000 RAD 1.0 CA
SPHERE CENTER 14.947000 21.879999 -5.199000 RAD 1.0 C
SPHERE CENTER 15.304000 20.784000 -4.719000 RAD 1.0 O
SPHERE CENTER 14.553000 22.764999 -7.568000 RAD 1.0 CB
SPHERE CENTER 14.018000 21.514000 -8.283000 RAD 1.0 CG
SPHERE CENTER 13.211000 20.593000 -7.394000 RAD 1.0 CD1
SPHERE CENTER 13.189000 21.898001 -9.518000 RAD 1.0 CD2
SPHERE CENTER 14.114000 22.691999 -4.605000 RAD 1.0 N
SPHERE CENTER 13.591000 22.299999 -3.306000 RAD 1.0 CA
SPHERE CENTER 12.246000 21.612000 -3.398000 RAD 1.0 C
SPHERE CENTER 11.508000 21.862000 -4.381000 RAD 1.0 O
SPHERE CENTER 13.406000 23.628000 -2.540000 RAD 1.0 CB
SPHERE CENTER 14.977000 24.433001 -2.196000 RAD 1.0 SG
SPHERE CENTER 12.005000 20.672001 -2.530000 RAD 1.0 N
SPHERE CENTER 10.813000 19.820999 -2.569000 RAD 1.0 CA
SPHERE CENTER 10.208000 19.822001 -1.167000 RAD 1.0 C
SPHERE CENTER 10.918000 20.218000 -0.210000 RAD 1.0 O
SPHERE CENTER 11.110000 18.377001 -3.007000 RAD 1.0 CB
SPHERE CENTER 11.604000 18.464001 -4.496000 RAD 1.0 CG
SPHERE CENTER 12.041000 17.093000 -4.992000 RAD 1.0 CD
SPHERE CENTER 12.104000 16.884001 -6.223000 RAD 1.0 OE1
SPHERE CENTER 12.461000 16.246000 -4.115000 RAD 1.0 NE2
SPHERE CENTER 8.983000 19.459000 -1.072000 RAD 1.0 N
SPHERE CENTER 8.377000 19.427999 0.280000 RAD 1.0 CA
SPHERE CENTER 8.573000 18.100000 0.950000 RAD 1.0 C
SPHERE CENTER 8.785000 17.013000 0.347000 RAD 1.0 O
SPHERE CENTER 6.844000 19.700001 0.273000 RAD 1.0 CB
SPHERE CENTER 6.304000 18.825001 -0.706000 RAD 1.0 OG1
SPHERE CENTER 6.585000 21.149000 -0.177000 RAD 1.0 CG2
SPHERE CENTER 8.526000 18.187000 2.280000 RAD 1.0 N
SPHERE CENTER 8.582000 16.999001 3.087000 RAD 1.0 CA
SPHERE CENTER 7.801000 17.273001 4.382000 RAD 1.0 C
SPHERE CENTER 7.554000 18.469000 4.665000 RAD 1.0 O
SPHERE CENTER 10.066000 16.503000 3.399000 RAD 1.0 CB
SPHERE CENTER 10.840000 17.323999 4.462000 RAD 1.0 CG
SPHERE CENTER 11.188000 16.711000 5.670000 RAD 1.0 CD1
SPHERE CENTER 11.224000 18.618999 4.188000 RAD 1.0 CD2
SPHERE CENTER 11.912000 17.452999 6.617000 RAD 1.0 CE1
SPHERE CENTER 11.948000 19.333000 5.129000 RAD 1.0 CE2
SPHERE CENTER 12.277000 18.763000 6.344000 RAD 1.0 CZ
SPHERE CENTER 7.455000 16.219999 5.116000 RAD 1.0 N
SPHERE CENTER 6.756000 16.414000 6.390000 RAD 1.0 CA
SPHERE CENTER 7.798000 16.358999 7.491000 RAD 1.0 C
SPHERE CENTER 8.422000 15.296000 7.692000 RAD 1.0 O
SPHERE CENTER 5.716000 15.281000 6.557000 RAD 1.0 CB
SPHERE CENTER 4.973000 15.432000 7.882000 RAD 1.0 CG1
SPHERE CENTER 4.667000 15.326000 5.371000 RAD 1.0 CG2
SPHERE CENTER 7.953000 17.509001 8.095000 RAD 1.0 N
SPHERE CENTER 8.816000 17.659000 9.286000 RAD 1.0 CA
SPHERE CENTER 7.941000 17.294001 10.498000 RAD 1.0 C
SPHERE CENTER 6.818000 17.832001 10.661000 RAD 1.0 O
SPHERE CENTER 9.260000 19.136000 9.274000 RAD 1.0 CB
SPHERE CENTER 10.066000 19.506001 10.540000 RAD 1.0 CG
SPHERE CENTER 11.058000 18.667999 11.032000 RAD 1.0 CD1
SPHERE CENTER 9.728000 20.677999 11.181000 RAD 1.0 CD2
SPHERE CENTER 11.713000 19.021999 12.217000 RAD 1.0 CE1
SPHERE CENTER 10.401000 21.042000 12.346000 RAD 1.0 CE2
SPHERE CENTER 11.371000 20.211000 12.851000 RAD 1.0 CZ
SPHERE CENTER 12.040000 20.579000 14.049000 RAD 1.0 OH
SPHERE CENTER 8.505000 16.504999 11.400000 RAD 1.0 N
SPHERE CENTER 7.774000 16.076000 12.622000 RAD 1.0 CA
SPHERE CENTER 7.696000 17.099001 13.728000 RAD 1.0 C
SPHERE CENTER 6.978000 16.834999 14.718000 RAD 1.0 O
SPHERE CENTER 8.385000 18.202000 13.646000 RAD 1.0 N
SPHERE CENTER 8.275000 19.365999 14.533000 RAD 1.0 CA
SPHERE CENTER 9.338000 19.430000 15.620000 RAD 1.0 C
SPHERE CENTER 9.309000 20.379999 16.415001 RAD 1.0 O
SPHERE CENTER 10.317000 18.555000 15.610000 RAD 1.0 N
SPHERE CENTER 11.453000 18.707001 16.541000 RAD 1.0 CA
SPHERE CENTER 12.763000 18.232000 15.950000 RAD 1.0 C
SPHERE CENTER 12.753000 17.224001 15.201000 RAD 1.0 O
SPHERE CENTER 11.179000 18.055000 17.937000 RAD 1.0 CB
SPHERE CENTER 11.154000 16.283001 17.922001 RAD 1.0 SG
SPHERE CENTER 13.828000 18.788000 16.528999 RAD 1.0 N
SPHERE CENTER 15.222000 18.386999 16.261999 RAD 1.0 CA
SPHERE CENTER 15.644000 18.605000 14.798000 RAD 1.0 C
SPHERE CENTER 16.306000 17.708000 14.224000 RAD 1.0 O
SPHERE CENTER 15.486000 16.941000 16.719000 RAD 1.0 CB
SPHERE CENTER 14.949000 16.624001 18.146999 RAD 1.0 CG
SPHERE CENTER 15.484000 17.593000 19.195000 RAD 1.0 CD
SPHERE CENTER 15.081000 17.068001 20.497000 RAD 1.0 NE
SPHERE CENTER 15.268000 17.830999 21.573999 RAD 1.0 CZ
SPHERE CENTER 15.870000 19.020000 21.452999 RAD 1.0 NH1
SPHERE CENTER 14.930000 17.320999 22.753000 RAD 1.0 NH2
SPHERE CENTER 15.154000 19.670000 14.180000 RAD 1.0 N
SPHERE CENTER 15.461000 19.893999 12.733000 RAD 1.0 CA
SPHERE CENTER 16.969000 19.924000 12.482000 RAD 1.0 C
SPHERE CENTER 17.752001 20.431000 13.327000 RAD 1.0 O
SPHERE CENTER 14.918000 21.275000 12.366000 RAD 1.0 CB
SPHERE CENTER 17.282000 19.622000 11.271000 RAD 1.0 N
SPHERE CENTER 18.584999 19.886999 10.687000 RAD 1.0 CA
SPHERE CENTER 18.461000 21.087000 9.753000 RAD 1.0 C
SPHERE CENTER 17.371000 21.708000 9.790000 RAD 1.0 O
SPHERE CENTER 18.961000 18.612000 9.934000 RAD 1.0 CB
SPHERE CENTER 19.486000 17.514999 10.843000 RAD 1.0 CG
SPHERE CENTER 20.042999 16.424999 9.926000 RAD 1.0 CD
SPHERE CENTER 20.782000 15.386000 10.779000 RAD 1.0 CE
SPHERE CENTER 20.985001 14.137000 10.021000 RAD 1.0 NZ
SPHERE CENTER 19.577000 21.643999 9.215000 RAD 1.0 N
SPHERE CENTER 19.570999 22.903000 8.543000 RAD 1.0 CA
SPHERE CENTER 18.898001 22.847000 7.144000 RAD 1.0 C
SPHERE CENTER 18.476000 23.930000 6.690000 RAD 1.0 O
SPHERE CENTER 20.981001 23.469999 8.429000 RAD 1.0 CB
SPHERE CENTER 21.461000 24.047001 9.786000 RAD 1.0 CG
SPHERE CENTER 22.614000 25.047001 9.608000 RAD 1.0 CD
SPHERE CENTER 22.118999 26.403999 9.384000 RAD 1.0 NE
SPHERE CENTER 22.948000 27.426001 9.370000 RAD 1.0 CZ
SPHERE CENTER 24.253000 27.187000 9.415000 RAD 1.0 NH1
SPHERE CENTER 22.472000 28.634001 9.297000 RAD 1.0 NH2
SPHERE CENTER 18.870001 21.715000 6.474000 RAD 1.0 N
SPHERE CENTER 18.209999 21.712999 5.169000 RAD 1.0 CA
SPHERE CENTER 16.671000 21.559000 5.372000 RAD 1.0 C
SPHERE CENTER 16.068001 20.466000 5.197000 RAD 1.0 O
SPHERE CENTER 18.745001 20.506001 4.379000 RAD 1.0 CB
SPHERE CENTER 18.295000 20.591999 2.909000 RAD 1.0 CG
SPHERE CENTER 17.721001 21.629000 2.499000 RAD 1.0 OD1
SPHERE CENTER 18.664000 19.563999 2.134000 RAD 1.0 ND2
SPHERE CENTER 16.097000 22.643000 5.820000 RAD 1.0 N
SPHERE CENTER 14.676000 22.662001 6.349000 RAD 1.0 CA
SPHERE CENTER 14.157000 24.101999 6.384000 RAD 1.0 C
SPHERE CENTER 14.715000 24.959000 7.120000 RAD 1.0 O
SPHERE CENTER 14.577000 21.951000 7.736000 RAD 1.0 CB
SPHERE CENTER 13.128000 21.861000 8.301000 RAD 1.0 CG
SPHERE CENTER 12.432000 22.889000 8.208000 RAD 1.0 OD1
SPHERE CENTER 12.975000 21.035000 9.288000 RAD 1.0 ND2
SPHERE CENTER 13.324000 24.438000 5.381000 RAD 1.0 N
SPHERE CENTER 12.918000 25.816999 5.120000 RAD 1.0 CA
SPHERE CENTER 11.388000 25.961000 5.164000 RAD 1.0 C
SPHERE CENTER 10.669000 24.966000 4.915000 RAD 1.0 O
SPHERE CENTER 13.372000 26.372999 3.741000 RAD 1.0 CB
SPHERE CENTER 14.913000 26.191999 3.701000 RAD 1.0 CG
SPHERE CENTER 15.492000 25.002001 3.268000 RAD 1.0 CD1
SPHERE CENTER 15.705000 27.252001 4.053000 RAD 1.0 CD2
SPHERE CENTER 16.877001 24.881001 3.132000 RAD 1.0 CE1
SPHERE CENTER 17.108999 27.125999 3.941000 RAD 1.0 CE2
SPHERE CENTER 17.659000 25.957001 3.487000 RAD 1.0 CZ
SPHERE CENTER 10.949000 27.146999 5.460000 RAD 1.0 N
SPHERE CENTER 9.480000 27.343000 5.498000 RAD 1.0 CA
SPHERE CENTER 8.875000 27.670000 4.157000 RAD 1.0 C
SPHERE CENTER 7.634000 27.622999 4.057000 RAD 1.0 O
SPHERE CENTER 9.045000 28.475000 6.433000 RAD 1.0 CB
SPHERE CENTER 9.258000 27.945999 7.875000 RAD 1.0 CG
SPHERE CENTER 9.119000 29.052000 8.948000 RAD 1.0 CD
SPHERE CENTER 10.025000 28.736000 10.167000 RAD 1.0 CE
SPHERE CENTER 9.826000 29.728001 11.231000 RAD 1.0 NZ
SPHERE CENTER 9.687000 27.909000 3.152000 RAD 1.0 N
SPHERE CENTER 9.124000 28.167999 1.840000 RAD 1.0 CA
SPHERE CENTER 10.108000 27.719000 0.765000 RAD 1.0 C
SPHERE CENTER 11.332000 27.660000 1.047000 RAD 1.0 O
SPHERE CENTER 8.778000 29.648001 1.642000 RAD 1.0 CB
SPHERE CENTER 10.000000 30.391001 1.484000 RAD 1.0 OG
SPHERE CENTER 9.604000 27.471001 -0.422000 RAD 1.0 N
SPHERE CENTER 10.526000 27.160999 -1.512000 RAD 1.0 CA
SPHERE CENTER 11.423000 28.346001 -1.863000 RAD 1.0 C
SPHERE CENTER 12.634000 28.115000 -2.136000 RAD 1.0 O
SPHERE CENTER 9.782000 26.679001 -2.783000 RAD 1.0 CB
SPHERE CENTER 10.966000 29.570000 -1.682000 RAD 1.0 N
SPHERE CENTER 11.751000 30.764000 -1.998000 RAD 1.0 CA
SPHERE CENTER 12.900000 30.964001 -1.040000 RAD 1.0 C
SPHERE CENTER 14.032000 31.282000 -1.463000 RAD 1.0 O
SPHERE CENTER 10.871000 32.021999 -2.024000 RAD 1.0 CB
SPHERE CENTER 9.868000 32.069000 -3.200000 RAD 1.0 CG
SPHERE CENTER 8.525000 31.417000 -2.847000 RAD 1.0 CD
SPHERE CENTER 7.573000 31.562000 -3.638000 RAD 1.0 OE1
SPHERE CENTER 8.368000 30.636999 -1.865000 RAD 1.0 OE2
SPHERE CENTER 12.658000 30.686001 0.225000 RAD 1.0 N
SPHERE CENTER 13.804000 30.775000 1.163000 RAD 1.0 CA
SPHERE CENTER 14.824000 29.667000 0.941000 RAD 1.0 C
SPHERE CENTER 16.058001 29.903999 1.049000 RAD 1.0 O
SPHERE CENTER 13.347000 30.500000 2.601000 RAD 1.0 CB
SPHERE CENTER 12.813000 31.775999 3.236000 RAD 1.0 CG
SPHERE CENTER 12.716000 32.875000 2.613000 RAD 1.0 OD1
SPHERE CENTER 12.096000 31.598000 4.247000 RAD 1.0 OD2
SPHERE CENTER 14.305000 28.478001 0.644000 RAD 1.0 N
SPHERE CENTER 15.128000 27.301001 0.379000 RAD 1.0 CA
SPHERE CENTER 16.006001 27.523001 -0.852000 RAD 1.0 C
SPHERE CENTER 17.247999 27.267000 -0.809000 RAD 1.0 O
SPHERE CENTER 14.238000 26.045000 0.259000 RAD 1.0 CB
SPHERE CENTER 15.047000 24.530001 -0.176000 RAD 1.0 SG
SPHERE CENTER 15.384000 28.062000 -1.870000 RAD 1.0 N
SPHERE CENTER 16.191999 28.302000 -3.048000 RAD 1.0 CA
SPHERE CENTER 17.171000 29.452999 -2.841000 RAD 1.0 C
SPHERE CENTER 18.246000 29.474001 -3.490000 RAD 1.0 O
SPHERE CENTER 15.267000 28.570999 -4.266000 RAD 1.0 CB
SPHERE CENTER 14.634000 27.261000 -4.708000 RAD 1.0 CG
SPHERE CENTER 15.759000 25.962000 -5.253000 RAD 1.0 SD
SPHERE CENTER 16.306999 26.625000 -6.805000 RAD 1.0 CE
SPHERE CENTER 16.775999 30.469999 -2.099000 RAD 1.0 N
SPHERE CENTER 17.652000 31.617001 -1.869000 RAD 1.0 CA
SPHERE CENTER 18.910000 31.125999 -1.141000 RAD 1.0 C
SPHERE CENTER 20.049999 31.469999 -1.556000 RAD 1.0 O
SPHERE CENTER 16.934000 32.595001 -0.930000 RAD 1.0 CB
SPHERE CENTER 17.721001 33.839001 -0.540000 RAD 1.0 CG
SPHERE CENTER 16.740999 35.039001 -0.291000 RAD 1.0 CD
SPHERE CENTER 15.472000 34.667999 0.404000 RAD 1.0 NE
SPHERE CENTER 14.256000 34.889999 -0.074000 RAD 1.0 CZ
SPHERE CENTER 13.983000 35.465000 -1.233000 RAD 1.0 NH1
SPHERE CENTER 13.260000 34.542999 0.660000 RAD 1.0 NH2
SPHERE CENTER 18.726999 30.198999 -0.237000 RAD 1.0 N
SPHERE CENTER 19.889999 29.693001 0.496000 RAD 1.0 CA
SPHERE CENTER 20.636999 28.649000 -0.297000 RAD 1.0 C
SPHERE CENTER 21.871000 28.686001 -0.287000 RAD 1.0 O
SPHERE CENTER 19.416000 29.106001 1.823000 RAD 1.0 CB
SPHERE CENTER 18.643999 30.132000 2.537000 RAD 1.0 OG1
SPHERE CENTER 20.615999 28.506001 2.662000 RAD 1.0 CG2
SPHERE CENTER 19.988001 27.747000 -0.961000 RAD 1.0 N
SPHERE CENTER 20.669001 26.563999 -1.471000 RAD 1.0 CA
SPHERE CENTER 20.773001 26.534000 -2.963000 RAD 1.0 C
SPHERE CENTER 21.341000 25.552999 -3.498000 RAD 1.0 O
SPHERE CENTER 19.955999 25.260000 -1.056000 RAD 1.0 CB
SPHERE CENTER 20.128000 24.914000 0.713000 RAD 1.0 SG
SPHERE CENTER 20.132000 27.441999 -3.608000 RAD 1.0 N
SPHERE CENTER 19.987000 27.268000 -5.071000 RAD 1.0 CA
SPHERE CENTER 21.257000 27.575001 -5.849000 RAD 1.0 C
SPHERE CENTER 21.386000 27.129000 -7.018000 RAD 1.0 O
SPHERE CENTER 22.225000 28.049999 -5.113000 RAD 1.0 N
SPHERE CENTER 23.639000 28.131001 -5.505000 RAD 1.0 CA
SPHERE CENTER 23.886999 29.393000 -6.316000 RAD 1.0 C
SPHERE CENTER 22.948999 30.065001 -6.822000 RAD 1.0 O
SPHERE CENTER 25.146000 29.681000 -6.493000 RAD 1.0 N
SPHERE CENTER 25.617001 30.840000 -7.256000 RAD 1.0 CA
SPHERE CENTER 25.247999 30.735001 -8.729000 RAD 1.0 C
SPHERE CENTER 24.962000 31.791000 -9.369000 RAD 1.0 O
SPHERE CENTER 27.160000 30.980000 -7.146000 RAD 1.0 CB
SPHERE CENTER 24.919001 29.594000 -9.172000 RAD 1.0 OXT
PLANE
CENTER 0.0 -25.0 0.0
NORMAL 0.0 1.0 0.0
TEXTURE
AMBIENT 0.1 DIFFUSE 0.9 SPECULAR 0.0 OPACITY 1.0
COLOR 1.0 1.0 1.0
TEXFUNC 0
END_SCENE

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

View File

@@ -0,0 +1,90 @@
// Microsoft Visual C++ generated resource script.
//
#include "resource.h"
#define APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 2 resource.
//
#define APSTUDIO_HIDDEN_SYMBOLS
#include "windows.h"
#undef APSTUDIO_HIDDEN_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
#undef APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
// English (U.S.) resources
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
#ifdef _WIN32
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
#pragma code_page(1252)
#endif //_WIN32
/////////////////////////////////////////////////////////////////////////////
//
// Icon
//
// Icon with lowest ID value placed first to ensure application icon
// remains consistent on all systems.
IDI_GUI ICON "gui.ico"
IDI_SMALL ICON "small.ico"
#ifdef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// TEXTINCLUDE
//
1 TEXTINCLUDE
BEGIN
"resource.h\0"
END
2 TEXTINCLUDE
BEGIN
"#define APSTUDIO_HIDDEN_SYMBOLS\r\n"
"#include ""windows.h""\r\n"
"#undef APSTUDIO_HIDDEN_SYMBOLS\r\n"
"\0"
END
3 TEXTINCLUDE
BEGIN
"\r\n"
"\0"
END
#endif // APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// String Table
//
STRINGTABLE
BEGIN
IDS_APP_TITLE "gui"
IDC_GUI "GUI"
END
#endif // English (U.S.) resources
/////////////////////////////////////////////////////////////////////////////
#ifndef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 3 resource.
//
/////////////////////////////////////////////////////////////////////////////
#endif // not APSTUDIO_INVOKED

View File

@@ -0,0 +1,24 @@
/*
Copyright (c) 2005-2020 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#define IDC_MYICON 2
#define IDD_GUI 102
#define IDS_APP_TITLE 103
#define IDI_GUI 107
#define IDI_SMALL 108
#define IDC_GUI 109
#define IDR_MAINFRAME 128
#define IDC_STATIC -1

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

View File

@@ -0,0 +1,15 @@
<Application
x:Class="tbbTachyon.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:tbbTachyon">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Common/StandardStyles.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
</Application>

View File

@@ -0,0 +1,50 @@
/*
Copyright (c) 2005-2020 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#include "DirectXPage.xaml.h"
using namespace tbbTachyon;
using namespace Platform;
using namespace Windows::ApplicationModel;
using namespace Windows::ApplicationModel::Activation;
using namespace Windows::Foundation;
using namespace Windows::Foundation::Collections;
using namespace Windows::Storage;
using namespace Windows::UI::Xaml;
using namespace Windows::UI::Xaml::Controls;
using namespace Windows::UI::Xaml::Controls::Primitives;
using namespace Windows::UI::Xaml::Data;
using namespace Windows::UI::Xaml::Input;
using namespace Windows::UI::Xaml::Interop;
using namespace Windows::UI::Xaml::Media;
using namespace Windows::UI::Xaml::Navigation;
#include "src/tachyon_video.h"
App::App()
{
InitializeComponent();
}
void App::OnLaunched(Windows::ApplicationModel::Activation::LaunchActivatedEventArgs^ pArgs)
{
m_directXPage = ref new DirectXPage();
// Place the frame in the current Window and ensure that it is active
Window::Current->Content = m_directXPage;
Window::Current->Activate();
}

View File

@@ -0,0 +1,37 @@
/*
Copyright (c) 2005-2020 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#pragma once
#include "App.g.h"
#include "DirectXPage.xaml.h"
namespace tbbTachyon
{
/// <summary>
/// Provides application-specific behavior to supplement the default Application class.
/// </summary>
ref class App sealed
{
public:
App();
virtual void OnLaunched(Windows::ApplicationModel::Activation::LaunchActivatedEventArgs^ pArgs) override;
private:
DirectXPage^ m_directXPage;
};
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 34 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 141 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.2 KiB

View File

@@ -0,0 +1,409 @@
/*
Copyright (c) 2005-2020 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#include "pch.h"
#include "DirectXBase.h"
#include <windows.ui.xaml.media.dxinterop.h>
#include <math.h>
using namespace Microsoft::WRL;
using namespace Windows::UI::Core;
using namespace Windows::UI::Xaml::Controls;
using namespace Windows::Foundation;
using namespace Windows::Graphics::Display;
using namespace D2D1;
// Constructor.
DirectXBase::DirectXBase() :
m_dpi(-1.0f)
{
}
// Initialize the DirectX resources required to run.
void DirectXBase::Initialize(CoreWindow^ window, SwapChainBackgroundPanel^ panel, float dpi)
{
m_window = window;
m_panel = panel;
CreateDeviceIndependentResources();
CreateDeviceResources();
SetDpi(dpi);
}
// These are the resources required independent of the device.
void DirectXBase::CreateDeviceIndependentResources()
{
D2D1_FACTORY_OPTIONS options;
ZeroMemory(&options, sizeof(D2D1_FACTORY_OPTIONS));
#if defined(_DEBUG)
// If the project is in a debug build, enable Direct2D debugging via SDK Layers
// TODO: investigate resource leaks reported by a debug version of a device.
// options.debugLevel = D2D1_DEBUG_LEVEL_INFORMATION;
#endif
DX::ThrowIfFailed(
D2D1CreateFactory(
D2D1_FACTORY_TYPE_SINGLE_THREADED,
__uuidof(ID2D1Factory1),
&options,
&m_d2dFactory
)
);
DX::ThrowIfFailed(
DWriteCreateFactory(
DWRITE_FACTORY_TYPE_SHARED,
__uuidof(IDWriteFactory),
&m_dwriteFactory
)
);
DX::ThrowIfFailed(
CoCreateInstance(
CLSID_WICImagingFactory,
nullptr,
CLSCTX_INPROC_SERVER,
IID_PPV_ARGS(&m_wicFactory)
)
);
}
// These are the resources that depend on the device.
void DirectXBase::CreateDeviceResources()
{
// This flag adds support for surfaces with a different color channel ordering than the API default.
// It is recommended usage, and is required for compatibility with Direct2D.
UINT creationFlags = D3D11_CREATE_DEVICE_BGRA_SUPPORT;
ComPtr<IDXGIDevice> dxgiDevice;
#if defined(_DEBUG)
// If the project is in a debug build, enable debugging via SDK Layers with this flag.
creationFlags |= D3D11_CREATE_DEVICE_DEBUG;
#endif
// This array defines the set of DirectX hardware feature levels this app will support.
// Note the ordering should be preserved.
// Don't forget to declare your application's minimum required feature level in its
// description. All applications are assumed to support 9.1 unless otherwise stated.
D3D_FEATURE_LEVEL featureLevels[] =
{
D3D_FEATURE_LEVEL_11_1,
D3D_FEATURE_LEVEL_11_0,
D3D_FEATURE_LEVEL_10_1,
D3D_FEATURE_LEVEL_10_0,
D3D_FEATURE_LEVEL_9_3,
D3D_FEATURE_LEVEL_9_2,
D3D_FEATURE_LEVEL_9_1
};
// Create the DX11 API device object, and get a corresponding context.
ComPtr<ID3D11Device> device;
ComPtr<ID3D11DeviceContext> context;
DX::ThrowIfFailed(
D3D11CreateDevice(
nullptr, // specify null to use the default adapter
D3D_DRIVER_TYPE_HARDWARE,
0, // leave as 0 unless software device
creationFlags, // optionally set debug and Direct2D compatibility flags
featureLevels, // list of feature levels this app can support
ARRAYSIZE(featureLevels), // number of entries in above list
D3D11_SDK_VERSION, // always set this to D3D11_SDK_VERSION for Metro style apps
&device, // returns the Direct3D device created
&m_featureLevel, // returns feature level of device created
&context // returns the device immediate context
)
);
// Get the DirectX11.1 device by QI off the DirectX11 one.
DX::ThrowIfFailed(
device.As(&m_d3dDevice)
);
// And get the corresponding device context in the same way.
DX::ThrowIfFailed(
context.As(&m_d3dContext)
);
// Obtain the underlying DXGI device of the Direct3D11.1 device.
DX::ThrowIfFailed(
m_d3dDevice.As(&dxgiDevice)
);
// Obtain the Direct2D device for 2-D rendering.
DX::ThrowIfFailed(
m_d2dFactory->CreateDevice(dxgiDevice.Get(), &m_d2dDevice)
);
// And get its corresponding device context object.
DX::ThrowIfFailed(
m_d2dDevice->CreateDeviceContext(
D2D1_DEVICE_CONTEXT_OPTIONS_NONE,
&m_d2dContext
)
);
// Release the swap chain (if it exists) as it will be incompatible with the new device.
m_swapChain = nullptr;
}
// Helps track the DPI in the helper class.
// This is called in the dpiChanged event handler in the view class.
void DirectXBase::SetDpi(float dpi)
{
if (dpi != m_dpi)
{
// Save the DPI of this display in our class.
m_dpi = dpi;
// Update Direct2D's stored DPI.
m_d2dContext->SetDpi(m_dpi, m_dpi);
// Often a DPI change implies a window size change. In some cases Windows will issues
// both a size changed event and a DPI changed event. In this case, the resulting bounds
// will not change, and the window resize code will only be executed once.
UpdateForWindowSizeChange();
}
}
// This routine is called in the event handler for the view SizeChanged event.
void DirectXBase::UpdateForWindowSizeChange()
{
// Only handle window size changed if there is no pending DPI change.
if (m_dpi != DisplayInformation::GetForCurrentView()->LogicalDpi)
return;
if (m_window->Bounds.Width != m_windowBounds.Width ||
m_window->Bounds.Height != m_windowBounds.Height)
{
m_d2dContext->SetTarget(nullptr);
m_d2dTargetBitmap = nullptr;
m_renderTargetView = nullptr;
m_depthStencilView = nullptr;
CreateWindowSizeDependentResources();
}
}
// Allocate all memory resources that change on a window SizeChanged event.
void DirectXBase::CreateWindowSizeDependentResources()
{
// Store the window bounds so the next time we get a SizeChanged event we can
// avoid rebuilding everything if the size is identical.
m_windowBounds = m_window->Bounds;
// Calculate the necessary swap chain and render target size in pixels.
m_renderTargetSize.Width = ConvertDipsToPixels(m_windowBounds.Width);
m_renderTargetSize.Height = ConvertDipsToPixels(m_windowBounds.Height);
// If the swap chain already exists, resize it.
if (m_swapChain != nullptr)
{
DX::ThrowIfFailed(
m_swapChain->ResizeBuffers(
2,
static_cast<UINT>(m_renderTargetSize.Width),
static_cast<UINT>(m_renderTargetSize.Height),
DXGI_FORMAT_B8G8R8A8_UNORM,
0
)
);
}
// Otherwise, create a new one.
else
{
// Allocate a descriptor.
DXGI_SWAP_CHAIN_DESC1 swapChainDesc = {0};
swapChainDesc.Width = static_cast<UINT>(m_renderTargetSize.Width); // Match the size of the windowm.
swapChainDesc.Height = static_cast<UINT>(m_renderTargetSize.Height);
swapChainDesc.Format = DXGI_FORMAT_B8G8R8A8_UNORM; // This is the most common swapchain format.
swapChainDesc.Stereo = false;
swapChainDesc.SampleDesc.Count = 1; // Don't use multi-sampling.
swapChainDesc.SampleDesc.Quality = 0;
swapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
swapChainDesc.BufferCount = 2; // Use double buffering to enable flip.
swapChainDesc.Scaling = DXGI_SCALING_STRETCH;
swapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL; // All Metro style apps must use this SwapEffect.
swapChainDesc.Flags = 0;
// Once the desired swap chain description is configured, it must be created on the same adapter as our D3D Device.
// First, retrieve the underlying DXGI Device from the D3D Device.
ComPtr<IDXGIDevice1> dxgiDevice;
DX::ThrowIfFailed(
m_d3dDevice.As(&dxgiDevice)
);
// Identify the physical adapter (GPU or card) this device is running on.
ComPtr<IDXGIAdapter> dxgiAdapter;
DX::ThrowIfFailed(
dxgiDevice->GetAdapter(&dxgiAdapter)
);
// And obtain the factory object that created it.
ComPtr<IDXGIFactory2> dxgiFactory;
DX::ThrowIfFailed(
dxgiAdapter->GetParent(IID_PPV_ARGS(&dxgiFactory))
);
// Create the swap chain and then associate it with the SwapChainBackgroundPanel.
DX::ThrowIfFailed(
dxgiFactory->CreateSwapChainForComposition(
m_d3dDevice.Get(),
&swapChainDesc,
nullptr,
&m_swapChain
)
);
ComPtr<ISwapChainBackgroundPanelNative> panelNative;
DX::ThrowIfFailed(
reinterpret_cast<IUnknown*>(m_panel)->QueryInterface(IID_PPV_ARGS(&panelNative))
);
DX::ThrowIfFailed(
panelNative->SetSwapChain(m_swapChain.Get())
);
// Ensure that DXGI does not queue more than one frame at a time. This both reduces
// latency and ensures that the application will only render after each VSync, minimizing
// power consumption.
DX::ThrowIfFailed(
dxgiDevice->SetMaximumFrameLatency(1)
);
}
// Obtain the backbuffer for this window which will be the final 3D rendertarget.
ComPtr<ID3D11Texture2D> backBuffer;
DX::ThrowIfFailed(
m_swapChain->GetBuffer(0, IID_PPV_ARGS(&backBuffer))
);
// Create a view interface on the rendertarget to use on bind.
DX::ThrowIfFailed(
m_d3dDevice->CreateRenderTargetView(
backBuffer.Get(),
nullptr,
&m_renderTargetView
)
);
// Create a descriptor for the depth/stencil buffer.
CD3D11_TEXTURE2D_DESC depthStencilDesc(
DXGI_FORMAT_D24_UNORM_S8_UINT,
static_cast<UINT>(m_renderTargetSize.Width),
static_cast<UINT>(m_renderTargetSize.Height),
1,
1,
D3D11_BIND_DEPTH_STENCIL
);
// Allocate a 2-D surface as the depth/stencil buffer.
ComPtr<ID3D11Texture2D> depthStencil;
DX::ThrowIfFailed(
m_d3dDevice->CreateTexture2D(
&depthStencilDesc,
nullptr,
&depthStencil
)
);
// Create a DepthStencil view on this surface to use on bind.
CD3D11_DEPTH_STENCIL_VIEW_DESC depthStencilViewDesc(D3D11_DSV_DIMENSION_TEXTURE2D);
DX::ThrowIfFailed(
m_d3dDevice->CreateDepthStencilView(
depthStencil.Get(),
&depthStencilViewDesc,
&m_depthStencilView
)
);
// Create a viewport descriptor of the full window size.
CD3D11_VIEWPORT viewport(
0.0f,
0.0f,
m_renderTargetSize.Width,
m_renderTargetSize.Height
);
// Set the current viewport using the descriptor.
m_d3dContext->RSSetViewports(1, &viewport);
// Now we set up the Direct2D render target bitmap linked to the swapchain.
// Whenever we render to this bitmap, it will be directly rendered to the
// swapchain associated with the window.
D2D1_BITMAP_PROPERTIES1 bitmapProperties =
BitmapProperties1(
D2D1_BITMAP_OPTIONS_TARGET | D2D1_BITMAP_OPTIONS_CANNOT_DRAW,
PixelFormat(DXGI_FORMAT_B8G8R8A8_UNORM, D2D1_ALPHA_MODE_PREMULTIPLIED),
m_dpi,
m_dpi
);
// Direct2D needs the DXGI version of the backbuffer surface pointer.
ComPtr<IDXGISurface> dxgiBackBuffer;
DX::ThrowIfFailed(
m_swapChain->GetBuffer(0, IID_PPV_ARGS(&dxgiBackBuffer))
);
// Get a D2D surface from the DXGI back buffer to use as the D2D render target.
DX::ThrowIfFailed(
m_d2dContext->CreateBitmapFromDxgiSurface(
dxgiBackBuffer.Get(),
&bitmapProperties,
&m_d2dTargetBitmap
)
);
// So now we can set the Direct2D render target.
m_d2dContext->SetTarget(m_d2dTargetBitmap.Get());
// Set D2D text anti-alias mode to Grayscale to ensure proper rendering of text on intermediate surfaces.
m_d2dContext->SetTextAntialiasMode(D2D1_TEXT_ANTIALIAS_MODE_GRAYSCALE);
}
// Method to deliver the final image to the display.
void DirectXBase::Present()
{
// The application may optionally specify "dirty" or "scroll" rects to improve efficiency
// in certain scenarios.
DXGI_PRESENT_PARAMETERS parameters = {0};
parameters.DirtyRectsCount = 0;
parameters.pDirtyRects = nullptr;
parameters.pScrollRect = nullptr;
parameters.pScrollOffset = nullptr;
// The first argument instructs DXGI to block until VSync, putting the application
// to sleep until the next VSync. This ensures we don't waste any cycles rendering
// frames that will never be displayed to the screen.
HRESULT hr = m_swapChain->Present1(1, 0, &parameters);
// If the device was removed either by a disconnect or a driver upgrade, we
// must completely reinitialize the renderer.
if (hr == DXGI_ERROR_DEVICE_REMOVED || hr == DXGI_ERROR_DEVICE_RESET)
{
Initialize(m_window.Get(), m_panel, m_dpi);
}
else
{
DX::ThrowIfFailed(hr);
}
}
// Method to convert a length in device-independent pixels (DIPs) to a length in physical pixels.
float DirectXBase::ConvertDipsToPixels(float dips)
{
static const float dipsPerInch = 96.0f;
return floor(dips * m_dpi / dipsPerInch + 0.5f); // Round to nearest integer.
}

View File

@@ -0,0 +1,88 @@
/*
Copyright (c) 2005-2020 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#pragma once
#include <wrl/client.h>
#include <d3d11_1.h>
#include <d2d1_1.h>
#include <d2d1effects.h>
#include <dwrite_1.h>
#include <wincodec.h>
#include "App.xaml.h"
#include <agile.h>
#pragma warning (disable: 4449)
// Helper utilities to make DirectX APIs work with exceptions
namespace DX
{
inline void ThrowIfFailed(HRESULT hr)
{
if (FAILED(hr))
{
// Set a breakpoint on this line to catch DirectX API errors
throw Platform::Exception::CreateException(hr);
}
}
}
// Helper class that initializes DirectX APIs
ref class DirectXBase abstract
{
internal:
DirectXBase();
public:
virtual void Initialize(Windows::UI::Core::CoreWindow^ window, Windows::UI::Xaml::Controls::SwapChainBackgroundPanel^ panel, float dpi);
virtual void CreateDeviceIndependentResources();
virtual void CreateDeviceResources();
virtual void SetDpi(float dpi);
virtual void CreateWindowSizeDependentResources();
virtual void UpdateForWindowSizeChange();
virtual void Render() = 0;
virtual void Present();
virtual float ConvertDipsToPixels(float dips);
protected private:
Platform::Agile<Windows::UI::Core::CoreWindow> m_window;
Windows::UI::Xaml::Controls::SwapChainBackgroundPanel^ m_panel;
// Direct2D Objects
Microsoft::WRL::ComPtr<ID2D1Factory1> m_d2dFactory;
Microsoft::WRL::ComPtr<ID2D1Device> m_d2dDevice;
Microsoft::WRL::ComPtr<ID2D1DeviceContext> m_d2dContext;
Microsoft::WRL::ComPtr<ID2D1Bitmap1> m_d2dTargetBitmap;
// DirectWrite & Windows Imaging Component Objects
Microsoft::WRL::ComPtr<IDWriteFactory1> m_dwriteFactory;
Microsoft::WRL::ComPtr<IWICImagingFactory2> m_wicFactory;
// Direct3D Objects
Microsoft::WRL::ComPtr<ID3D11Device1> m_d3dDevice;
Microsoft::WRL::ComPtr<ID3D11DeviceContext1> m_d3dContext;
Microsoft::WRL::ComPtr<IDXGISwapChain1> m_swapChain;
Microsoft::WRL::ComPtr<ID3D11RenderTargetView> m_renderTargetView;
Microsoft::WRL::ComPtr<ID3D11DepthStencilView> m_depthStencilView;
D3D_FEATURE_LEVEL m_featureLevel;
Windows::Foundation::Size m_renderTargetSize;
Windows::Foundation::Rect m_windowBounds;
float m_dpi;
};
#pragma warning (default: 4449)

View File

@@ -0,0 +1,31 @@
<SwapChainBackgroundPanel
x:Class="tbbTachyon.DirectXPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:tbbTachyon"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
>
<SwapChainBackgroundPanel.RowDefinitions>
<RowDefinition Height="15*"/>
<RowDefinition Height="17*"/>
</SwapChainBackgroundPanel.RowDefinitions>
<Page Grid.RowSpan="2" Background="Black" MinHeight="100" MaxHeight="100">
<Page.BottomAppBar>
<AppBar Padding="10,0,10,0">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="100" />
<ColumnDefinition Width="100" />
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="0" x:Name="NumberOfThreadsTextBlock" Text="Number Of Threads: Auto" TextAlignment="Center" TextWrapping="Wrap" Height="54" FontSize="20" VerticalAlignment="Top" HorizontalAlignment="Center"/>
<Slider Grid.Column="0" x:Name="ThreadsSlider" Minimum="0" Maximum="16" TickFrequency="1" TickPlacement="Outside" ValueChanged="ThreadsSliderValueChanged" Height="37" StepFrequency="1" IsThumbToolTipEnabled="False" />
<Button Grid.Column="1" x:Name="ThreadsApply" Style="{StaticResource YesAppBarButtonStyle}" Tag="Apply this number of threads" AutomationProperties.Name="Apply" Click="ThreadsApply_Click" HorizontalAlignment="Right" Visibility="Collapsed"/>
<Button Grid.Column="2" x:Name="Exit" Style="{StaticResource NoAppBarButtonStyle}" Tag="Exit" Click="Exit_Click" AutomationProperties.Name="Exit" HorizontalAlignment="Right" />
</Grid>
</AppBar>
</Page.BottomAppBar>
</Page>
</SwapChainBackgroundPanel>

View File

@@ -0,0 +1,128 @@
/*
Copyright (c) 2005-2020 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#include "pch.h"
#include "DirectXPage.xaml.h"
using namespace tbbTachyon;
using namespace Platform;
using namespace Windows::Foundation;
using namespace Windows::Foundation::Collections;
using namespace Windows::UI::Input;
using namespace Windows::UI::Core;
using namespace Windows::UI::Xaml;
using namespace Windows::UI::Xaml::Controls;
using namespace Windows::UI::Xaml::Controls::Primitives;
using namespace Windows::UI::Xaml::Data;
using namespace Windows::UI::Xaml::Input;
using namespace Windows::UI::Xaml::Media;
using namespace Windows::UI::Xaml::Navigation;
using namespace Windows::Graphics::Display;
#include "src/tachyon_video.h"
extern int volatile global_number_of_threads;
extern volatile bool global_isCancelled;
#pragma intrinsic(_BitScanReverse)
static int log2( unsigned int x ) {
DWORD i;
_BitScanReverse(&i,(DWORD)x);
return (int)i;
}
const unsigned interval_step_power = 1;
const unsigned num_interval_steps = 1 << (interval_step_power+1);
DirectXPage::DirectXPage() :
m_renderNeeded(true)
{
InitializeComponent();
m_renderer = ref new tbbTachyonRenderer();
m_renderer->Initialize(
Window::Current->CoreWindow,
this,
DisplayInformation::GetForCurrentView()->LogicalDpi
);
m_eventToken = CompositionTarget::Rendering::add(ref new EventHandler<Object^>(this, &DirectXPage::OnRendering));
int num_threads = 2*utility::get_default_num_threads();
// The thread slider has geometric sequence with several intermediate steps for each interval between 2^N and 2^(N+1).
// The nearest (from below) the power of 2.
int i_base = int(log2(num_threads));
int base = 1 << i_base;
// The step size for the current interval.
int step = base / num_interval_steps;
// The number of steps inside the interval.
int i_step = (num_threads-base)/step;
ThreadsSlider->Maximum = (i_base-interval_step_power)*num_interval_steps + i_step;
global_number_of_threads = m_number_of_threads = utility::get_default_num_threads();
}
DirectXPage::~DirectXPage()
{
}
void DirectXPage::OnRendering(Platform::Object^ sender, Platform::Object^ args)
{
if (m_renderNeeded){
m_renderer->Render();
m_renderer->Present();
m_renderNeeded = true;
}
}
void tbbTachyon::DirectXPage::ThreadsApply_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
{
if (global_number_of_threads != m_number_of_threads){
global_number_of_threads = m_number_of_threads;
global_isCancelled = true;
video->running = false;
m_renderNeeded = true;
ThreadsApply->Visibility=Windows::UI::Xaml::Visibility::Collapsed;
}
}
void tbbTachyon::DirectXPage::Exit_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
{
m_renderNeeded = false;
Application::Current->Exit();
}
void tbbTachyon::DirectXPage::ThreadsSliderValueChanged(Platform::Object^ sender, Windows::UI::Xaml::Controls::Primitives::RangeBaseValueChangedEventArgs^ e)
{
int pos = (int) e->NewValue;
// The nearest (from below) the power of 2.
int base = pos<num_interval_steps ? 0 : 1 << (pos/num_interval_steps+interval_step_power);
// The step size for the current interval.
int step = max(1,base/num_interval_steps);
m_number_of_threads = base + (pos%num_interval_steps)*step;
if (m_number_of_threads == 0) m_number_of_threads = utility::get_default_num_threads();
NumberOfThreadsTextBlock->Text="Number Of Threads: " + (m_number_of_threads == utility::get_default_num_threads()? "Auto": m_number_of_threads.ToString());
if (global_number_of_threads != m_number_of_threads){
ThreadsApply->Visibility=Windows::UI::Xaml::Visibility::Visible;
}else{
ThreadsApply->Visibility=Windows::UI::Xaml::Visibility::Collapsed;
}
}

View File

@@ -0,0 +1,44 @@
/*
Copyright (c) 2005-2020 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#pragma once
#include "DirectXPage.g.h"
#include "tbbTachyonRenderer.h"
namespace tbbTachyon
{
[Windows::Foundation::Metadata::WebHostHidden]
public ref class DirectXPage sealed
{
public:
DirectXPage();
private:
~DirectXPage();
void OnRendering(Object^ sender, Object^ args);
Windows::Foundation::EventRegistrationToken m_eventToken;
tbbTachyonRenderer^ m_renderer;
bool m_renderNeeded;
int m_number_of_threads;
void ThreadsSliderValueChanged(Platform::Object^ sender, Windows::UI::Xaml::Controls::Primitives::RangeBaseValueChangedEventArgs^ e);
void ThreadsApply_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e);
void Exit_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e);
};
}

View File

@@ -0,0 +1,49 @@
<?xml version="1.0" encoding="utf-8"?>
<Package
xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10"
xmlns:mp="http://schemas.microsoft.com/appx/2014/phone/manifest"
xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10"
IgnorableNamespaces="uap mp">
<Identity
Name="551ef478-a6dc-40b3-a3ff-10052625a781"
Publisher="CN=Administrator"
Version="1.0.0.0" />
<mp:PhoneIdentity PhoneProductId="551ef478-a6dc-40b3-a3ff-10052625a781" PhonePublisherId="00000000-0000-0000-0000-000000000000"/>
<Properties>
<DisplayName>tbbTachyon</DisplayName>
<PublisherDisplayName>Administrator</PublisherDisplayName>
<Logo>Assets\StoreLogo.png</Logo>
</Properties>
<Dependencies>
<TargetDeviceFamily Name="Windows.Universal" MinVersion="10.0.0.0" MaxVersionTested="10.0.0.0" />
</Dependencies>
<Resources>
<Resource Language="x-generate"/>
</Resources>
<Applications>
<Application Id="App"
Executable="$targetnametoken$.exe"
EntryPoint="tbbTachyon.App">
<uap:VisualElements
DisplayName="tbbTachyon"
Square150x150Logo="Assets\Square150x150Logo.png"
Square44x44Logo="Assets\Square44x44Logo.png"
Description="tbbTachyon"
BackgroundColor="transparent">
<uap:DefaultTile Wide310x150Logo="Assets\Wide310x150Logo.png"/>
<uap:SplashScreen Image="Assets\SplashScreen.png" />
</uap:VisualElements>
</Application>
</Applications>
<Capabilities>
<Capability Name="internetClient" />
</Capabilities>
</Package>

View File

@@ -0,0 +1,70 @@
@echo on
REM
REM Copyright (c) 2005-2020 Intel Corporation
REM
REM Licensed under the Apache License, Version 2.0 (the "License");
REM you may not use this file except in compliance with the License.
REM You may obtain a copy of the License at
REM
REM http://www.apache.org/licenses/LICENSE-2.0
REM
REM Unless required by applicable law or agreed to in writing, software
REM distributed under the License is distributed on an "AS IS" BASIS,
REM WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
REM See the License for the specific language governing permissions and
REM limitations under the License.
REM
:: Getting parameters
:: Architecture
if ("%1") == ("") goto error0
:: Release/Debug
if ("%2") == ("") goto error0
:: Output directory
if (%3) == ("") goto error0
set arch=%1
if ("%2") == ("debug") set postfix=_debug
set output_dir="%3"
if ("%4") == ("") set dat_file="%output_dir%\..\..\dat\balls.dat"
:: Actually we can set install root by ourselves
if ("%TBBROOT%") == ("") set TBBROOT=%~dp0..\..\..\..\..\
:: Getting vs folders ordered from oldest to newest, so we end with newest available version
if ("%VS140COMNTOOLS%") NEQ ("") set vc_dir=vc14_uwp
:: To use Microsoft* Visual Studio* 2017 IDE, make sure the variable VS150COMNTOOLS is set in your IDE instance.
:: If it is not, try running Microsoft Visual Studio 2017 from Microsoft* Developer Command Prompt* for VS 2017.
:: For details, see https://developercommunity.visualstudio.com/content/problem/730/vs154-env-var-vs150comntools-missing-from-build-sy.html
if ("%VS150COMNTOOLS%") NEQ ("") set vc_dir=vc14_uwp
:: The same comment also applies to Microsoft Visual Studio 2019 and variable VS160COMNTOOLS
if ("%VS160COMNTOOLS%") NEQ ("") set vc_dir=vc14_uwp
echo Using %vc_dir% libraries
if exist "%TBBROOT%\bin\%arch%\%vc_dir%\tbb%postfix%.dll" set interim_path=bin\%arch%
if exist "%TBBROOT%..\redist\%arch%\tbb\%vc_dir%\tbb%postfix%.dll" set interim_path=..\redist\%arch%\tbb
if exist "%TBBROOT%\lib\%arch%\%vc_dir%\tbb%postfix%.lib" set interim_lib_path=lib\%arch%
if ("%interim_path%") == ("") goto error1
if ("%interim_lib_path%") == ("") goto error1
:: We know everything we wanted and there are no errors
:: Copying binaries
copy "%TBBROOT%\%interim_path%\%vc_dir%\tbb%postfix%.dll" "%output_dir%"
copy "%TBBROOT%\%interim_path%\%vc_dir%\tbb%postfix%.pdb" "%output_dir%"
copy "%TBBROOT%\%interim_path%\%vc_dir%\tbbmalloc%postfix%.dll" "%output_dir%"
copy "%TBBROOT%\%interim_path%\%vc_dir%\tbbmalloc%postfix%.pdb" "%output_dir%"
copy "%TBBROOT%\%interim_lib_path%\%vc_dir%\tbb%postfix%.lib" "%output_dir%"
:: Copying DAT-file
echo Using DAT-file %dat_file%
if exist %dat_file% copy %dat_file% "%output_dir%\Assets\balls.dat"
goto end
:error0
echo Custom build script usage: %0 [ia32 or intel64] [release or debug] [output dir] [dat-file]
exit /B 1
:error1
echo Could not determine path to Intel TBB libraries
exit /B 1
:end
exit /B 0

View File

@@ -0,0 +1,25 @@
/*
Copyright (c) 2005-2020 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#pragma once
#include <wrl/client.h>
#include <d3d11_1.h>
#include <d2d1_1.h>
#include <d2d1effects.h>
#include <dwrite_1.h>
#include <wincodec.h>
#include "App.xaml.h"

View File

@@ -0,0 +1,185 @@
/*
Copyright (c) 2005-2020 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#include "pch.h"
#include "tbbTachyonRenderer.h"
#include <DirectXMath.h>
#include <process.h>
#include <thread>
#include "../../src/tachyon_video.h"
using namespace Microsoft::WRL;
using namespace Windows::Foundation;
using namespace Windows::Foundation::Collections;
using namespace Windows::UI::Core;
using namespace DirectX;
tbbTachyonRenderer::tbbTachyonRenderer() :
m_renderNeeded(true)
{
}
tbbTachyonRenderer::~tbbTachyonRenderer()
{
}
void tbbTachyonRenderer::CreateDeviceIndependentResources()
{
DirectXBase::CreateDeviceIndependentResources();
DX::ThrowIfFailed(
m_dwriteFactory->CreateTextFormat(
L"Segoe UI",
nullptr,
DWRITE_FONT_WEIGHT_NORMAL,
DWRITE_FONT_STYLE_NORMAL,
DWRITE_FONT_STRETCH_NORMAL,
32.0f,
L"en-US",
&m_textFormat
)
);
DX::ThrowIfFailed(
m_textFormat->SetTextAlignment(DWRITE_TEXT_ALIGNMENT_LEADING)
);
}
unsigned int __stdcall example_main(void*);
float g_ratiox, g_ratioy;
extern unsigned int *g_pImg;
extern int g_sizex, g_sizey;
extern int global_xsize, global_ysize;
extern int volatile global_number_of_threads;
extern volatile long global_startTime;
extern volatile long global_elapsedTime;
#define SHOW_TEXT 1
void tbbTachyonRenderer::CreateDeviceResources()
{
DirectXBase::CreateDeviceResources();
DX::ThrowIfFailed(
m_d2dContext->CreateSolidColorBrush(
D2D1::ColorF(D2D1::ColorF::Green),
&m_Brush
)
);
D2D1_BITMAP_PROPERTIES1 properties = D2D1::BitmapProperties1(
D2D1_BITMAP_OPTIONS_TARGET,
D2D1::PixelFormat(
DXGI_FORMAT_R8G8B8A8_UNORM,
D2D1_ALPHA_MODE_IGNORE
)
);
//Setting manual rendering size
global_xsize = 800;
global_ysize = int(global_xsize/m_window->Bounds.Width*m_window->Bounds.Height);
D2D1_SIZE_U opacityBitmapSize = D2D1::SizeU(global_xsize, global_ysize);
DX::ThrowIfFailed(
m_d2dContext->CreateBitmap(
opacityBitmapSize,
(BYTE*)g_pImg,
sizeof(unsigned int)*g_sizex,
&properties,
&m_opacityBitmap
)
);
m_d2dContext->SetTarget(m_opacityBitmap.Get());
m_d2dContext->BeginDraw();
m_d2dContext->Clear(D2D1::ColorF(D2D1::ColorF::Black, 0.0f));
DX::ThrowIfFailed(
m_d2dContext->EndDraw()
);
std::thread* thread_tmp=new std::thread(example_main, (void*)NULL);
}
void tbbTachyonRenderer::CreateWindowSizeDependentResources()
{
DirectXBase::CreateWindowSizeDependentResources();
}
void tbbTachyonRenderer::Render()
{
D2D1_SIZE_F size = m_d2dContext->GetSize();
#if SHOW_TEXT
if (video && video->running)
global_elapsedTime=(long)(time(NULL)-global_startTime);
Platform::String^ text= "Running in " +
(global_number_of_threads == utility::get_default_num_threads()? "all hardware threads: ":
global_number_of_threads.ToString() + (global_number_of_threads==1?" thread: ":" threads: ")) +
global_elapsedTime.ToString() + (global_elapsedTime>1?" seconds":" second");
g_ratiox=float(size.width/1024.0);
g_ratioy=float(size.height/512.0);
DX::ThrowIfFailed(
m_dwriteFactory->CreateTextLayout(
text->Data(),
text->Length(),
m_textFormat.Get(),
1000, // maxWidth
1000, // maxHeight
&m_textLayout
)
);
m_textLayout->GetMetrics(&m_textMetrics);
#endif
m_d2dContext->BeginDraw();
if(g_pImg)m_opacityBitmap->CopyFromMemory( NULL,(BYTE*)g_pImg, sizeof(unsigned int)*g_sizex );
m_d2dContext->DrawBitmap( m_opacityBitmap.Get(), D2D1::RectF(0,0,size.width,size.height) );
#if SHOW_TEXT
m_d2dContext->DrawTextLayout(
D2D1::Point2F(0.0f, 0.0f),
m_textLayout.Get(),
m_Brush.Get(),
D2D1_DRAW_TEXT_OPTIONS_CLIP
);
#endif
HRESULT hr = m_d2dContext->EndDraw();
if (hr == D2DERR_RECREATE_TARGET){
m_d2dContext->SetTarget(nullptr);
m_d2dTargetBitmap = nullptr;
CreateWindowSizeDependentResources();
}else{
DX::ThrowIfFailed(hr);
}
m_renderNeeded = false;
}

View File

@@ -0,0 +1,42 @@
/*
Copyright (c) 2005-2020 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#pragma once
#include <wrl.h>
#include "DirectXBase.h"
ref class tbbTachyonRenderer sealed : public DirectXBase
{
public:
tbbTachyonRenderer();
virtual void CreateDeviceIndependentResources() override;
virtual void CreateDeviceResources() override;
virtual void CreateWindowSizeDependentResources() override;
virtual void Render() override;
void Update(float timeTotal, float timeDelta);
void UpdateView(Windows::Foundation::Point deltaViewPosition);
private:
Microsoft::WRL::ComPtr<ID2D1SolidColorBrush> m_Brush;
Microsoft::WRL::ComPtr<IDWriteTextFormat> m_textFormat;
Microsoft::WRL::ComPtr<ID2D1Bitmap1> m_opacityBitmap;
Microsoft::WRL::ComPtr<IDWriteTextLayout> m_textLayout;
DWRITE_TEXT_METRICS m_textMetrics;
bool m_renderNeeded;
~tbbTachyonRenderer();
};

View File

@@ -0,0 +1,572 @@
<!DOCTYPE html>
<html xmlns:mso="urn:schemas-microsoft-com:office:office" xmlns:msdt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882">
<head>
<meta charset="UTF-8">
<style>
::selection {
background: #b7ffb7;
}
::-moz-selection {
background: #b7ffb7;
}
body {
font-family: Arial, Helvetica, sans-serif;
font-size: 16px;
width: 800px;
margin: 0 auto;
}
#banner {
/* Div for banner */
float:left;
margin: 0px;
margin-bottom: 10px;
width: 100%;
background-color: #0071C5;
z-index: 0;
}
#banner .logo {
/* Apply to logo in banner. Add as class to image tag. */
float: left;
margin-right: 20px;
margin-left: 20px;
margin-top: 15px;
padding-bottom: 5px;
}
h1 {
text-align: center;
font-size: 36px;
}
h1.title {
/* Add as class to H1 in banner */
font-family: "Intel Clear", Verdana, Arial, sans-serif;
font-weight:normal;
color: #FFFFFF;
font-size: 170%;
margin-right: 40px;
margin-left: 40px;
padding-right: 20px;
text-indent: 20px;
}
.h3-alike {
display:inline;
font-size: 1.17em;
font-weight: bold;
color: #0071C5;
}
h3 {
font-size: 1.17em;
font-weight: bold;
color: #0071C5;
}
.h4-alike {
display:inline;
font-size: 1.05em;
font-weight: bold;
}
pre {
font-family: "Consolas", Monaco, monospace;
font-size:small;
background: #fafafa;
margin: 0;
padding-left:20px;
}
#footer {
font-size: small;
}
code {
font-family: "Consolas", Monaco, monospace;
}
.code-block
{
padding-left:20px;
}
.changes {
margin: 1em 0;
}
.changes input:active {
position: relative;
top: 1px;
}
.changes input:hover:after {
padding-left: 16px;
font-size: 10px;
content: 'More';
}
.changes input:checked:hover:after {
content: 'Less';
}
.changes input + .show-hide {
display: none;
}
.changes input:checked + .show-hide {
display: block;
}
ul {
margin: 0;
padding: 0.5em 0 0.5em 2.5em;
}
ul li {
margin-bottom: 3px;
}
ul li:last-child {
margin-bottom: 0;
}
.disc {
list-style-type:disc
}
.circ {
list-style-type:circle
}
.single {
padding: 0 0.5em;
}
/* ------------------------------------------------- */
/* Table styles */
table{
margin-bottom:5pt;
border-collapse:collapse;
margin-left:0px;
margin-top:0.3em;
font-size:10pt;
}
tr{
vertical-align:top;
}
th,
th h3{
padding:4px;
text-align:left;
background-color:#0071C5;
font-weight:bold;
margin-top:1px;
margin-bottom:0;
color:#FFFFFF;
font-size:10pt;
vertical-align:middle;
}
th{
border:1px #dddddd solid;
padding-top:2px;
padding-bottom:0px;
padding-right:3px;
padding-left:3px;
}
td{
border:1px #dddddd solid;
vertical-align:top;
font-size:100%;
text-align:left;
margin-bottom:0;
}
td,
td p{
margin-top:0;
margin-left:0;
text-align:left;
font-size:inherit;
line-height:120%;
}
td p{
margin-bottom:0;
padding-top:5px;
padding-bottom:5px;
padding-right:5px;
padding-left:1px;
}
.noborder{
border:0px none;
}
.noborder1stcol{
border:0px none;
padding-left:0pt;
}
td ol{
font-size:inherit;
margin-left:28px;
}
td ul{
font-size:inherit;
margin-left:24px;
}
.DefListTbl{
width:90%;
margin-left:-3pt;
}
.syntaxdiagramtbl{
margin-left:-3pt;
}
.sdtbl{
}
.sdrow{
}
.sdtblp{
border:0px none;
font-size:inherit;
line-height:120%;
margin-bottom:0;
padding-bottom:0px;
padding-top:5px;
padding-left:0px;
padding-right:5px;
vertical-align:top;
}
.idepara, .ide_para{
border:0px none;
font-size:inherit;
line-height:120%;
margin-bottom:0;
padding-bottom:0px;
padding-top:5px;
padding-left:0px;
padding-right:5px;
vertical-align:top;
}
.specs {
border-collapse:collapse;
}
.specs td, .specs th {
font-size: 14px;
}
.specs td {
border: 1px solid black;
}
.specs td td, .specs td th {
border: none;
}
.specs td, .specs td td, .specs td th {
padding: 0 0.2em 0.2em;
text-align: center;
}
.specs td tr:last-child td,
.specs td tr:last-child th {
padding: 0 0.2em;
}
.serial-time {
}
.modified-time {
width: 6.5em;
}
.compiler {
}
.comp-opt {
}
.sys-specs {
width: 18em;
}
.note {
font-size:small;
font-style: italic;
}
</style>
<title>Intel&reg; Threading Building Blocks. Tachyon sample</title>
</head>
<body>
<div id="banner">
<img class="logo" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEMAAAAsCAYAAAA+aAX8AAAAAXNSR0IArs4c6QAAAARnQU1BAACx
jwv8YQUAAAAJcEhZcwAALiIAAC4iAari3ZIAAAAZdEVYdFNvZnR3YXJlAEFkb2JlIEltYWdlUmVh
ZHlxyWU8AAAIN0lEQVRoQ+WaCaxdUxSGW2ouatZWaVS15nkqkZhSVERQglLEPCam1BCixhqqCKUS
NIiYpxhqHmouIeaY5ylFzA/v1fev8+/j3N5737v3vtf3buNP/uy9/7X2Ovuse4a997m9mgltbW2L
wRHwcHgFfAx+AH+GCb/BT2fNmvUk5ZXwYOrrOsTcCU5CJ74pPBJeA5+Bn8LfOLmagf/f8Af4NrwD
ngg3wdTHh2pOMMB1Gejx8AE4M85mNqD/A7+D78GXkXQFTIMPwUfhdPg6/AxWTRw29b8QruPD9zwY
zPrwHPi2xxmg3QrfgDfD05BGU24EB1HvC3s7REXgtwDsDzeEY+Ak+AJsUfwE2sJdcBN37V4whiU4
+KGUM2JEBtpzUInZEa5g9y4FcYfAo+GLPmwOND2HFrXrnAUHWgnq0vzDB2+Bt0H9coPs1m3gmNvD
ZyITBu234Jp26XoQfCC80sfTAXVv7wOXskuPgnHoSvnTw9P49MDdyOauAQEXhWdC4Vd4ARxmc1OB
cW0Gv3U+lJDvKFa0ufMg4GXwR3gs7J57sRNoaWnR2+znLB2RkKds6jwItvbckIQiGO+eTkSby71t
qh100qtsUCJxmmpSw5i2gWebR1jWm2047T1gf0vyfViJEKi/TtHua7wMdNJs8U/zDzjUpqYA47k4
O704wY+kUZ2P+glQc5ldac9j323sF1cH2EB6h8BxYZdbRDeDOJ16UBJiHDFuMMdYbhjEGA8DxJ4h
jXIemmMpz6ccqbZ1JUlT/3SrHC+9XeB0MjzV9RHqKFAXVg2nBkH/lxxO8aZYbhjEKEuGQH1BuCKc
z1IAN61jAtiut1wZ+ByIkwa6r9t6ZmhSFZw9eL0gxiMw4SLLDYMYFZNRDbhpcpgwzXI5MOqSEvKM
Ue8D+xU4r/Xe+C8HB1ThkhFgNqAXk6FVqyZuA1LcItBXQd+WUvf6YMslwFZvMs7KvMP/SculwKa3
hfYPPsZpfsvS9QD9PRHbcOmUC9J+H2qfoRJ/0MHgFhHIQC8mQ8twxZ0Ji099vSGegn/TP0BdD/Db
Ycn0nna9yZiceQcetFwKDE/4oNtZCtDeXHoC7dWlU1Uyvs7U6sBHJ7FaBAPU82TYJUAzFnCU+1mq
COyfwGLi6k3G05l34BrL/wFxjA/0mKUcaNqBKiJODHclQ3sLCVqZprfEvVCLtThhiskRDFAvXhnv
QPlfi5uW7ytTL14Nr0Bd1pfDXy1Lv93h6koGLstCLR/SuPJ5SQBBD8hPZATbWs6BrdZk7B4dDNpT
Mjkw3bL0YjLOsxygPUWDyExtD1GNV6JAeyTUBlDCKtbrScYxhfjyj1s+B9o+dnifIj94AnpNyaC9
f3QwkNJCTnjOsvRiMi6xrHiaA3ycyYFNbcqBpisl/aoHWaspGdg03uIc43mb/gOilt3CREslQG80
GedmlkC1KyNPBnU9wOPWMp6Aut0S74HfwIQJ7ldTMjBPdBIiGWC0TRkQlseWNmR2tlwC9DmZjEmW
pQ/zOAKqtwdcrnW/DpOBPtp9Ii6F9lhL1yWIo2zUvVhxzYHeLVcG/QfT/iuTA3qwan+zGndVP8p2
k4G8E/wLW4D6PxTlnxgwaDEjaMe6n+USYOvqZKTbUrjQcor3ZSYHRtjULvCrmgwkfY5oRc9B+3Cb
S4FhIhS+gAtZLgH9Y6GWuQU6mwx9IEqYajlA+47CsZ6lGovFBDTNkA9xM4CmpXsAWySDUrPjqZQl
QBsfnSoB41UKAvS9ouJmDfpaDpTQ2WRcXYinCZm+pdyEtDClPgLloP0unABPp3lrpoZ+KkWskSgP
sVZMhlat2t7LQftE2aoCh0sVBOheXclyCYjTp7W19bUsZAQtJuPLTA39gOhg0D7PJtny1xj1tWA+
sUpAG2j7mZaqAh9tzPSVP+XStL+w/qY1XRlfWdOSYXvp7QKnU6Ayqk4jLZcB2zD4gv1iu52qkvG5
NKPsyrCuPs9aDtDeDr4EtS7RRyXNCgfYLPtYfoC33D0Hul6tE6jOfvsMhVqaT8PWG85PXR+WxlOP
pHUIHPNXDsif7NWAT773STdlX6vK4ebi4WRgWybZqFe86tBXUAw4BL+S7UTautTXo9yFcjdKPbsq
PuQTsKdbZ16YLzZrAgdRRvXLCF/Big/R/wXInn5dffdMt8opNs214Bz6cyqNbUDRcZwTIWjDt3m+
XtcBxq3pvL6p6mFftlFUE+i8JPxRCRGoawVbcVepGcF4V4eTGPNPHv+7NjUGAhzmQOl20fyhphlg
T4CxLcQw9WC9Gxb3P4Q37NY4CHJXCuhSW3JnwEXs0qNgSHqVbw210ZP2XwK0A65/6C6NgziaAU5X
wCIUHB4H86227gKH1+JtL3gd1N5sCdACbgZo5rtgnQKx+hLs/ixsdjBXBd2TtyKNhUOp1/dprgMQ
rx9x16fcn1KbttrIyf9OkICWw1KApvY2YyXbpSBobKf7OGXApFtI+5d3Qq1BDoL6V87GcDVc9Ivq
E4D+bjTQbc1i9demreDu8Ch0ffG6hdnmDMrvFbsSsAXczIGk3fwb4VYe+pwBB9Angkd83ADtqgkq
AjetdTTV1icDlfl+Qi3AP4elHEjaDXscHgFjPdNt4ID6S9B9sNLiKoelmuFuJbCpDJi+hvqz2qFw
iIfWc2AQusxPgvq484vH2eUgtpYHH0Hteeqb75ZwMQ+j+cDg9PlwFDwd6o9sr0KtbWI/tSPgp32M
76H+s6mNX3030df5neGq1OtbZDUbOIlFoFaha0L9j0qfCHeAerDqVtODU8+hNThZfR1fHHbpG6kx
9Or1LzUmVVz+HJXDAAAAAElFTkSuQmCC">
<h1 class="title">Intel&reg; Threading Building Blocks.<br>Tachyon sample</h1>
</div>
<p>
Parallel raytracer / renderer that demonstrates the use of parallel_for.
</p>
<p><i>
This example includes software developed by John E. Stone. See
<a href="#copyright">here</a> for copyright information.
</i></p>
<p>
This example is a 2-D raytracer/renderer that visually shows different parallel scheduling
methods and their resulting speedup. The code was parallelized by speculating
that each pixel could be rendered in parallel. The resulting parallel code was
then checked for correctness by using Intel&reg; Thread Checker, which
pointed out where synchronization was needed. Minimal synchronization was then
inserted into the parallel code. The resulting parallel code exhibits good speedup.
</p>
<div class="changes">
<div class="h3-alike">System Requirements</div>
<input type="checkbox">
<div class="show-hide">
<p>
For the most up to date system requirements, see the <a href="http://software.intel.com/en-us/articles/intel-threading-building-blocks-release-notes">release notes.</a>
</p>
</div>
</div>
<div class="changes">
<div class="h3-alike">Versions</div>
<input type="checkbox" checked="checked">
<div class="show-hide">
<dl>
<dt><b>serial</b>
<dd>Original sequential version.
<dt><b>tbb1d</b>
<dd>Parallel version that uses Intel&reg; Threading Building Blocks (Intel&reg; TBB) and blocked_range to parallelize
over tasks that are groups of scan-lines.
<ul>
<li>By default, this version uses one thread per available processor. To change this
default, set the TBB_NUM_THREADS environment variable to the desired number of threads before running.
<li>This version uses the preview feature: auto_range_partitioner. No grain size is provided to blocked_range.
The blocked_range class uses a default grain size of 1 when none is provided. However, the auto_range_partitioner
controls the amount of range splitting dynamically at runtime, resulting in sub-ranges of varying sizes.
</ul>
<dt><b>tbb</b>
<dd>Parallel version that uses Intel TBB and blocked_range2d to parallelize
over tasks that are rectangular sub-areas.
<ul>
<li>By default, this version uses one thread per available processor. To change this
default, set the TBB_NUM_THREADS environment variable to the desired number of threads before running.
<li>This version uses a reasonable task grain size by default. To change this default,
set the TBB_GRAINSIZE environment variable to the desired grain size before running.
The grain size corresponds to the number of pixels (in the X or Y direction, for a
rectangular sub-area) in each parallel task.
</ul>
</dl>
</div>
</div>
<div class="changes">
<div class="h3-alike">Files</div>
<input type="checkbox" checked="checked">
<div class="show-hide">
<dl>
<dt><a href="src/main.cpp">src/main.cpp</a>
<dd>Main program which parses command line options and runs the raytracer.
<dt><a href="src/tachyon_video.cpp">src/tachyon_video.cpp</a>
<dd>Source code for GUI interfaces.
<dt><a href="src/trace.serial.cpp">src/trace.serial.cpp</a>
<dd>Source code for original sequential version of example.
<dt><a href="src/trace.tbb1d.cpp">src/trace.tbb1d.cpp</a>
<dd>Source code for Intel TBB blocked_range (scan-line) version of example.
<dt><a href="src/trace.tbb.cpp">src/trace.tbb.cpp</a>
<dd>Source code for Intel TBB blocked_range2d (rectangular sub-area) version of example.
<dt>(src/*.cpp)
<dd>Remainder of source code for example.
<dt>(src/*.h)
<dd>Remainder of include files for example.
<dt><a href="Makefile">Makefile</a>
<dd>Makefile for building the example.
</dl>
</div>
</div>
<div class="changes">
<div class="h3-alike">Directories</div>
<input type="checkbox" checked="checked">
<div class="show-hide">
<dl>
<dt><a href="src/">src</a>
<dd>Contains source code and include files for the example.
<dt><a href="dat/">dat</a>
<dd>Contains data sets for running the example.
<dt><a href="msvs/">msvs</a>
<dd>Contains Microsoft* Visual Studio* workspace for building and running the example (Windows* systems only).
<dt><a href="xcode/">xcode</a>
<dd>Contains Xcode* IDE workspace for building and running the example (macOS* systems only).
</dl>
<p>For information about the minimum supported version of IDE, see <a href="http://software.intel.com/en-us/articles/intel-threading-building-blocks-release-notes">release notes.</a></p>
</div>
</div>
<div class="changes">
<div class="h3-alike">Build instructions</div>
<input type="checkbox" checked="checked">
<div class="show-hide">
<p>General build directions can be found <a href="../../index.html">here</a>.</p>
<p>
For Windows* systems Microsoft* Visual Studio* projects are provided for each of the above example versions.
</p>
<p>
The Makefile supports the following build targets (in addition to the <a href="../../index.html">general</a> ones).
Here, &lt;<i>version</i>&gt; is one of the above versions of the example, i.e., {serial, tbb1d, tbb}.
</p>
<dl>
<dt><tt>make &lt;<i>version</i>&gt;[_debug]</tt>
<dd>Build and run a single version (release or debug).
Equivalent to 'make build_&lt;<i>version</i>&gt;[_debug] run_&lt;<i>version</i>&gt;'.
<dt><tt>make build_&lt;<i>version</i>&gt;[_debug]</tt>
<dd>Compile and link a single version (release or debug).
The resulting executable is left in the directory for the example.
<dt><tt>make run_&lt;<i>version</i>&gt;</tt>
<dd>Run a single version previously produced by one of the above commands.
<dt><tt>make [(above options or targets)] DATASET={820spheres, balls, balls3, lattice, model2,
teapot, trypsin4pti}</tt>
<dd>Build and run as above, but run with the specified data set.
<dt><tt>make [(above options or targets)] ARGS=-D</tt>
<dd>Build and run as above, but run with disabled run-time display updating for use in making performance measurements
<i>(strongly recommended when measuring performance or scalability; see note below)</i>.
<dt><tt>make [(above options or targets)] UI={con, gdi, d2d, x, mac}</tt>
<dd>Build and run as usual, but build with the specified GUI driver: console, GDI+*, Direct2D*, X11, or OpenGL*
(see the description of the <a href="../../common/index.html">common GUI code</a>
for more information on available graphics support).
For Linux* and macOS* systems, the best available driver is detected automatically by the Makefile.
For Windows* systems, UI=gdi is the default GUI driver; compiling with UI=d2d may offer superior
performance, but can only be used if the Microsoft* DirectX* SDK is installed on your system.
Use UI=con to build without the GUI for use in making performance measurements
<i>(strongly recommended when measuring performance or scalability; see note below)</i>.
<dt><tt>make [(above options or targets)] XARCH=x64</tt>
<dd>Build and run as above, but
also specify XARCH=x64 (or XARCH=AMD64 for older compilers) when building the example on Windows* as a 64-bit binary.
<dt><tt>make [(above options or targets)] DDLIB_DIR=&lt;<i>specify path to Direct Draw* SDK here</i>&gt;</tt>
<dd>If you experience ddraw.lib linking problems, specify the correct library directory via this option.
</dl>
</div>
</div>
<div class="changes">
<div class="h3-alike">Usage</div>
<input type="checkbox" checked="checked">
<div class="show-hide">
<p>
Building via the above make commands, or via Visual Studio projects on Windows* systems, produces executable files
named <tt>tachyon.&lt;<i>version</i>&gt;.exe</tt>. To run these executables directly, use one or more of the following commands.
</p>
<dl>
<dt><tt>tachyon.&lt;<i>version</i>&gt; <i>-h</i></tt>
<dd>Prints the help for command line options
<dt><tt>tachyon.&lt;<i>version</i>&gt; [<i>dataset</i>=value] [<i>boundthresh</i>=value] [<i>no-display-updating</i>] [<i>nobounding</i>] [<i>silent</i>]</tt>
<dt><tt>tachyon.&lt;<i>version</i>&gt; [<i>dataset</i> [<i>boundthresh</i>]] [<i>no-display-updating</i>] [<i>nobounding</i>] [<i>silent</i>]</tt>
<dd><i>dataset</i> is the path/name of one of the *.dat files in the <a href="dat">dat</a> directory for the example.<br>
<i>boundthresh</i> is a bounding threshold value.<br>
<i>no-display-updating</i> - disable run-time display updating.<br>
<i>no-bounding</i> - disable bounding technique.<br>
<i>silent</i> - no output except elapsed time.<br>
<dt><tt>tachyon.&lt;<i>version</i>&gt; [<i>dataset</i>] [<i>no-display-updating</i>]</tt>
<dd>Run this version (release or debug), but run with disabled run-time display updating
for use in making performance measurements
<i>(strongly recommended when measuring performance or scalability; see note below)</i>.
<dt>To run a short version of this example, e.g., for use with Intel&reg; Parallel Inspector:
<dd>Build a <i>debug</i> version of the <tt>tbb</tt> example with the GUI turned off
(e.g., <tt>make UI=con tbb_debug</tt>; see also the build directions above).
<br>Run it with a small dataset, e.g., <tt>tachyon.tbb.exe dat/820spheres.dat no-display-updating</tt>.
</dl>
</div>
</div>
<div class="changes">
<div class="h3-alike">Keys</div>
<input type="checkbox" checked="checked">
<div class="show-hide">
<p>While running with the GUI display turned on the following keyboard keys can be used:</p>
<dl>
<dt><tt>ESC</tt>
<dd>Interrupt the rendering and exit
<dt><tt><i>Any key</i></tt>
<dd>Enable repetition of rendering after the pause. Press ESC to stop the application.
<dt><tt>Space</tt>
<dd>Toggle run-time display updating mode while rendering (see no-display-updating above).
<dt><tt>p</tt>
<dd>Holds the picture after rendering completion. Press 'p' again to continue.
</dl>
</div>
</div>
<div class="changes">
<div class="h3-alike">Notes</div>
<input type="checkbox" checked="checked">
<div class="show-hide">
<ul>
<li>While running with the GUI display turned on should yield reasonable performance in most cases, <i>running with the GUI
display turned off is strongly recommended</i> in order to demonstrate the full performance and scalability of the example.
</ul>
</div>
</div>
<br>
<a href="../index.html">Up to parent directory</a>
<hr>
<a name="copyright"></a>
<div class="changes">
<div class="h3-alike">Legal Information</div>
<input type="checkbox">
<div class="show-hide">
<p>
Intel and the Intel logo are trademarks of Intel Corporation in the U.S. and/or other countries.
<br>* Other names and brands may be claimed as the property of others.
<br>&copy; 2020, Intel Corporation
</p>
<p>
The original source for this example is
Copyright (c) 1994-2008 John E. Stone
All rights reserved.
</p>
<p>
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
<ol>
<li>Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
<li>Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
<li>The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.
</ol>
</p>
<p>
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
</p>
</div>
</div>
</body>
</html>

View File

@@ -0,0 +1,414 @@
/*
Copyright (c) 2005-2020 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*
The original source for this example is
Copyright (c) 1994-2008 John E. Stone
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
*/
/*
* api.cpp - This file contains all of the API calls that are defined for
* external driver code to use.
*/
#include "machine.h"
#include "types.h"
#include "macros.h"
#include "box.h"
#include "cylinder.h"
#include "plane.h"
#include "quadric.h"
#include "ring.h"
#include "sphere.h"
#include "triangle.h"
#include "vol.h"
#include "extvol.h"
#include "texture.h"
#include "light.h"
#include "render.h"
#include "camera.h"
#include "vector.h"
#include "intersect.h"
#include "shade.h"
#include "util.h"
#include "imap.h"
#include "global.h"
#include "tachyon_video.h"
typedef void * SceneHandle;
#include "api.h"
vector rt_vector(apiflt x, apiflt y, apiflt z) {
vector v;
v.x = x;
v.y = y;
v.z = z;
return v;
}
color rt_color(apiflt r, apiflt g, apiflt b) {
color c;
c.r = r;
c.g = g;
c.b = b;
return c;
}
void rt_initialize() {
rpcmsg msg;
reset_object();
reset_lights();
InitTextures();
if (!parinitted) {
parinitted=1;
msg.type=1; /* setup a ping message */
}
}
void rt_renderscene(SceneHandle voidscene) {
scenedef * scene = (scenedef *) voidscene;
renderscene(*scene);
}
void rt_camerasetup(SceneHandle voidscene, apiflt zoom, apiflt aspectratio,
int antialiasing, int raydepth,
vector camcent, vector viewvec, vector upvec) {
scenedef * scene = (scenedef *) voidscene;
vector newupvec;
vector newviewvec;
vector newrightvec;
VCross((vector *) &upvec, &viewvec, &newrightvec);
VNorm(&newrightvec);
VCross((vector *) &viewvec, &newrightvec, &newupvec);
VNorm(&newupvec);
newviewvec=viewvec;
VNorm(&newviewvec);
scene->camzoom=zoom;
scene->aspectratio=aspectratio;
scene->antialiasing=antialiasing;
scene->raydepth=raydepth;
scene->camcent=camcent;
scene->camviewvec=newviewvec;
scene->camrightvec=newrightvec;
scene->camupvec=newupvec;
}
void rt_outputfile(SceneHandle voidscene, const char * outname) {
scenedef * scene = (scenedef *) voidscene;
strcpy((char *) &scene->outfilename, outname);
}
void rt_resolution(SceneHandle voidscene, int hres, int vres) {
scenedef * scene = (scenedef *) voidscene;
scene->hres=hres;
scene->vres=vres;
}
void rt_verbose(SceneHandle voidscene, int v) {
scenedef * scene = (scenedef *) voidscene;
scene->verbosemode = v;
}
void rt_rawimage(SceneHandle voidscene, unsigned char *rawimage) {
scenedef * scene = (scenedef *) voidscene;
scene->rawimage = rawimage;
}
void rt_background(SceneHandle voidscene, color col) {
scenedef * scene = (scenedef *) voidscene;
scene->background.r = col.r;
scene->background.g = col.g;
scene->background.b = col.b;
}
void rt_boundmode(SceneHandle voidscene, int mode) {
scenedef * scene = (scenedef *) voidscene;
scene->boundmode = mode;
}
void rt_boundthresh(SceneHandle voidscene, int threshold) {
scenedef * scene = (scenedef *) voidscene;
if (threshold > 1) {
scene->boundthresh = threshold;
}
else {
rtmesg("Ignoring out-of-range automatic bounding threshold.\n");
rtmesg("Automatic bounding threshold reset to default.\n");
scene->boundthresh = MAXOCTNODES;
}
}
void rt_displaymode(SceneHandle voidscene, int mode) {
scenedef * scene = (scenedef *) voidscene;
scene->displaymode = mode;
}
void rt_scenesetup(SceneHandle voidscene, char * outname, int hres, int vres, int verbose) {
rt_outputfile(voidscene, outname);
rt_resolution(voidscene, hres, vres);
rt_verbose(voidscene, verbose);
}
SceneHandle rt_newscene(void) {
scenedef * scene;
SceneHandle voidscene;
scene = (scenedef *) malloc(sizeof(scenedef));
memset(scene, 0, sizeof(scenedef)); /* clear all valuas to 0 */
voidscene = (SceneHandle) scene;
rt_outputfile(voidscene, "/dev/null"); /* default output file (.tga) */
rt_resolution(voidscene, 512, 512); /* 512x512 resolution */
rt_verbose(voidscene, 0); /* verbose messages off */
rt_rawimage(voidscene, NULL); /* raw image output off */
rt_boundmode(voidscene, RT_BOUNDING_ENABLED); /* spatial subdivision on */
rt_boundthresh(voidscene, MAXOCTNODES); /* default threshold */
rt_displaymode(voidscene, RT_DISPLAY_ENABLED); /* video output on */
rt_camerasetup(voidscene, 1.0, 1.0, 0, 6,
rt_vector(0.0, 0.0, 0.0),
rt_vector(0.0, 0.0, 1.0),
rt_vector(0.0, 1.0, 0.0));
return scene;
}
void rt_deletescene(SceneHandle scene) {
if (scene != NULL)
free(scene);
}
void apitextotex(apitexture * apitex, texture * tex) {
switch(apitex->texturefunc) {
case 0:
tex->texfunc=(color(*)(void *, void *, void *))(standard_texture);
break;
case 1:
tex->texfunc=(color(*)(void *, void *, void *))(checker_texture);
break;
case 2:
tex->texfunc=(color(*)(void *, void *, void *))(grit_texture);
break;
case 3:
tex->texfunc=(color(*)(void *, void *, void *))(marble_texture);
break;
case 4:
tex->texfunc=(color(*)(void *, void *, void *))(wood_texture);
break;
case 5:
tex->texfunc=(color(*)(void *, void *, void *))(gnoise_texture);
break;
case 6:
tex->texfunc=(color(*)(void *, void *, void *))(cyl_checker_texture);
break;
case 7:
tex->texfunc=(color(*)(void *, void *, void *))(image_sphere_texture);
tex->img=AllocateImage((char *)apitex->imap);
break;
case 8:
tex->texfunc=(color(*)(void *, void *, void *))(image_cyl_texture);
tex->img=AllocateImage((char *)apitex->imap);
break;
case 9:
tex->texfunc=(color(*)(void *, void *, void *))(image_plane_texture);
tex->img=AllocateImage((char *)apitex->imap);
break;
default:
tex->texfunc=(color(*)(void *, void *, void *))(standard_texture);
break;
}
tex->ctr = apitex->ctr;
tex->rot = apitex->rot;
tex->scale = apitex->scale;
tex->uaxs = apitex->uaxs;
tex->vaxs = apitex->vaxs;
tex->ambient = apitex->ambient;
tex->diffuse = apitex->diffuse;
tex->specular = apitex->specular;
tex->opacity = apitex->opacity;
tex->col = apitex->col;
tex->islight = 0;
tex->shadowcast = 1;
tex->phong = 0.0;
tex->phongexp = 0.0;
tex->phongtype = 0;
}
void * rt_texture(apitexture * apitex) {
texture * tex;
tex=(texture *)rt_getmem(sizeof(texture));
apitextotex(apitex, tex);
return(tex);
}
void rt_tex_color(void * voidtex, color col) {
texture * tex = (texture *) voidtex;
tex->col = col;
}
void rt_tex_phong(void * voidtex, apiflt phong, apiflt phongexp, int type) {
texture * tex = (texture *) voidtex;
tex->phong = phong;
tex->phongexp = phongexp;
tex->phongtype = type;
}
void rt_light(void * tex, vector ctr, apiflt rad) {
point_light * li;
li=newlight(tex, (vector) ctr, rad);
li->tex->islight=1;
li->tex->shadowcast=1;
li->tex->diffuse=0.0;
li->tex->specular=0.0;
li->tex->opacity=1.0;
add_light(li);
add_object((object *)li);
}
void rt_scalarvol(void * tex, vector min, vector max,
int xs, int ys, int zs, char * fname, void * invol) {
add_object((object *) newscalarvol(tex, (vector)min, (vector)max, xs, ys, zs, fname, (scalarvol *) invol));
}
void rt_extvol(void * tex, vector min, vector max, int samples, flt (* evaluator)(flt, flt, flt)) {
add_object((object *) newextvol(tex, (vector)min, (vector)max, samples, evaluator));
}
void rt_box(void * tex, vector min, vector max) {
add_object((object *) newbox(tex, (vector)min, (vector)max));
}
void rt_cylinder(void * tex, vector ctr, vector axis, apiflt rad) {
add_object(newcylinder(tex, (vector)ctr, (vector)axis, rad));
}
void rt_fcylinder(void * tex, vector ctr, vector axis, apiflt rad) {
add_object(newfcylinder(tex, (vector)ctr, (vector)axis, rad));
}
void rt_plane(void * tex, vector ctr, vector norm) {
add_object(newplane(tex, (vector)ctr, (vector)norm));
}
void rt_ring(void * tex, vector ctr, vector norm, apiflt a, apiflt b) {
add_object(newring(tex, (vector)ctr, (vector)norm, a, b));
}
void rt_sphere(void * tex, vector ctr, apiflt rad) {
add_object(newsphere(tex, (vector)ctr, rad));
}
void rt_tri(void * tex, vector v0, vector v1, vector v2) {
object * trn;
trn = newtri(tex, (vector)v0, (vector)v1, (vector)v2);
if (trn != NULL) {
add_object(trn);
}
}
void rt_stri(void * tex, vector v0, vector v1, vector v2,
vector n0, vector n1, vector n2) {
object * trn;
trn = newstri(tex, (vector)v0, (vector)v1, (vector)v2, (vector)n0, (vector)n1, (vector)n2);
if (trn != NULL) {
add_object(trn);
}
}
void rt_quadsphere(void * tex, vector ctr, apiflt rad) {
quadric * q;
flt factor;
q=(quadric *) newquadric();
factor= 1.0 / (rad*rad);
q->tex=(texture *)tex;
q->ctr=ctr;
q->mat.a=factor;
q->mat.b=0.0;
q->mat.c=0.0;
q->mat.d=0.0;
q->mat.e=factor;
q->mat.f=0.0;
q->mat.g=0.0;
q->mat.h=factor;
q->mat.i=0.0;
q->mat.j=-1.0;
add_object((object *)q);
}

View File

@@ -0,0 +1,204 @@
/*
Copyright (c) 2005-2020 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*
The original source for this example is
Copyright (c) 1994-2008 John E. Stone
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
*/
/*****************************************************************************
* api.h - The declarations and prototypes needed so that 3rd party driver *
* code can run the raytracer. Third party driver code should *
* only use the functions in this header file to interface with *
* the rendering engine. *
*************************************************************************** */
/*
* $Id: api.h,v 1.2 2007-02-22 17:54:15 Exp $
*/
/********************************************/
/* Types defined for use with the API calls */
/********************************************/
#ifdef USESINGLEFLT
typedef float apiflt; /* generic floating point number */
#else
typedef double apiflt; /* generic floating point number */
#endif
typedef void * SceneHandle;
typedef struct {
int texturefunc; /* which texture function to use */
color col; /* base object color */
int shadowcast; /* does the object cast a shadow */
apiflt ambient; /* ambient lighting */
apiflt diffuse; /* diffuse reflection */
apiflt specular; /* specular reflection */
apiflt opacity; /* how opaque the object is */
vector ctr; /* origin of texture */
vector rot; /* rotation of texture around origin */
vector scale; /* scale of texture in x,y,z */
vector uaxs; /* planar map u axis */
vector vaxs; /* planar map v axis */
char imap[96]; /* name of image map */
} apitexture;
/*******************************************************************
* NOTE: The value passed in apitexture.texturefunc corresponds to
* the meanings given in this table:
*
* 0 - No texture function is applied other than standard lighting.
* 1 - 3D checkerboard texture. Red & Blue checkers through 3d space.
* 2 - Grit texture, roughens up the surface of the object a bit.
* 3 - 3D marble texture. Makes a 3D swirl pattern through the object.
* 4 - 3D wood texture. Makes a 3D wood pattern through the object.
* 5 - 3D gradient noise function.
* 6 - I've forgotten :-)
* 7 - Cylindrical Image Map **** IMAGE MAPS REQUIRE the filename
* 8 - Spherical Image Map of the image be put in imap[]
* 9 - Planar Image Map part of the texture...
* planar requires uaxs, and vaxs..
*
*******************************************************************/
/********************************************/
/* Functions implemented to provide the API */
/********************************************/
vector rt_vector(apiflt x, apiflt y, apiflt z); /* helper to make vectors */
color rt_color(apiflt r, apiflt g, apiflt b); /* helper to make colors */
void rt_initialize();/* reset raytracer, memory deallocation */
void rt_finalize(void); /* close down for good.. */
SceneHandle rt_newscene(void); /* allocate new scene */
void rt_deletescene(SceneHandle); /* delete a scene */
void rt_renderscene(SceneHandle); /* raytrace the current scene */
void rt_outputfile(SceneHandle, const char * outname);
void rt_resolution(SceneHandle, int hres, int vres);
void rt_verbose(SceneHandle, int v);
void rt_rawimage(SceneHandle, unsigned char *rawimage);
void rt_background(SceneHandle, color);
/* Parameter values for rt_boundmode() */
#define RT_BOUNDING_DISABLED 0
#define RT_BOUNDING_ENABLED 1
void rt_boundmode(SceneHandle, int);
void rt_boundthresh(SceneHandle, int);
/* Parameter values for rt_displaymode() */
#define RT_DISPLAY_DISABLED 0
#define RT_DISPLAY_ENABLED 1
void rt_displaymode(SceneHandle, int);
void rt_scenesetup(SceneHandle, char *, int, int, int);
/* scene, output filename, horizontal resolution, vertical resolution,
verbose mode */
void rt_camerasetup(SceneHandle, apiflt, apiflt, int, int,
vector, vector, vector);
/* camera parms: scene, zoom, aspectratio, antialiasing, raydepth,
camera center, view direction, up direction */
void * rt_texture(apitexture *);
/* pointer to the texture struct that would have been passed to each
object() call in older revisions.. */
void rt_light(void * , vector, apiflt); /* add a light */
/* light parms: texture, center, radius */
void rt_sphere(void *, vector, apiflt); /* add a sphere */
/* sphere parms: texture, center, radius */
void rt_scalarvol(void *, vector, vector,
int, int, int, char *, void *);
void rt_extvol(void *, vector, vector, int, apiflt (* evaluator)(apiflt, apiflt, apiflt));
void rt_box(void *, vector, vector);
/* box parms: texture, min, max */
void rt_plane(void *, vector, vector);
/* plane parms: texture, center, normal */
void rt_ring(void *, vector, vector, apiflt, apiflt);
/* ring parms: texture, center, normal, inner, outer */
void rt_tri(void *, vector, vector, vector);
/* tri parms: texture, vertex 0, vertex 1, vertex 2 */
void rt_stri(void *, vector, vector, vector,
vector, vector, vector);
/* stri parms: texture, vertex 0, vertex 1, vertex 2, norm 0, norm 1, norm 2 */
void rt_heightfield(void *, vector, int, int, apiflt *, apiflt, apiflt);
/* field parms: texture, center, m, n, field, wx, wy */
void rt_landscape(void *, int, int, vector, apiflt, apiflt);
void rt_quadsphere(void *, vector, apiflt); /* add quadric sphere */
/* sphere parms: texture, center, radius */
void rt_cylinder(void *, vector, vector, apiflt);
void rt_fcylinder(void *, vector, vector, apiflt);
void rt_polycylinder(void *, vector *, int, apiflt);
/* new texture handling routines */
void rt_tex_color(void * voidtex, color col);
#define RT_PHONG_PLASTIC 0
#define RT_PHONG_METAL 1
void rt_tex_phong(void * voidtex, apiflt phong, apiflt phongexp, int type);

View File

@@ -0,0 +1,264 @@
/*
Copyright (c) 2005-2020 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*
The original source for this example is
Copyright (c) 1994-2008 John E. Stone
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
*/
/*
* api.cpp - This file contains all of the API calls that are defined for
* external driver code to use.
*/
#include "machine.h"
#include "types.h"
#include "api.h"
#include "macros.h"
#include "vector.h"
#define MyVNorm(a) VNorm ((vector *) a)
void rt_polycylinder(void * tex, vector * points, int numpts, apiflt rad) {
vector a;
int i;
if ((points == NULL) || (numpts == 0)) {
return;
}
if (numpts > 0) {
rt_sphere(tex, points[0], rad);
if (numpts > 1) {
for (i=1; i<numpts; i++) {
a.x = points[i].x - points[i-1].x;
a.y = points[i].y - points[i-1].y;
a.z = points[i].z - points[i-1].z;
rt_fcylinder(tex, points[i-1], a, rad);
rt_sphere(tex, points[i], rad);
}
}
}
}
void rt_heightfield(void * tex, vector ctr, int m, int n,
apiflt * field, apiflt wx, apiflt wy) {
int xx,yy;
vector v0, v1, v2;
apiflt xoff, yoff, zoff;
xoff=ctr.x - (wx / 2.0);
yoff=ctr.z - (wy / 2.0);
zoff=ctr.y;
for (yy=0; yy<(n-1); yy++) {
for (xx=0; xx<(m-1); xx++) {
v0.x=wx*(xx )/(m*1.0) + xoff;
v0.y=field[(yy )*m + (xx )] + zoff;
v0.z=wy*(yy )/(n*1.0) + yoff;
v1.x=wx*(xx + 1)/(m*1.0) + xoff;
v1.y=field[(yy )*m + (xx + 1)] + zoff;
v1.z=wy*(yy )/(n*1.0) + yoff;
v2.x=wx*(xx + 1)/(m*1.0) + xoff;
v2.y=field[(yy + 1)*m + (xx + 1)] + zoff;
v2.z=wy*(yy + 1)/(n*1.0) + yoff;
rt_tri(tex, v1, v0, v2);
v0.x=wx*(xx )/(m*1.0) + xoff;
v0.y=field[(yy )*m + (xx )] + zoff;
v0.z=wy*(yy )/(n*1.0) + yoff;
v1.x=wx*(xx )/(m*1.0) + xoff;
v1.y=field[(yy + 1)*m + (xx )] + zoff;
v1.z=wy*(yy + 1)/(n*1.0) + yoff;
v2.x=wx*(xx + 1)/(m*1.0) + xoff;
v2.y=field[(yy + 1)*m + (xx + 1)] + zoff;
v2.z=wy*(yy + 1)/(n*1.0) + yoff;
rt_tri(tex, v0, v1, v2);
}
}
} /* end of heightfield */
static void rt_sheightfield(void * tex, vector ctr, int m, int n,
apiflt * field, apiflt wx, apiflt wy) {
vector * vertices;
vector * normals;
vector offset;
apiflt xinc, yinc;
int x, y, addr;
vertices = (vector *) malloc(m*n*sizeof(vector));
normals = (vector *) malloc(m*n*sizeof(vector));
offset.x = ctr.x - (wx / 2.0);
offset.y = ctr.z - (wy / 2.0);
offset.z = ctr.y;
xinc = wx / ((apiflt) m);
yinc = wy / ((apiflt) n);
/* build vertex list */
for (y=0; y<n; y++) {
for (x=0; x<m; x++) {
addr = y*m + x;
vertices[addr] = rt_vector(
x * xinc + offset.x,
field[addr] + offset.z,
y * yinc + offset.y);
}
}
/* build normals from vertex list */
for (x=1; x<m; x++) {
normals[x] = normals[(n - 1)*m + x] = rt_vector(0.0, 1.0, 0.0);
}
for (y=1; y<n; y++) {
normals[y*m] = normals[y*m + (m-1)] = rt_vector(0.0, 1.0, 0.0);
}
for (y=1; y<(n-1); y++) {
for (x=1; x<(m-1); x++) {
addr = y*m + x;
normals[addr] = rt_vector(
-(field[addr + 1] - field[addr - 1]) / (2.0 * xinc),
1.0,
-(field[addr + m] - field[addr - m]) / (2.0 * yinc));
MyVNorm(&normals[addr]);
}
}
/* generate actual triangles */
for (y=0; y<(n-1); y++) {
for (x=0; x<(m-1); x++) {
addr = y*m + x;
rt_stri(tex, vertices[addr], vertices[addr + 1 + m], vertices[addr + 1],
normals[addr], normals[addr + 1 + m], normals[addr + 1]);
rt_stri(tex, vertices[addr], vertices[addr + m], vertices[addr + 1 + m],
normals[addr], normals[addr + m], normals[addr + 1 + m]);
}
}
free(normals);
free(vertices);
} /* end of smoothed heightfield */
static void adjust(apiflt *base, int xres, int yres, apiflt wx, apiflt wy,
int xa, int ya, int x, int y, int xb, int yb) {
apiflt d, v;
if (base[x + (xres*y)]==0.0) {
d=(abs(xa - xb) / (xres * 1.0))*wx + (abs(ya - yb) / (yres * 1.0))*wy;
v=(base[xa + (xres*ya)] + base[xb + (xres*yb)]) / 2.0 +
(((((rand() % 1000) - 500.0)/500.0)*d) / 8.0);
if (v < 0.0) v=0.0;
if (v > (xres + yres)) v=(xres + yres);
base[x + (xres * y)]=v;
}
}
static void subdivide(apiflt *base, int xres, int yres, apiflt wx, apiflt wy,
int x1, int y1, int x2, int y2) {
long x,y;
if (((x2 - x1) < 2) && ((y2 - y1) < 2)) { return; }
x=(x1 + x2) / 2;
y=(y1 + y2) / 2;
adjust(base, xres, yres, wx, wy, x1, y1, x, y1, x2, y1);
adjust(base, xres, yres, wx, wy, x2, y1, x2, y, x2, y2);
adjust(base, xres, yres, wx, wy, x1, y2, x, y2, x2, y2);
adjust(base, xres, yres, wx, wy, x1, y1, x1, y, x1, y2);
if (base[x + xres*y]==0.0) {
base[x + (xres * y)]=(base[x1 + xres*y1] + base[x2 + xres*y1] +
base[x2 + xres*y2] + base[x1 + xres*y2] )/4.0;
}
subdivide(base, xres, yres, wx, wy, x1, y1 ,x ,y);
subdivide(base, xres, yres, wx, wy, x, y1, x2, y);
subdivide(base, xres, yres, wx, wy, x, y, x2, y2);
subdivide(base, xres, yres, wx, wy, x1, y, x, y2);
}
void rt_landscape(void * tex, int m, int n,
vector ctr, apiflt wx, apiflt wy) {
int totalsize, x, y;
apiflt * field;
totalsize=m*n;
srand(totalsize);
field=(apiflt *) malloc(totalsize*sizeof(apiflt));
for (y=0; y<n; y++) {
for (x=0; x<m; x++) {
field[x + y*m]=0.0;
}
}
field[0 + 0]=1.0 + (rand() % 100)/100.0;
field[m - 1]=1.0 + (rand() % 100)/100.0;
field[0 + m*(n - 1)]=1.0 + (rand() % 100)/100.0;
field[m - 1 + m*(n - 1)]=1.0 + (rand() % 100)/100.0;
subdivide(field, m, n, wx, wy, 0, 0, m-1, n-1);
rt_sheightfield(tex, ctr, m, n, field, wx, wy);
free(field);
}

View File

@@ -0,0 +1,222 @@
/*
Copyright (c) 2005-2020 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*
The original source for this example is
Copyright (c) 1994-2008 John E. Stone
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
*/
/*
* apitrigeom.cpp - This file contains code for generating triangle tessellated
* geometry, for use with OpenGL, XGL, etc.
*/
#include "machine.h"
#include "types.h"
#include "api.h"
#include "macros.h"
#include "vector.h"
#define MyVNorm(a) VNorm ((vector *) a)
#define MyVCross(a,b,c) VCross ((vector *) a, (vector *) b, (vector *) c)
#define MyVAddS(x,a,b,c) VAddS ((flt) x, (vector *) a, (vector *) b, (vector *) c)
#define CYLFACETS 36
#define RINGFACETS 36
#define SPHEREFACETS 25
void rt_tri_fcylinder(void * tex, vector ctr, vector axis, apiflt rad) {
vector x, y, z, tmp;
double u, v, u2, v2;
int j;
vector p1, p2, p3, p4;
vector n1, n2;
z = axis;
MyVNorm(&z);
tmp.x = z.y - 2.1111111;
tmp.y = -z.z + 3.14159267;
tmp.z = z.x - 3.915292342341;
MyVNorm(&z);
MyVNorm(&tmp);
MyVCross(&z, &tmp, &x);
MyVNorm(&x);
MyVCross(&x, &z, &y);
MyVNorm(&y);
for (j=0; j<CYLFACETS; j++) {
u = rad * sin((6.28 * j) / (CYLFACETS - 1.0));
v = rad * cos((6.28 * j) / (CYLFACETS - 1.0));
u2 = rad * sin((6.28 * (j + 1.0)) / (CYLFACETS - 1.0));
v2 = rad * cos((6.28 * (j + 1.0)) / (CYLFACETS - 1.0));
p1.x = p1.y = p1.z = 0.0;
p4 = p3 = p2 = p1;
MyVAddS(u, &x, &p1, &p1);
MyVAddS(v, &y, &p1, &p1);
n1 = p1;
MyVNorm(&n1);
MyVAddS(1.0, &ctr, &p1, &p1);
MyVAddS(u2, &x, &p2, &p2);
MyVAddS(v2, &y, &p2, &p2);
n2 = p2;
MyVNorm(&n2);
MyVAddS(1.0, &ctr, &p2, &p2);
MyVAddS(1.0, &axis, &p1, &p3);
MyVAddS(1.0, &axis, &p2, &p4);
rt_stri(tex, p1, p2, p3, n1, n2, n1);
rt_stri(tex, p3, p2, p4, n1, n2, n2);
}
}
void rt_tri_cylinder(void * tex, vector ctr, vector axis, apiflt rad) {
rt_fcylinder(tex, ctr, axis, rad);
}
void rt_tri_ring(void * tex, vector ctr, vector norm, apiflt a, apiflt b) {
vector x, y, z, tmp;
double u, v, u2, v2;
int j;
vector p1, p2, p3, p4;
vector n1, n2;
z = norm;
MyVNorm(&z);
tmp.x = z.y - 2.1111111;
tmp.y = -z.z + 3.14159267;
tmp.z = z.x - 3.915292342341;
MyVNorm(&z);
MyVNorm(&tmp);
MyVCross(&z, &tmp, &x);
MyVNorm(&x);
MyVCross(&x, &z, &y);
MyVNorm(&y);
for (j=0; j<RINGFACETS; j++) {
u = sin((6.28 * j) / (RINGFACETS - 1.0));
v = cos((6.28 * j) / (RINGFACETS - 1.0));
u2 = sin((6.28 * (j + 1.0)) / (RINGFACETS - 1.0));
v2 = cos((6.28 * (j + 1.0)) / (RINGFACETS - 1.0));
p1.x = p1.y = p1.z = 0.0;
p4 = p3 = p2 = p1;
MyVAddS(u, &x, &p1, &p1);
MyVAddS(v, &y, &p1, &p1);
n1 = p1;
MyVNorm(&n1);
MyVAddS(a, &n1, &ctr, &p1);
MyVAddS(b, &n1, &ctr, &p3);
MyVAddS(u2, &x, &p2, &p2);
MyVAddS(v2, &y, &p2, &p2);
n2 = p2;
MyVNorm(&n2);
MyVAddS(a, &n2, &ctr, &p2);
MyVAddS(b, &n2, &ctr, &p4);
rt_stri(tex, p1, p2, p3, norm, norm, norm);
rt_stri(tex, p3, p2, p4, norm, norm, norm);
}
}
void rt_tri_box(void * tex, vector min, vector max) {
/* -XY face */
rt_tri(tex, rt_vector(min.x, min.y, min.z),
rt_vector(min.x, max.y, min.z),
rt_vector(max.x, max.y, min.z));
rt_tri(tex, rt_vector(min.x, min.y, min.z),
rt_vector(max.x, max.y, min.z),
rt_vector(max.x, min.y, min.z));
/* +XY face */
rt_tri(tex, rt_vector(min.x, min.y, max.z),
rt_vector(max.x, max.y, max.z),
rt_vector(min.x, max.y, max.z));
rt_tri(tex, rt_vector(min.x, min.y, max.z),
rt_vector(max.x, min.y, max.z),
rt_vector(max.x, max.y, max.z));
/* -YZ face */
rt_tri(tex, rt_vector(min.x, min.y, min.z),
rt_vector(min.x, max.y, max.z),
rt_vector(min.x, min.y, max.z));
rt_tri(tex, rt_vector(min.x, min.y, min.z),
rt_vector(min.x, max.y, min.z),
rt_vector(min.x, max.y, max.z));
/* +YZ face */
rt_tri(tex, rt_vector(max.x, min.y, min.z),
rt_vector(max.x, min.y, max.z),
rt_vector(max.x, max.y, max.z));
rt_tri(tex, rt_vector(max.x, min.y, min.z),
rt_vector(max.x, max.y, max.z),
rt_vector(max.x, max.y, min.z));
/* -XZ face */
rt_tri(tex, rt_vector(min.x, min.y, min.z),
rt_vector(min.x, min.y, max.z),
rt_vector(max.x, min.y, max.z));
rt_tri(tex, rt_vector(min.x, min.y, min.z),
rt_vector(max.x, min.y, max.z),
rt_vector(max.x, min.y, min.z));
/* +XZ face */
rt_tri(tex, rt_vector(min.x, max.y, min.z),
rt_vector(max.x, max.y, max.z),
rt_vector(min.x, max.y, max.z));
rt_tri(tex, rt_vector(min.x, max.y, min.z),
rt_vector(max.x, max.y, min.z),
rt_vector(max.x, max.y, max.z));
}
void rt_tri_sphere(void * tex, vector ctr, apiflt rad) {
}
void rt_tri_plane(void * tex, vector ctr, vector norm) {
rt_tri_ring(tex, ctr, norm, 0.0, 10000.0);
}

View File

@@ -0,0 +1,56 @@
/*
Copyright (c) 2005-2020 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*
The original source for this example is
Copyright (c) 1994-2008 John E. Stone
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
*/
/*
* apitrigeom.h - header for functions to generate triangle tessellated
* geometry for use with OpenGL, XGL, etc.
*
*/
void rt_tri_fcylinder(void * tex, vector ctr, vector axis, apiflt rad);
void rt_tri_cylinder(void * tex, vector ctr, vector axis, apiflt rad);
void rt_tri_ring(void * tex, vector ctr, vector norm, apiflt a, apiflt b);
void rt_tri_plane(void * tex, vector ctr, vector norm);
void rt_tri_box(void * tex, vector min, vector max);

View File

@@ -0,0 +1,178 @@
/*
Copyright (c) 2005-2020 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*
The original source for this example is
Copyright (c) 1994-2008 John E. Stone
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
*/
/*
* bndbox.cpp - This file contains the functions for dealing with bounding boxes.
*/
#include "machine.h"
#include "types.h"
#include "macros.h"
#include "vector.h"
#include "intersect.h"
#include "util.h"
#define BNDBOX_PRIVATE
#include "bndbox.h"
static object_methods bndbox_methods = {
(void (*)(void *, void *))(bndbox_intersect),
(void (*)(void *, void *, void *, void *))(NULL),
bndbox_bbox,
free_bndbox
};
bndbox * newbndbox(vector min, vector max) {
bndbox * b;
b=(bndbox *) rt_getmem(sizeof(bndbox));
memset(b, 0, sizeof(bndbox));
b->min=min;
b->max=max;
b->methods = &bndbox_methods;
b->objlist=NULL;
b->tex=NULL;
b->nextobj=NULL;
return b;
}
static int bndbox_bbox(void * obj, vector * min, vector * max) {
bndbox * b = (bndbox *) obj;
*min = b->min;
*max = b->max;
return 1;
}
static void free_bndbox(void * v) {
bndbox * b = (bndbox *) v;
free_objects(b->objlist);
free(b);
}
static void bndbox_intersect(bndbox * bx, ray * ry) {
flt a, tx1, tx2, ty1, ty2, tz1, tz2;
flt tnear, tfar;
object * obj;
ray newray;
/* eliminate bounded rays whose bounds do not intersect */
/* the bounds of the box.. */
if (ry->flags & RT_RAY_BOUNDED) {
if ((ry->s.x > bx->max.x) && (ry->e.x > bx->max.x)) return;
if ((ry->s.x < bx->min.x) && (ry->e.x < bx->min.x)) return;
if ((ry->s.y > bx->max.y) && (ry->e.y > bx->max.y)) return;
if ((ry->s.y < bx->min.y) && (ry->e.y < bx->min.y)) return;
if ((ry->s.z > bx->max.z) && (ry->e.z > bx->max.z)) return;
if ((ry->s.z < bx->min.z) && (ry->e.z < bx->min.z)) return;
}
tnear= -FHUGE;
tfar= FHUGE;
if (ry->d.x == 0.0) {
if ((ry->o.x < bx->min.x) || (ry->o.x > bx->max.x)) return;
}
else {
tx1 = (bx->min.x - ry->o.x) / ry->d.x;
tx2 = (bx->max.x - ry->o.x) / ry->d.x;
if (tx1 > tx2) { a=tx1; tx1=tx2; tx2=a; }
if (tx1 > tnear) tnear=tx1;
if (tx2 < tfar) tfar=tx2;
}
if (tnear > tfar) return;
if (tfar < 0.0) return;
if (ry->d.y == 0.0) {
if ((ry->o.y < bx->min.y) || (ry->o.y > bx->max.y)) return;
}
else {
ty1 = (bx->min.y - ry->o.y) / ry->d.y;
ty2 = (bx->max.y - ry->o.y) / ry->d.y;
if (ty1 > ty2) { a=ty1; ty1=ty2; ty2=a; }
if (ty1 > tnear) tnear=ty1;
if (ty2 < tfar) tfar=ty2;
}
if (tnear > tfar) return;
if (tfar < 0.0) return;
if (ry->d.z == 0.0) {
if ((ry->o.z < bx->min.z) || (ry->o.z > bx->max.z)) return;
}
else {
tz1 = (bx->min.z - ry->o.z) / ry->d.z;
tz2 = (bx->max.z - ry->o.z) / ry->d.z;
if (tz1 > tz2) { a=tz1; tz1=tz2; tz2=a; }
if (tz1 > tnear) tnear=tz1;
if (tz2 < tfar) tfar=tz2;
}
if (tnear > tfar) return;
if (tfar < 0.0) return;
/* intersect all of the enclosed objects */
newray=*ry;
newray.flags |= RT_RAY_BOUNDED;
RAYPNT(newray.s , (*ry) , tnear);
RAYPNT(newray.e , (*ry) , (tfar + EPSILON));
obj = bx->objlist;
while (obj != NULL) {
obj->methods->intersect(obj, &newray);
obj = (object *)obj->nextobj;
}
}

View File

@@ -0,0 +1,70 @@
/*
Copyright (c) 2005-2020 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*
The original source for this example is
Copyright (c) 1994-2008 John E. Stone
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
*/
/*
* bndbox.h - This file contains the defines for bounding boxes etc.
*
* $Id: bndbox.h,v 1.2 2007-02-22 17:54:15 Exp $
*/
typedef struct {
unsigned int id; /* Unique Object serial number */
void * nextobj; /* pointer to next object in list */
object_methods * methods; /* this object's methods */
texture * tex; /* object texture */
vector min;
vector max;
object * objlist;
} bndbox;
bndbox * newbndbox(vector min, vector max);
#ifdef BNDBOX_PRIVATE
static int bndbox_bbox(void * obj, vector * min, vector * max);
static void free_bndbox(void * v);
static void bndbox_intersect(bndbox *, ray *);
#endif

View File

@@ -0,0 +1,164 @@
/*
Copyright (c) 2005-2020 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*
The original source for this example is
Copyright (c) 1994-2008 John E. Stone
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
*/
/*
* box.cpp - This file contains the functions for dealing with boxes.
*/
#include "machine.h"
#include "types.h"
#include "macros.h"
#include "box.h"
#include "vector.h"
#include "intersect.h"
#include "util.h"
int box_bbox(void * obj, vector * min, vector * max) {
box * b = (box *) obj;
*min = b->min;
*max = b->max;
return 1;
}
static object_methods box_methods = {
(void (*)(void *, void *))(box_intersect),
(void (*)(void *, void *, void *, void *))(box_normal),
box_bbox,
free
};
box * newbox(void * tex, vector min, vector max) {
box * b;
b=(box *) rt_getmem(sizeof(box));
memset(b, 0, sizeof(box));
b->methods = &box_methods;
b->tex = (texture *)tex;
b->min = min;
b->max = max;
return b;
}
void box_intersect(box * bx, ray * ry) {
flt a, tx1, tx2, ty1, ty2, tz1, tz2;
flt tnear, tfar;
tnear= -FHUGE;
tfar= FHUGE;
if (ry->d.x == 0.0) {
if ((ry->o.x < bx->min.x) || (ry->o.x > bx->max.x)) return;
}
else {
tx1 = (bx->min.x - ry->o.x) / ry->d.x;
tx2 = (bx->max.x - ry->o.x) / ry->d.x;
if (tx1 > tx2) { a=tx1; tx1=tx2; tx2=a; }
if (tx1 > tnear) tnear=tx1;
if (tx2 < tfar) tfar=tx2;
}
if (tnear > tfar) return;
if (tfar < 0.0) return;
if (ry->d.y == 0.0) {
if ((ry->o.y < bx->min.y) || (ry->o.y > bx->max.y)) return;
}
else {
ty1 = (bx->min.y - ry->o.y) / ry->d.y;
ty2 = (bx->max.y - ry->o.y) / ry->d.y;
if (ty1 > ty2) { a=ty1; ty1=ty2; ty2=a; }
if (ty1 > tnear) tnear=ty1;
if (ty2 < tfar) tfar=ty2;
}
if (tnear > tfar) return;
if (tfar < 0.0) return;
if (ry->d.z == 0.0) {
if ((ry->o.z < bx->min.z) || (ry->o.z > bx->max.z)) return;
}
else {
tz1 = (bx->min.z - ry->o.z) / ry->d.z;
tz2 = (bx->max.z - ry->o.z) / ry->d.z;
if (tz1 > tz2) { a=tz1; tz1=tz2; tz2=a; }
if (tz1 > tnear) tnear=tz1;
if (tz2 < tfar) tfar=tz2;
}
if (tnear > tfar) return;
if (tfar < 0.0) return;
add_intersection(tnear, (object *) bx, ry);
add_intersection(tfar, (object *) bx, ry);
}
void box_normal(box * bx, vector * pnt, ray * incident, vector * N) {
vector a, b, c;
flt t;
c.x=(bx->max.x + bx->min.x) / 2.0;
c.y=(bx->max.y + bx->min.y) / 2.0;
c.z=(bx->max.z + bx->min.z) / 2.0;
VSub((vector *) pnt, &c, N);
b=(*N);
a.x=fabs(N->x);
a.y=fabs(N->y);
a.z=fabs(N->z);
N->x=0.0; N->y=0.0; N->z=0.0;
t=MYMAX(a.x, MYMAX(a.y, a.z));
if (t==a.x) N->x=b.x;
if (t==a.y) N->y=b.y;
if (t==a.z) N->z=b.z;
VNorm(N);
}

View File

@@ -0,0 +1,65 @@
/*
Copyright (c) 2005-2020 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*
The original source for this example is
Copyright (c) 1994-2008 John E. Stone
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
*/
/*
* box.h - This file contains the defines for boxes etc.
*
* $Id: box.h,v 1.2 2007-02-22 17:54:15 Exp $
*/
typedef struct {
unsigned int id; /* Unique Object serial number */
void * nextobj; /* pointer to next object in list */
object_methods * methods; /* this object's methods */
texture * tex; /* object texture */
vector min;
vector max;
} box;
box * newbox(void * tex, vector min, vector max);
void box_intersect(box *, ray *);
void box_normal(box *, vector *, ray * incident, vector *);

View File

@@ -0,0 +1,105 @@
/*
Copyright (c) 2005-2020 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*
The original source for this example is
Copyright (c) 1994-2008 John E. Stone
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
*/
/*
* camera.cpp - This file contains all of the functions for doing camera work.
*/
#include "machine.h"
#include "types.h"
#include "macros.h"
#include "vector.h"
#include "camera.h"
#include "util.h"
ray camray(scenedef *scene, int x, int y) {
ray ray1, newray;
vector projcent;
vector projpixel;
flt px, py, sx, sy;
sx = (flt) scene->hres;
sy = (flt) scene->vres;
/* calculate the width and height of the image plane given the */
/* aspect ratio, image resolution, and zoom factor */
px=((sx / sy) / scene->aspectratio) / scene->camzoom;
py=1.0 / scene->camzoom;
/* assuming viewvec is a unit vector, then the center of the */
/* image plane is the camera center + vievec */
projcent.x = scene->camcent.x + scene->camviewvec.x;
projcent.y = scene->camcent.y + scene->camviewvec.y;
projcent.z = scene->camcent.z + scene->camviewvec.z;
/* starting from the center of the image plane, we move the */
/* center of the pel we're calculating, to */
/* projcent + (rightvec * x distance) */
ray1.o=projcent;
ray1.d=scene->camrightvec;
projpixel=Raypnt(&ray1, ((x*px/sx) - (px / 2.0)));
/* starting from the horizontally translated pel, we move the */
/* center of the pel we're calculating, to */
/* projcent + (upvec * y distance) */
ray1.o=projpixel;
ray1.d=scene->camupvec;
projpixel=Raypnt(&ray1, ((y*py/sy) - (py / 2.0)));
/* now that we have the exact pel center in the image plane */
/* we create the real primary ray that will be used by the */
/* rest of the system. */
/* The ray is expected to be re-normalized elsewhere, we're */
/* only really concerned about getting its direction right. */
newray.o=scene->camcent;
VSub(&projpixel, &scene->camcent, &newray.d);
newray.depth = scene->raydepth;
newray.flags = RT_RAY_REGULAR; /* camera only generates primary rays */
return newray;
}

View File

@@ -0,0 +1,52 @@
/*
Copyright (c) 2005-2020 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*
The original source for this example is
Copyright (c) 1994-2008 John E. Stone
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
*/
/*
* camera.h - This file contains the defines for camera routines etc.
*
* $Id: camera.h,v 1.2 2007-02-22 17:54:15 Exp $
*/
ray camray(scenedef *, int, int);

View File

@@ -0,0 +1,92 @@
/*
Copyright (c) 2005-2020 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*
The original source for this example is
Copyright (c) 1994-2008 John E. Stone
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
*/
/*
* coordsys.cpp - Routines to translate from one coordinate system to another.
*/
#include "machine.h"
#include "types.h"
#include "coordsys.h"
void xytopolar(flt x, flt y, flt rad, flt * u, flt * v) {
flt r1;
r1=x*x + y*y;
*v=sqrt(r1 / (rad*rad));
if (y<0.0)
*u=1.0 - acos(x/sqrt(r1))/TWOPI;
else
*u= acos(x/sqrt(r1))/TWOPI;
}
void xyztocyl(vector pnt, flt height, flt * u, flt * v) {
flt r1;
r1=pnt.x*pnt.x + pnt.y*pnt.y;
*v=pnt.z / height;
if (pnt.y<0.0)
*u=1.0 - acos(pnt.x/sqrt(r1))/TWOPI;
else
*u=acos(pnt.x/sqrt(r1))/TWOPI;
}
void xyztospr(vector pnt, flt * u, flt * v) {
flt r1, phi, theta;
r1=sqrt(pnt.x*pnt.x + pnt.y*pnt.y + pnt.z*pnt.z);
phi=acos(-pnt.y/r1);
*v=phi/3.1415926;
theta=acos((pnt.x/r1)/sin(phi))/TWOPI;
if (pnt.z > 0.0)
*u = theta;
else
*u = 1 - theta;
}

View File

@@ -0,0 +1,56 @@
/*
Copyright (c) 2005-2020 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*
The original source for this example is
Copyright (c) 1994-2008 John E. Stone
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
*/
/*
* coordsys.h - defines for coordinate system routines.
*
* $Id: coordsys.h,v 1.2 2007-02-22 17:54:15 Exp $
*/
#define TWOPI 6.2831853
void xytopolar(flt, flt, flt, flt *, flt *);
void xyztocyl(vector, flt, flt *, flt *);
void xyztospr(vector, flt *, flt *);

View File

@@ -0,0 +1,267 @@
/*
Copyright (c) 2005-2020 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*
The original source for this example is
Copyright (c) 1994-2008 John E. Stone
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
*/
/*
* cylinder.cpp - This file contains the functions for dealing with cylinders.
*/
#include "machine.h"
#include "types.h"
#include "macros.h"
#include "vector.h"
#include "intersect.h"
#include "util.h"
#define CYLINDER_PRIVATE
#include "cylinder.h"
static object_methods cylinder_methods = {
(void (*)(void *, void *))(cylinder_intersect),
(void (*)(void *, void *, void *, void *))(cylinder_normal),
cylinder_bbox,
free
};
static object_methods fcylinder_methods = {
(void (*)(void *, void *))(fcylinder_intersect),
(void (*)(void *, void *, void *, void *))(cylinder_normal),
fcylinder_bbox,
free
};
object * newcylinder(void * tex, vector ctr, vector axis, flt rad) {
cylinder * c;
c=(cylinder *) rt_getmem(sizeof(cylinder));
memset(c, 0, sizeof(cylinder));
c->methods = &cylinder_methods;
c->tex=(texture *) tex;
c->ctr=ctr;
c->axis=axis;
c->rad=rad;
return (object *) c;
}
static int cylinder_bbox(void * obj, vector * min, vector * max) {
return 0; /* infinite / unbounded object */
}
static void cylinder_intersect(cylinder * cyl, ray * ry) {
vector rc, n, D, O;
flt t, s, tin, tout, ln, d;
rc.x = ry->o.x - cyl->ctr.x;
rc.y = ry->o.y - cyl->ctr.y;
rc.z = ry->o.z - cyl->ctr.z;
VCross(&ry->d, &cyl->axis, &n);
VDOT(ln, n, n);
ln=sqrt(ln); /* finish length calculation */
if (ln == 0.0) { /* ray is parallel to the cylinder.. */
VDOT(d, rc, cyl->axis);
D.x = rc.x - d * cyl->axis.x;
D.y = rc.y - d * cyl->axis.y;
D.z = rc.z - d * cyl->axis.z;
VDOT(d, D, D);
d = sqrt(d);
tin = -FHUGE;
tout = FHUGE;
/* if (d <= cyl->rad) then ray is inside cylinder.. else outside */
}
VNorm(&n);
VDOT(d, rc, n);
d = fabs(d);
if (d <= cyl->rad) { /* ray intersects cylinder.. */
VCross(&rc, &cyl->axis, &O);
VDOT(t, O, n);
t = - t / ln;
VCross(&n, &cyl->axis, &O);
VNorm(&O);
VDOT(s, ry->d, O);
s = fabs(sqrt(cyl->rad*cyl->rad - d*d) / s);
tin = t - s;
add_intersection(tin, (object *) cyl, ry);
tout = t + s;
add_intersection(tout, (object *) cyl, ry);
}
}
static void cylinder_normal(cylinder * cyl, vector * pnt, ray * incident, vector * N) {
vector a,b,c;
flt t;
VSub((vector *) pnt, &(cyl->ctr), &a);
c=cyl->axis;
VNorm(&c);
VDOT(t, a, c);
b.x = c.x * t + cyl->ctr.x;
b.y = c.y * t + cyl->ctr.y;
b.z = c.z * t + cyl->ctr.z;
VSub(pnt, &b, N);
VNorm(N);
if (VDot(N, &(incident->d)) > 0.0) { /* make cylinder double sided */
N->x=-N->x;
N->y=-N->y;
N->z=-N->z;
}
}
object * newfcylinder(void * tex, vector ctr, vector axis, flt rad) {
cylinder * c;
c=(cylinder *) rt_getmem(sizeof(cylinder));
memset(c, 0, sizeof(cylinder));
c->methods = &fcylinder_methods;
c->tex=(texture *) tex;
c->ctr=ctr;
c->axis=axis;
c->rad=rad;
return (object *) c;
}
static int fcylinder_bbox(void * obj, vector * min, vector * max) {
cylinder * c = (cylinder *) obj;
vector mintmp, maxtmp;
mintmp.x = c->ctr.x;
mintmp.y = c->ctr.y;
mintmp.z = c->ctr.z;
maxtmp.x = c->ctr.x + c->axis.x;
maxtmp.y = c->ctr.y + c->axis.y;
maxtmp.z = c->ctr.z + c->axis.z;
min->x = MYMIN(mintmp.x, maxtmp.x);
min->y = MYMIN(mintmp.y, maxtmp.y);
min->z = MYMIN(mintmp.z, maxtmp.z);
min->x -= c->rad;
min->y -= c->rad;
min->z -= c->rad;
max->x = MYMAX(mintmp.x, maxtmp.x);
max->y = MYMAX(mintmp.y, maxtmp.y);
max->z = MYMAX(mintmp.z, maxtmp.z);
max->x += c->rad;
max->y += c->rad;
max->z += c->rad;
return 1;
}
static void fcylinder_intersect(cylinder * cyl, ray * ry) {
vector rc, n, O, hit, tmp2, ctmp4;
flt t, s, tin, tout, ln, d, tmp, tmp3;
rc.x = ry->o.x - cyl->ctr.x;
rc.y = ry->o.y - cyl->ctr.y;
rc.z = ry->o.z - cyl->ctr.z;
VCross(&ry->d, &cyl->axis, &n);
VDOT(ln, n, n);
ln=sqrt(ln); /* finish length calculation */
if (ln == 0.0) { /* ray is parallel to the cylinder.. */
return; /* in this case, we want to miss or go through the "hole" */
}
VNorm(&n);
VDOT(d, rc, n);
d = fabs(d);
if (d <= cyl->rad) { /* ray intersects cylinder.. */
VCross(&rc, &cyl->axis, &O);
VDOT(t, O, n);
t = - t / ln;
VCross(&n, &cyl->axis, &O);
VNorm(&O);
VDOT(s, ry->d, O);
s = fabs(sqrt(cyl->rad*cyl->rad - d*d) / s);
tin = t - s;
RAYPNT(hit, (*ry), tin);
ctmp4=cyl->axis;
VNorm(&ctmp4);
tmp2.x = hit.x - cyl->ctr.x;
tmp2.y = hit.y - cyl->ctr.y;
tmp2.z = hit.z - cyl->ctr.z;
VDOT(tmp, tmp2, ctmp4);
VDOT(tmp3, cyl->axis, cyl->axis);
if ((tmp > 0.0) && (tmp < sqrt(tmp3)))
add_intersection(tin, (object *) cyl, ry);
tout = t + s;
RAYPNT(hit, (*ry), tout);
tmp2.x = hit.x - cyl->ctr.x;
tmp2.y = hit.y - cyl->ctr.y;
tmp2.z = hit.z - cyl->ctr.z;
VDOT(tmp, tmp2, ctmp4);
VDOT(tmp3, cyl->axis, cyl->axis);
if ((tmp > 0.0) && (tmp < sqrt(tmp3)))
add_intersection(tout, (object *) cyl, ry);
}
}

View File

@@ -0,0 +1,74 @@
/*
Copyright (c) 2005-2020 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*
The original source for this example is
Copyright (c) 1994-2008 John E. Stone
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
*/
/*
* cylinder.h - This file contains the defines for cylinders etc.
*
* $Id: cylinder.h,v 1.2 2007-02-22 17:54:15 Exp $
*/
object * newcylinder(void *, vector, vector, flt);
object * newfcylinder(void *, vector, vector, flt);
#ifdef CYLINDER_PRIVATE
typedef struct {
unsigned int id; /* Unique Object serial number */
void * nextobj; /* pointer to next object in list */
object_methods * methods; /* this object's methods */
texture * tex; /* object texture */
vector ctr;
vector axis;
flt rad;
} cylinder;
static void cylinder_intersect(cylinder *, ray *);
static void fcylinder_intersect(cylinder *, ray *);
static int cylinder_bbox(void * obj, vector * min, vector * max);
static int fcylinder_bbox(void * obj, vector * min, vector * max);
static void cylinder_normal(cylinder *, vector *, ray *, vector *);
#endif

View File

@@ -0,0 +1,307 @@
/*
Copyright (c) 2005-2020 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*
The original source for this example is
Copyright (c) 1994-2008 John E. Stone
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
*/
/*
* extvol.cpp - Volume rendering helper routines etc.
*/
#include<stdio.h>
#include "machine.h"
#include "types.h"
#include "macros.h"
#include "vector.h"
#include "util.h"
#include "box.h"
#include "extvol.h"
#include "trace.h"
#include "sphere.h"
#include "light.h"
#include "shade.h"
#include "global.h"
int extvol_bbox(void * obj, vector * min, vector * max) {
box * b = (box *) obj;
*min = b->min;
*max = b->max;
return 1;
}
static object_methods extvol_methods = {
(void (*)(void *, void *))(box_intersect),
(void (*)(void *, void *, void *, void *))(box_normal),
extvol_bbox,
free
};
extvol * newextvol(void * voidtex, vector min, vector max,
int samples, flt (* evaluator)(flt, flt, flt)) {
extvol * xvol;
texture * tex;
tex = (texture *) voidtex;
xvol = (extvol *) rt_getmem(sizeof(extvol));
memset(xvol, 0, sizeof(extvol));
xvol->methods = &extvol_methods;
xvol->min=min;
xvol->max=max;
xvol->evaluator = evaluator;
xvol->ambient = tex->ambient;
xvol->diffuse = tex->diffuse;
xvol->opacity = tex->opacity;
xvol->samples = samples;
xvol->tex = (texture *)rt_getmem(sizeof(texture));
memset(xvol->tex, 0, sizeof(texture));
xvol->tex->ctr.x = 0.0;
xvol->tex->ctr.y = 0.0;
xvol->tex->ctr.z = 0.0;
xvol->tex->rot = xvol->tex->ctr;
xvol->tex->scale = xvol->tex->ctr;
xvol->tex->uaxs = xvol->tex->ctr;
xvol->tex->vaxs = xvol->tex->ctr;
xvol->tex->islight = 0;
xvol->tex->shadowcast = 0;
xvol->tex->col=tex->col;
xvol->tex->ambient=1.0;
xvol->tex->diffuse=0.0;
xvol->tex->specular=0.0;
xvol->tex->opacity=1.0;
xvol->tex->img=NULL;
xvol->tex->texfunc=(color(*)(void *, void *, void *))(ext_volume_texture);
xvol->tex->obj = (void *) xvol; /* XXX hack! */
return xvol;
}
color ExtVoxelColor(flt scalar) {
color col;
if (scalar > 1.0)
scalar = 1.0;
if (scalar < 0.0)
scalar = 0.0;
if (scalar < 0.5) {
col.g = 0.0;
}
else {
col.g = (scalar - 0.5) * 2.0;
}
col.r = scalar;
col.b = 1.0 - (scalar / 2.0);
return col;
}
color ext_volume_texture(vector * hit, texture * tex, ray * ry) {
color col, col2;
box * bx;
extvol * xvol;
flt a, tx1, tx2, ty1, ty2, tz1, tz2;
flt tnear, tfar;
flt t, tdist, dt, ddt, sum, tt;
vector pnt, bln;
flt scalar, transval;
int i;
point_light * li;
color diffint;
vector N, L;
flt inten;
col.r = 0.0;
col.g = 0.0;
col.b = 0.0;
bx = (box *) tex->obj;
xvol = (extvol *) tex->obj;
tnear= -FHUGE;
tfar= FHUGE;
if (ry->d.x == 0.0) {
if ((ry->o.x < bx->min.x) || (ry->o.x > bx->max.x)) return col;
}
else {
tx1 = (bx->min.x - ry->o.x) / ry->d.x;
tx2 = (bx->max.x - ry->o.x) / ry->d.x;
if (tx1 > tx2) { a=tx1; tx1=tx2; tx2=a; }
if (tx1 > tnear) tnear=tx1;
if (tx2 < tfar) tfar=tx2;
}
if (tnear > tfar) return col;
if (tfar < 0.0) return col;
if (ry->d.y == 0.0) {
if ((ry->o.y < bx->min.y) || (ry->o.y > bx->max.y)) return col;
}
else {
ty1 = (bx->min.y - ry->o.y) / ry->d.y;
ty2 = (bx->max.y - ry->o.y) / ry->d.y;
if (ty1 > ty2) { a=ty1; ty1=ty2; ty2=a; }
if (ty1 > tnear) tnear=ty1;
if (ty2 < tfar) tfar=ty2;
}
if (tnear > tfar) return col;
if (tfar < 0.0) return col;
if (ry->d.z == 0.0) {
if ((ry->o.z < bx->min.z) || (ry->o.z > bx->max.z)) return col;
}
else {
tz1 = (bx->min.z - ry->o.z) / ry->d.z;
tz2 = (bx->max.z - ry->o.z) / ry->d.z;
if (tz1 > tz2) { a=tz1; tz1=tz2; tz2=a; }
if (tz1 > tnear) tnear=tz1;
if (tz2 < tfar) tfar=tz2;
}
if (tnear > tfar) return col;
if (tfar < 0.0) return col;
if (tnear < 0.0) tnear=0.0;
tdist = xvol->samples;
tt = (xvol->opacity / tdist);
bln.x=fabs(bx->min.x - bx->max.x);
bln.y=fabs(bx->min.y - bx->max.y);
bln.z=fabs(bx->min.z - bx->max.z);
dt = 1.0 / tdist;
sum = 0.0;
/* Accumulate color as the ray passes through the voxels */
for (t=tnear; t<=tfar; t+=dt) {
if (sum < 1.0) {
pnt.x=((ry->o.x + (ry->d.x * t)) - bx->min.x) / bln.x;
pnt.y=((ry->o.y + (ry->d.y * t)) - bx->min.y) / bln.y;
pnt.z=((ry->o.z + (ry->d.z * t)) - bx->min.z) / bln.z;
/* call external evaluator assume 0.0 -> 1.0 range.. */
scalar = xvol->evaluator(pnt.x, pnt.y, pnt.z);
transval = tt * scalar;
sum += transval;
col2 = ExtVoxelColor(scalar);
col.r += transval * col2.r * xvol->ambient;
col.g += transval * col2.g * xvol->ambient;
col.b += transval * col2.b * xvol->ambient;
ddt = dt;
/* Add in diffuse shaded light sources (no shadows) */
if (xvol->diffuse > 0.0) {
/* Calculate the Volume gradient at the voxel */
N.x = (xvol->evaluator(pnt.x - ddt, pnt.y, pnt.z) -
xvol->evaluator(pnt.x + ddt, pnt.y, pnt.z)) * 8.0 * tt;
N.y = (xvol->evaluator(pnt.x, pnt.y - ddt, pnt.z) -
xvol->evaluator(pnt.x, pnt.y + ddt, pnt.z)) * 8.0 * tt;
N.z = (xvol->evaluator(pnt.x, pnt.y, pnt.z - ddt) -
xvol->evaluator(pnt.x, pnt.y, pnt.z + ddt)) * 8.0 * tt;
/* only light surfaces with enough of a normal.. */
if ((N.x*N.x + N.y*N.y + N.z*N.z) > 0.0) {
diffint.r = 0.0;
diffint.g = 0.0;
diffint.b = 0.0;
/* add the contribution of each of the lights.. */
for (i=0; i<numlights; i++) {
li=lightlist[i];
VSUB(li->ctr, (*hit), L)
VNorm(&L);
VDOT(inten, N, L)
/* only add light if its from the front of the surface */
/* could add back-lighting if we wanted to later.. */
if (inten > 0.0) {
diffint.r += inten*li->tex->col.r;
diffint.g += inten*li->tex->col.g;
diffint.b += inten*li->tex->col.b;
}
}
col.r += col2.r * diffint.r * xvol->diffuse;
col.g += col2.g * diffint.g * xvol->diffuse;
col.b += col2.b * diffint.b * xvol->diffuse;
}
}
}
else {
sum=1.0;
}
}
/* Add in transmitted ray from outside environment */
if (sum < 1.0) { /* spawn transmission rays / refraction */
color transcol;
transcol = shade_transmission(ry, hit, 1.0 - sum);
col.r += transcol.r; /* add the transmitted ray */
col.g += transcol.g; /* to the diffuse and */
col.b += transcol.b; /* transmission total.. */
}
return col;
}

View File

@@ -0,0 +1,69 @@
/*
Copyright (c) 2005-2020 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*
The original source for this example is
Copyright (c) 1994-2008 John E. Stone
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
*/
/*
* vol.h - Volume rendering definitions etc.
*
*
* $Id: extvol.h,v 1.2 2007-02-22 17:54:15 Exp $
*/
typedef struct {
unsigned int id; /* Unique Object serial number */
void * nextobj; /* pointer to next object in list */
object_methods * methods; /* this object's methods */
texture * tex; /* object texture */
vector min;
vector max;
flt ambient;
flt diffuse;
flt opacity;
int samples;
flt (* evaluator)(flt, flt, flt);
} extvol;
extvol * newextvol(void * voidtex, vector min, vector max,
int samples, flt (* evaluator)(flt, flt, flt));
color ext_volume_texture(vector *, texture *, ray *);

View File

@@ -0,0 +1,70 @@
/*
Copyright (c) 2005-2020 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*
The original source for this example is
Copyright (c) 1994-2008 John E. Stone
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
*/
/*
* global.cpp - any/all global data items etc should be in this file
*/
#include "types.h"
#include "machine.h"
#include "sphere.h"
#include "light.h"
/* stuff moved from intersect.c */
object * rootobj = NULL; /* starts out empty. */
point_light * lightlist[MAXLIGHTS];
int numlights = 0;
unsigned int numobjects = 0; /* used to assign unique object ID's */
/* used in util.c */
unsigned int rt_mem_in_use = 0;
/* used in api.c */
int parinitted = 0;
int graphicswindowopen = 0;

View File

@@ -0,0 +1,64 @@
/*
Copyright (c) 2005-2020 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*
The original source for this example is
Copyright (c) 1994-2008 John E. Stone
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
*/
/*
* global.h - any/all global data items etc should be in this file
*
* $Id: global.h,v 1.2 2007-02-22 17:54:15 Exp $
*
*/
/* stuff moved from intersect.c */
extern object * rootobj;
extern point_light * lightlist[MAXLIGHTS];
extern int numlights;
extern unsigned int numobjects;
extern unsigned int rt_mem_in_use;
extern int parinitted;
extern int graphicswindowopen;

View File

@@ -0,0 +1,675 @@
/*
Copyright (c) 2005-2020 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*
The original source for this example is
Copyright (c) 1994-2008 John E. Stone
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
*/
/*
* grid.cpp - spatial subdivision efficiency structures
*/
#include "machine.h"
#include "types.h"
#include "macros.h"
#include "vector.h"
#include "intersect.h"
#include "util.h"
#define GRID_PRIVATE
#include "grid.h"
#ifndef cbrt
#define cbrt(x) ((x) > 0.0 ? pow((double)(x), 1.0/3.0) : \
((x) < 0.0 ? -pow((double)-(x), 1.0/3.0) : 0.0))
#define qbrt(x) ((x) > 0.0 ? pow((double)(x), 1.0/4.0) : \
((x) < 0.0 ? -pow((double)-(x), 1.0/4.0) : 0.0))
#endif
static object_methods grid_methods = {
(void (*)(void *, void *))(grid_intersect),
(void (*)(void *, void *, void *, void *))(NULL),
grid_bbox,
grid_free
};
extern bool silent_mode;
object * newgrid(int xsize, int ysize, int zsize, vector min, vector max) {
grid * g;
g = (grid *) rt_getmem(sizeof(grid));
memset(g, 0, sizeof(grid));
g->methods = &grid_methods;
g->id = new_objectid();
g->xsize = xsize;
g->ysize = ysize;
g->zsize = zsize;
g->min = min;
g->max = max;
VSub(&g->max, &g->min, &g->voxsize);
g->voxsize.x /= (flt) g->xsize;
g->voxsize.y /= (flt) g->ysize;
g->voxsize.z /= (flt) g->zsize;
g->cells = (objectlist **) rt_getmem(xsize*ysize*zsize*sizeof(objectlist *));
memset(g->cells, 0, xsize*ysize*zsize * sizeof(objectlist *));
/* fprintf(stderr, "New grid, size: %8d %8d %8d\n", g->xsize, g->ysize, g->zsize); */
return (object *) g;
}
static int grid_bbox(void * obj, vector * min, vector * max) {
grid * g = (grid *) obj;
*min = g->min;
*max = g->max;
return 1;
}
static void grid_free(void * v) {
int i, numvoxels;
grid * g = (grid *) v;
/* loop through all voxels and free the object lists */
numvoxels = g->xsize * g->ysize * g->zsize;
for (i=0; i<numvoxels; i++) {
objectlist * lcur, * lnext;
lcur = g->cells[i];
while (lcur != NULL) {
lnext = lcur->next;
free(lcur);
}
}
/* free the grid cells */
free(g->cells);
/* free all objects on the grid object list */
free_objects(g->objects);
free(g);
}
static void globalbound(object ** rootlist, vector * gmin, vector * gmax) {
vector min, max;
object * cur;
if (*rootlist == NULL) /* don't bound non-existent objects */
return;
gmin->x = FHUGE; gmin->y = FHUGE; gmin->z = FHUGE;
gmax->x = -FHUGE; gmax->y = -FHUGE; gmax->z = -FHUGE;
cur=*rootlist;
while (cur != NULL) { /* Go! */
min.x = -FHUGE; min.y = -FHUGE; min.z = -FHUGE;
max.x = FHUGE; max.y = FHUGE; max.z = FHUGE;
if (cur->methods->bbox((void *) cur, &min, &max)) {
gmin->x = MYMIN( gmin->x , min.x);
gmin->y = MYMIN( gmin->y , min.y);
gmin->z = MYMIN( gmin->z , min.z);
gmax->x = MYMAX( gmax->x , max.x);
gmax->y = MYMAX( gmax->y , max.y);
gmax->z = MYMAX( gmax->z , max.z);
}
cur=(object *)cur->nextobj;
}
}
static int cellbound(grid *g, gridindex *index, vector * cmin, vector * cmax) {
vector min, max, cellmin, cellmax;
objectlist * cur;
int numinbounds = 0;
cur = g->cells[index->z*g->xsize*g->ysize + index->y*g->xsize + index->x];
if (cur == NULL) /* don't bound non-existent objects */
return 0;
cellmin.x = voxel2x(g, index->x);
cellmin.y = voxel2y(g, index->y);
cellmin.z = voxel2z(g, index->z);
cellmax.x = cellmin.x + g->voxsize.x;
cellmax.y = cellmin.y + g->voxsize.y;
cellmax.z = cellmin.z + g->voxsize.z;
cmin->x = FHUGE; cmin->y = FHUGE; cmin->z = FHUGE;
cmax->x = -FHUGE; cmax->y = -FHUGE; cmax->z = -FHUGE;
while (cur != NULL) { /* Go! */
min.x = -FHUGE; min.y = -FHUGE; min.z = -FHUGE;
max.x = FHUGE; max.y = FHUGE; max.z = FHUGE;
if (cur->obj->methods->bbox((void *) cur->obj, &min, &max)) {
if ((min.x >= cellmin.x) && (max.x <= cellmax.x) &&
(min.y >= cellmin.y) && (max.y <= cellmax.y) &&
(min.z >= cellmin.z) && (max.z <= cellmax.z)) {
cmin->x = MYMIN( cmin->x , min.x);
cmin->y = MYMIN( cmin->y , min.y);
cmin->z = MYMIN( cmin->z , min.z);
cmax->x = MYMAX( cmax->x , max.x);
cmax->y = MYMAX( cmax->y , max.y);
cmax->z = MYMAX( cmax->z , max.z);
numinbounds++;
}
}
cur=cur->next;
}
/* in case we get a 0.0 sized axis on the cell bounds, we'll */
/* use the original cell bounds */
if ((cmax->x - cmin->x) < EPSILON) {
cmax->x += EPSILON;
cmin->x -= EPSILON;
}
if ((cmax->y - cmin->y) < EPSILON) {
cmax->y += EPSILON;
cmin->y -= EPSILON;
}
if ((cmax->z - cmin->z) < EPSILON) {
cmax->z += EPSILON;
cmin->z -= EPSILON;
}
return numinbounds;
}
static int countobj(object * root) {
object * cur; /* counts the number of objects on a list */
int numobj;
numobj=0;
cur=root;
while (cur != NULL) {
cur=(object *)cur->nextobj;
numobj++;
}
return numobj;
}
static int countobjlist(objectlist * root) {
objectlist * cur;
int numobj;
numobj=0;
cur = root;
while (cur != NULL) {
cur = cur->next;
numobj++;
}
return numobj;
}
int engrid_scene(object ** list) {
grid * g;
int numobj, numcbrt;
vector gmin, gmax;
gridindex index;
if (*list == NULL)
return 0;
numobj = countobj(*list);
if ( !silent_mode )
fprintf(stderr, "Scene contains %d bounded objects.\n", numobj);
if (numobj > 16) {
numcbrt = (int) cbrt(4*numobj);
globalbound(list, &gmin, &gmax);
g = (grid *) newgrid(numcbrt, numcbrt, numcbrt, gmin, gmax);
engrid_objlist(g, list);
numobj = countobj(*list);
g->nextobj = *list;
*list = (object *) g;
/* now create subgrids.. */
for (index.z=0; index.z<g->zsize; index.z++) {
for (index.y=0; index.y<g->ysize; index.y++) {
for (index.x=0; index.x<g->xsize; index.x++) {
engrid_cell(g, &index);
}
}
}
}
return 1;
}
void engrid_objlist(grid * g, object ** list) {
object * cur, * next, **prev;
if (*list == NULL)
return;
prev = list;
cur = *list;
while (cur != NULL) {
next = (object *)cur->nextobj;
if (engrid_object(g, cur))
*prev = next;
else
prev = (object **) &cur->nextobj;
cur = next;
}
}
static int engrid_cell(grid * gold, gridindex *index) {
vector gmin, gmax, gsize;
flt len;
int numobj, numcbrt, xs, ys, zs;
grid * g;
objectlist **list;
objectlist * newobj;
list = &gold->cells[index->z*gold->xsize*gold->ysize +
index->y*gold->xsize + index->x];
if (*list == NULL)
return 0;
numobj = cellbound(gold, index, &gmin, &gmax);
VSub(&gmax, &gmin, &gsize);
len = 1.0 / (MYMAX( MYMAX(gsize.x, gsize.y), gsize.z ));
gsize.x *= len;
gsize.y *= len;
gsize.z *= len;
if (numobj > 16) {
numcbrt = (int) cbrt(2*numobj);
xs = (int) ((flt) numcbrt * gsize.x);
if (xs < 1) xs = 1;
ys = (int) ((flt) numcbrt * gsize.y);
if (ys < 1) ys = 1;
zs = (int) ((flt) numcbrt * gsize.z);
if (zs < 1) zs = 1;
g = (grid *) newgrid(xs, ys, zs, gmin, gmax);
engrid_objectlist(g, list);
newobj = (objectlist *) rt_getmem(sizeof(objectlist));
newobj->obj = (object *) g;
newobj->next = *list;
*list = newobj;
g->nextobj = gold->objects;
gold->objects = (object *) g;
}
return 1;
}
static int engrid_objectlist(grid * g, objectlist ** list) {
objectlist * cur, * next, **prev;
int numsucceeded = 0;
if (*list == NULL)
return 0;
prev = list;
cur = *list;
while (cur != NULL) {
next = cur->next;
if (engrid_object(g, cur->obj)) {
*prev = next;
free(cur);
numsucceeded++;
}
else {
prev = &cur->next;
}
cur = next;
}
return numsucceeded;
}
static int engrid_object(grid * g, object * obj) {
vector omin, omax;
gridindex low, high;
int x, y, z, zindex, yindex, voxindex;
objectlist * tmp;
if (obj->methods->bbox(obj, &omin, &omax)) {
if (!pos2grid(g, &omin, &low) || !pos2grid(g, &omax, &high)) {
return 0; /* object is not wholly contained in the grid */
}
}
else {
return 0; /* object is unbounded */
}
/* add the object to the complete list of objects in the grid */
obj->nextobj = g->objects;
g->objects = obj;
/* add this object to all voxels it inhabits */
for (z=low.z; z<=high.z; z++) {
zindex = z * g->xsize * g->ysize;
for (y=low.y; y<=high.y; y++) {
yindex = y * g->xsize;
for (x=low.x; x<=high.x; x++) {
voxindex = x + yindex + zindex;
tmp = (objectlist *) rt_getmem(sizeof(objectlist));
tmp->next = g->cells[voxindex];
tmp->obj = obj;
g->cells[voxindex] = tmp;
}
}
}
return 1;
}
static int pos2grid(grid * g, vector * pos, gridindex * index) {
index->x = (int) ((pos->x - g->min.x) / g->voxsize.x);
index->y = (int) ((pos->y - g->min.y) / g->voxsize.y);
index->z = (int) ((pos->z - g->min.z) / g->voxsize.z);
if (index->x == g->xsize)
index->x--;
if (index->y == g->ysize)
index->y--;
if (index->z == g->zsize)
index->z--;
if (index->x < 0 || index->x > g->xsize ||
index->y < 0 || index->y > g->ysize ||
index->z < 0 || index->z > g->zsize)
return 0;
if (pos->x < g->min.x || pos->x > g->max.x ||
pos->y < g->min.y || pos->y > g->max.y ||
pos->z < g->min.z || pos->z > g->max.z)
return 0;
return 1;
}
/* the real thing */
static void grid_intersect(grid * g, ray * ry) {
flt tnear, tfar, offset;
vector curpos, tmax, tdelta, pdeltaX, pdeltaY, pdeltaZ, nXp, nYp, nZp;
gridindex curvox, step, out;
int voxindex;
objectlist * cur;
if (ry->flags & RT_RAY_FINISHED)
return;
if (!grid_bounds_intersect(g, ry, &tnear, &tfar))
return;
if (ry->maxdist < tnear)
return;
curpos = Raypnt(ry, tnear);
pos2grid(g, &curpos, &curvox);
offset = tnear;
/* Setup X iterator stuff */
if (fabs(ry->d.x) < EPSILON) {
tmax.x = FHUGE;
tdelta.x = 0.0;
step.x = 0;
out.x = 0; /* never goes out of bounds on this axis */
}
else if (ry->d.x < 0.0) {
tmax.x = offset + ((voxel2x(g, curvox.x) - curpos.x) / ry->d.x);
tdelta.x = g->voxsize.x / - ry->d.x;
step.x = out.x = -1;
}
else {
tmax.x = offset + ((voxel2x(g, curvox.x + 1) - curpos.x) / ry->d.x);
tdelta.x = g->voxsize.x / ry->d.x;
step.x = 1;
out.x = g->xsize;
}
/* Setup Y iterator stuff */
if (fabs(ry->d.y) < EPSILON) {
tmax.y = FHUGE;
tdelta.y = 0.0;
step.y = 0;
out.y = 0; /* never goes out of bounds on this axis */
}
else if (ry->d.y < 0.0) {
tmax.y = offset + ((voxel2y(g, curvox.y) - curpos.y) / ry->d.y);
tdelta.y = g->voxsize.y / - ry->d.y;
step.y = out.y = -1;
}
else {
tmax.y = offset + ((voxel2y(g, curvox.y + 1) - curpos.y) / ry->d.y);
tdelta.y = g->voxsize.y / ry->d.y;
step.y = 1;
out.y = g->ysize;
}
/* Setup Z iterator stuff */
if (fabs(ry->d.z) < EPSILON) {
tmax.z = FHUGE;
tdelta.z = 0.0;
step.z = 0;
out.z = 0; /* never goes out of bounds on this axis */
}
else if (ry->d.z < 0.0) {
tmax.z = offset + ((voxel2z(g, curvox.z) - curpos.z) / ry->d.z);
tdelta.z = g->voxsize.z / - ry->d.z;
step.z = out.z = -1;
}
else {
tmax.z = offset + ((voxel2z(g, curvox.z + 1) - curpos.z) / ry->d.z);
tdelta.z = g->voxsize.z / ry->d.z;
step.z = 1;
out.z = g->zsize;
}
pdeltaX = ry->d;
VScale(&pdeltaX, tdelta.x);
pdeltaY = ry->d;
VScale(&pdeltaY, tdelta.y);
pdeltaZ = ry->d;
VScale(&pdeltaZ, tdelta.z);
nXp = Raypnt(ry, tmax.x);
nYp = Raypnt(ry, tmax.y);
nZp = Raypnt(ry, tmax.z);
voxindex = curvox.z*g->xsize*g->ysize + curvox.y*g->xsize + curvox.x;
while (1) {
if (tmax.x < tmax.y && tmax.x < tmax.z) {
cur = g->cells[voxindex];
while (cur != NULL) {
if (ry->mbox[cur->obj->id] != ry->serial) {
ry->mbox[cur->obj->id] = ry->serial;
cur->obj->methods->intersect(cur->obj, ry);
}
cur = cur->next;
}
curvox.x += step.x;
if (ry->maxdist < tmax.x || curvox.x == out.x)
break;
voxindex += step.x;
tmax.x += tdelta.x;
curpos = nXp;
nXp.x += pdeltaX.x;
nXp.y += pdeltaX.y;
nXp.z += pdeltaX.z;
}
else if (tmax.z < tmax.y) {
cur = g->cells[voxindex];
while (cur != NULL) {
if (ry->mbox[cur->obj->id] != ry->serial) {
ry->mbox[cur->obj->id] = ry->serial;
cur->obj->methods->intersect(cur->obj, ry);
}
cur = cur->next;
}
curvox.z += step.z;
if (ry->maxdist < tmax.z || curvox.z == out.z)
break;
voxindex += step.z*g->xsize*g->ysize;
tmax.z += tdelta.z;
curpos = nZp;
nZp.x += pdeltaZ.x;
nZp.y += pdeltaZ.y;
nZp.z += pdeltaZ.z;
}
else {
cur = g->cells[voxindex];
while (cur != NULL) {
if (ry->mbox[cur->obj->id] != ry->serial) {
ry->mbox[cur->obj->id] = ry->serial;
cur->obj->methods->intersect(cur->obj, ry);
}
cur = cur->next;
}
curvox.y += step.y;
if (ry->maxdist < tmax.y || curvox.y == out.y)
break;
voxindex += step.y*g->xsize;
tmax.y += tdelta.y;
curpos = nYp;
nYp.x += pdeltaY.x;
nYp.y += pdeltaY.y;
nYp.z += pdeltaY.z;
}
if (ry->flags & RT_RAY_FINISHED)
break;
}
}
static void voxel_intersect(grid * g, ray * ry, int voxindex) {
objectlist * cur;
cur = g->cells[voxindex];
while (cur != NULL) {
cur->obj->methods->intersect(cur->obj, ry);
cur = cur->next;
}
}
static int grid_bounds_intersect(grid * g, ray * ry, flt *nr, flt *fr) {
flt a, tx1, tx2, ty1, ty2, tz1, tz2;
flt tnear, tfar;
tnear= -FHUGE;
tfar= FHUGE;
if (ry->d.x == 0.0) {
if ((ry->o.x < g->min.x) || (ry->o.x > g->max.x)) return 0;
}
else {
tx1 = (g->min.x - ry->o.x) / ry->d.x;
tx2 = (g->max.x - ry->o.x) / ry->d.x;
if (tx1 > tx2) { a=tx1; tx1=tx2; tx2=a; }
if (tx1 > tnear) tnear=tx1;
if (tx2 < tfar) tfar=tx2;
}
if (tnear > tfar) return 0;
if (tfar < 0.0) return 0;
if (ry->d.y == 0.0) {
if ((ry->o.y < g->min.y) || (ry->o.y > g->max.y)) return 0;
}
else {
ty1 = (g->min.y - ry->o.y) / ry->d.y;
ty2 = (g->max.y - ry->o.y) / ry->d.y;
if (ty1 > ty2) { a=ty1; ty1=ty2; ty2=a; }
if (ty1 > tnear) tnear=ty1;
if (ty2 < tfar) tfar=ty2;
}
if (tnear > tfar) return 0;
if (tfar < 0.0) return 0;
if (ry->d.z == 0.0) {
if ((ry->o.z < g->min.z) || (ry->o.z > g->max.z)) return 0;
}
else {
tz1 = (g->min.z - ry->o.z) / ry->d.z;
tz2 = (g->max.z - ry->o.z) / ry->d.z;
if (tz1 > tz2) { a=tz1; tz1=tz2; tz2=a; }
if (tz1 > tnear) tnear=tz1;
if (tz2 < tfar) tfar=tz2;
}
if (tnear > tfar) return 0;
if (tfar < 0.0) return 0;
*nr = tnear;
*fr = tfar;
return 1;
}

View File

@@ -0,0 +1,116 @@
/*
Copyright (c) 2005-2020 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*
The original source for this example is
Copyright (c) 1994-2008 John E. Stone
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
*/
/*
* grid.h - spatial subdivision efficiency structures
*
* $Id: grid.h,v 1.2 2007-02-22 17:54:15 Exp $
*
*/
int engrid_scene(object ** list);
object * newgrid(int xsize, int ysize, int zsize, vector min, vector max);
#ifdef GRID_PRIVATE
typedef struct objectlist {
struct objectlist * next; /* next link in the list */
object * obj; /* the actual object */
} objectlist;
typedef struct {
unsigned int id; /* Unique Object serial number */
void * nextobj; /* pointer to next object in list */
object_methods * methods; /* this object's methods */
texture * tex; /* object texture */
int xsize; /* number of cells along the X direction */
int ysize; /* number of cells along the Y direction */
int zsize; /* number of cells along the Z direction */
vector min; /* the minimum coords for the box containing the grid */
vector max; /* the maximum coords for the box containing the grid */
vector voxsize; /* the size of a grid cell/voxel */
object * objects; /* all objects contained in the grid */
objectlist ** cells; /* the grid cells themselves */
} grid;
typedef struct {
int x; /* Voxel X address */
int y; /* Voxel Y address */
int z; /* Voxel Z address */
} gridindex;
/*
* Convert from voxel number along X/Y/Z to corresponding coordinate.
*/
#define voxel2x(g,X) ((X) * (g->voxsize.x) + (g->min.x))
#define voxel2y(g,Y) ((Y) * (g->voxsize.y) + (g->min.y))
#define voxel2z(g,Z) ((Z) * (g->voxsize.z) + (g->min.z))
/*
* And vice-versa.
*/
#define x2voxel(g,x) (((x) - g->min.x) / g->voxsize.x)
#define y2voxel(g,y) (((y) - g->min.y) / g->voxsize.y)
#define z2voxel(g,z) (((z) - g->min.z) / g->voxsize.z)
static int grid_bbox(void * obj, vector * min, vector * max);
static void grid_free(void * v);
static int cellbound(grid *g, gridindex *index, vector * cmin, vector * cmax);
void engrid_objlist(grid * g, object ** list);
static int engrid_object(grid * g, object * obj);
static int engrid_objectlist(grid * g, objectlist ** list);
static int engrid_cell(grid *, gridindex *);
static int pos2grid(grid * g, vector * pos, gridindex * index);
static void grid_intersect(grid *, ray *);
static void voxel_intersect(grid * g, ray * ry, int voxaddr);
static int grid_bounds_intersect(grid * g, ray * ry, flt *near, flt *far);
#endif

View File

@@ -0,0 +1,143 @@
/*
Copyright (c) 2005-2020 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*
The original source for this example is
Copyright (c) 1994-2008 John E. Stone
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
*/
/*
* imageio.cpp - This file deals with reading/writing image files
*/
/* For our puposes, we're interested only in the 3 byte per pixel 24 bit
* truecolor sort of file..
*/
#include <stdio.h>
#include "machine.h"
#include "types.h"
#include "util.h"
#include "imageio.h"
#include "ppm.h" /* PPM files */
#include "tgafile.h" /* Truevision Targa files */
#include "jpeg.h" /* JPEG files */
static
int fakeimage(char * name, int * xres, int * yres, unsigned char ** imgdata) {
int i, imgsize;
fprintf(stderr, "Error loading image %s. Faking it.\n", name);
*xres = 2;
*yres = 2;
imgsize = 3 * (*xres) * (*yres);
*imgdata = (unsigned char *)rt_getmem(imgsize);
for (i=0; i<imgsize; i++) {
(*imgdata)[i] = 255;
}
return IMAGENOERR;
}
int readimage(rawimage * img) {
int rc;
int xres, yres;
unsigned char * imgdata = NULL;
char * name = img->name;
if (strstr(name, ".ppm")) {
rc = readppm(name, &xres, &yres, &imgdata);
}
else if (strstr(name, ".tga")) {
rc = readtga(name, &xres, &yres, &imgdata);
}
else if (strstr(name, ".jpg")) {
rc = readjpeg(name, &xres, &yres, &imgdata);
}
else if (strstr(name, ".gif")) {
rc = IMAGEUNSUP;
}
else if (strstr(name, ".png")) {
rc = IMAGEUNSUP;
}
else if (strstr(name, ".tiff")) {
rc = IMAGEUNSUP;
}
else if (strstr(name, ".rgb")) {
rc = IMAGEUNSUP;
}
else if (strstr(name, ".xpm")) {
rc = IMAGEUNSUP;
}
else {
rc = readppm(name, &xres, &yres, &imgdata);
}
switch (rc) {
case IMAGEREADERR:
fprintf(stderr, "Short read encountered while loading image %s\n", name);
rc = IMAGENOERR; /* remap to non-fatal error */
break;
case IMAGEUNSUP:
fprintf(stderr, "Cannot read unsupported image format for image %s\n", name);
break;
}
/* If the image load failed, create a tiny white colored image to fake it */
/* this allows a scene to render even when a file can't be loaded */
if (rc != IMAGENOERR) {
rc = fakeimage(name, &xres, &yres, &imgdata);
}
/* If we succeeded in loading the image, return it. */
if (rc == IMAGENOERR) {
img->xres = xres;
img->yres = yres;
img->bpp = 3;
img->data = imgdata;
}
return rc;
}

View File

@@ -0,0 +1,61 @@
/*
Copyright (c) 2005-2020 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*
The original source for this example is
Copyright (c) 1994-2008 John E. Stone
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
*/
/*
* imageio.h - This file deals with reading/writing image files
*
* $Id: imageio.h,v 1.2 2007-02-22 17:54:15 Exp $
*/
/* For our puposes, we're interested only in the 3 byte per pixel 24 bit
truecolor sort of file.. */
#define IMAGENOERR 0 /* no error */
#define IMAGEBADFILE 1 /* can't find or can't open the file */
#define IMAGEUNSUP 2 /* the image file is an unsupported format */
#define IMAGEALLOCERR 3 /* not enough remaining memory to load this image */
#define IMAGEREADERR 4 /* failed read, short reads etc */
int readimage(rawimage *);

View File

@@ -0,0 +1,164 @@
/*
Copyright (c) 2005-2020 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*
The original source for this example is
Copyright (c) 1994-2008 John E. Stone
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
*/
/*
* imap.cpp - This file contains code for doing image map type things.
*/
#include "machine.h"
#include "types.h"
#include "imap.h"
#include "util.h"
#include "imageio.h"
rawimage * imagelist[MAXIMGS];
int numimages;
void ResetImages(void) {
int i;
numimages=0;
for (i=0; i<MAXIMGS; i++) {
imagelist[i]=NULL;
}
}
void LoadImage(rawimage * image) {
if (!image->loaded) {
readimage(image);
image->loaded=1;
}
}
color ImageMap(rawimage * image, flt u, flt v) {
color col, colx, colx2;
flt x,y, px, py;
int x1, x2, y1, y2;
unsigned char * ptr;
unsigned char * ptr2;
if (!image->loaded) {
LoadImage(image);
image->loaded=1;
}
if ((u <= 1.0) && (u >=0.0) && (v <= 1.0) && (v >= 0.0)) {
x=(image->xres - 1.0) * u; /* floating point X location */
y=(image->yres - 1.0) * v; /* floating point Y location */
px = x - ((int) x);
py = y - ((int) y);
x1 = (int) x;
x2 = x1 + 1;
y1 = (int) y;
y2 = y1 + 1;
ptr = image->data + ((image->xres * y1) + x1) * 3;
ptr2 = image->data + ((image->xres * y1) + x2) * 3;
colx.r = (flt) ((flt)ptr[0] + px*((flt)ptr2[0] - (flt) ptr[0])) / 255.0;
colx.g = (flt) ((flt)ptr[1] + px*((flt)ptr2[1] - (flt) ptr[1])) / 255.0;
colx.b = (flt) ((flt)ptr[2] + px*((flt)ptr2[2] - (flt) ptr[2])) / 255.0;
ptr = image->data + ((image->xres * y2) + x1) * 3;
ptr2 = image->data + ((image->xres * y2) + x2) * 3;
colx2.r = ((flt)ptr[0] + px*((flt)ptr2[0] - (flt)ptr[0])) / 255.0;
colx2.g = ((flt)ptr[1] + px*((flt)ptr2[1] - (flt)ptr[1])) / 255.0;
colx2.b = ((flt)ptr[2] + px*((flt)ptr2[2] - (flt)ptr[2])) / 255.0;
col.r = colx.r + py*(colx2.r - colx.r);
col.g = colx.g + py*(colx2.g - colx.g);
col.b = colx.b + py*(colx2.b - colx.b);
}
else {
col.r=0.0;
col.g=0.0;
col.b=0.0;
}
return col;
}
rawimage * AllocateImage(char * filename) {
rawimage * newimage = NULL;
int i, intable;
size_t len;
intable=0;
if (numimages!=0) {
for (i=0; i<numimages; i++) {
if (!strcmp(filename, imagelist[i]->name)) {
newimage=imagelist[i];
intable=1;
}
}
}
if (!intable) {
newimage=(rawimage *)rt_getmem(sizeof(rawimage));
newimage->loaded=0;
newimage->xres=0;
newimage->yres=0;
newimage->bpp=0;
newimage->data=NULL;
len=strlen(filename);
if (len > 80) rtbomb("Filename too long in image map!!");
strcpy(newimage->name, filename);
imagelist[numimages]=newimage; /* add new one to the table */
numimages++; /* increment the number of images */
}
return newimage;
}
void DeallocateImage(rawimage * image) {
image->loaded=0;
rt_freemem(image->data);
}

View File

@@ -0,0 +1,57 @@
/*
Copyright (c) 2005-2020 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*
The original source for this example is
Copyright (c) 1994-2008 John E. Stone
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
*/
/*
* imap.h - This file contains defines etc for doing image map type things.
*
* $Id: imap.h,v 1.2 2007-02-22 17:54:15 Exp $
*/
void ResetImage(void);
void LoadImage(rawimage *);
color ImageMap(rawimage *, flt, flt);
rawimage * AllocateImage(char *);
void DeallocateImage(rawimage *);
void ResetImages(void);

View File

@@ -0,0 +1,173 @@
/*
Copyright (c) 2005-2020 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*
The original source for this example is
Copyright (c) 1994-2008 John E. Stone
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
*/
/*
* intersect.cpp - This file contains code for CSG and intersection routines.
*/
#include "machine.h"
#include "types.h"
#include "intersect.h"
#include "light.h"
#include "util.h"
#include "global.h"
unsigned int new_objectid(void) {
return numobjects++; /* global used to generate unique object ID's */
}
unsigned int max_objectid(void) {
return numobjects;
}
void add_object(object * obj) {
object * objtemp;
if (obj == NULL)
return;
obj->id = new_objectid();
objtemp = rootobj;
rootobj = obj;
obj->nextobj = objtemp;
}
void free_objects(object * start) {
object * cur;
object * cur2;
cur=start;
while (cur->nextobj != NULL) {
cur2=(object *)cur->nextobj;
cur->methods->free(cur);
cur=cur2;
}
free(cur);
}
void reset_object(void) {
if (rootobj != NULL)
free_objects(rootobj);
rootobj = NULL;
numobjects = 0; /* set number of objects back to 0 */
}
void intersect_objects(ray * intray) {
object * cur;
object temp;
temp.nextobj = rootobj; /* setup the initial object pointers.. */
cur = &temp; /* ready, set */
while ((cur=(object *)cur->nextobj) != NULL)
cur->methods->intersect(cur, intray);
}
void reset_intersection(intersectstruct * intstruct) {
intstruct->num = 0;
intstruct->list[0].t = FHUGE;
intstruct->list[0].obj = NULL;
intstruct->list[1].t = FHUGE;
intstruct->list[1].obj = NULL;
}
void add_intersection(flt t, object * obj, ray * ry) {
intersectstruct * intstruct = ry->intstruct;
if (t > EPSILON) {
/* if we hit something before maxdist update maxdist */
if (t < ry->maxdist) {
ry->maxdist = t;
/* if we hit *anything* before maxdist, and we're firing a */
/* shadow ray, then we are finished ray tracing the shadow */
if (ry->flags & RT_RAY_SHADOW)
ry->flags |= RT_RAY_FINISHED;
}
intstruct->num++;
intstruct->list[intstruct->num].obj = obj;
intstruct->list[intstruct->num].t = t;
}
}
int closest_intersection(flt * t, object ** obj, intersectstruct * intstruct) {
int i;
*t=FHUGE;
for (i=1; i<=intstruct->num; i++) {
if (intstruct->list[i].t < *t) {
*t=intstruct->list[i].t;
*obj=intstruct->list[i].obj;
}
}
return intstruct->num;
}
int shadow_intersection(intersectstruct * intstruct, flt maxdist) {
int i;
if (intstruct->num > 0) {
for (i=1; i<=intstruct->num; i++) {
if ((intstruct->list[i].t < maxdist) &&
(intstruct->list[i].obj->tex->shadowcast == 1)) {
return 1;
}
}
}
return 0;
}

View File

@@ -0,0 +1,63 @@
/*
Copyright (c) 2005-2020 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*
The original source for this example is
Copyright (c) 1994-2008 John E. Stone
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
*/
/*
* intersect.h - This file contains the declarations and defines for the
* functions that manage intersection, bounding and CSG..
*
* $Id: intersect.h,v 1.2 2007-02-22 17:54:15 Exp $
*/
unsigned int new_objectid(void);
unsigned int max_objectid(void);
void add_object(object *);
void reset_object(void);
void free_objects(object *);
void intersect_objects(ray *);
void reset_intersection(intersectstruct *);
void add_intersection(flt, object *, ray *);
int closest_intersection(flt *, object **, intersectstruct *);
int next_intersection(object **, object *, intersectstruct *);
int shadow_intersection(intersectstruct * intstruct, flt maxdist);

View File

@@ -0,0 +1,125 @@
/*
Copyright (c) 2005-2020 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*
The original source for this example is
Copyright (c) 1994-2008 John E. Stone
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
*/
/*
* jpeg.cpp - This file deals with JPEG format image files (reading/writing)
*/
/*
* This code requires support from the Independent JPEG Group's libjpeg.
* For our puposes, we're interested only in the 3 byte per pixel 24 bit
* RGB output. Probably won't implement any decent checking at this point.
*/
#include <stdio.h>
#include "machine.h"
#include "types.h"
#include "util.h"
#include "imageio.h" /* error codes etc */
#include "jpeg.h" /* the protos for this file */
#if !defined(USEJPEG)
int readjpeg(char * name, int * xres, int * yres, unsigned char **imgdata) {
return IMAGEUNSUP;
}
#else
#include "jpeglib.h" /* the IJG jpeg library headers */
int readjpeg(char * name, int * xres, int * yres, unsigned char **imgdata) {
FILE * ifp;
struct jpeg_decompress_struct cinfo; /* JPEG decompression struct */
struct jpeg_error_mgr jerr; /* JPEG Error handler */
JSAMPROW row_pointer[1]; /* output row buffer */
int row_stride; /* physical row width in output buf */
/* open input file before doing any JPEG decompression setup */
if ((ifp = fopen(name, "rb")) == NULL)
return IMAGEBADFILE; /* Could not open image, return error */
/*
* Note: The Independent JPEG Group's library does not have a way
* of returning errors without the use of setjmp/longjmp.
* This is a problem in multi-threaded environment, since setjmp
* and longjmp are declared thread-unsafe by many vendors currently.
* For now, JPEG decompression errors will result in the "default"
* error handling provided by the JPEG library, which is an error
* message and a fatal call to exit(). I'll have to work around this
* or find a reasonably thread-safe way of doing setjmp/longjmp..
*/
cinfo.err = jpeg_std_error(&jerr); /* Set JPEG error handler to default */
jpeg_create_decompress(&cinfo); /* Create decompression context */
jpeg_stdio_src(&cinfo, ifp); /* Set input mechanism to stdio type */
jpeg_read_header(&cinfo, TRUE); /* Read the JPEG header for info */
jpeg_start_decompress(&cinfo); /* Prepare for actual decompression */
*xres = cinfo.output_width; /* set returned image width */
*yres = cinfo.output_height; /* set returned image height */
/* Calculate the size of a row in the image */
row_stride = cinfo.output_width * cinfo.output_components;
/* Allocate the image buffer which will be returned to the ray tracer */
*imgdata = (unsigned char *) malloc(row_stride * cinfo.output_height);
/* decompress the JPEG, one scanline at a time into the buffer */
while (cinfo.output_scanline < cinfo.output_height) {
row_pointer[0] = &((*imgdata)[(cinfo.output_scanline)*row_stride]);
jpeg_read_scanlines(&cinfo, row_pointer, 1);
}
jpeg_finish_decompress(&cinfo); /* Tell the JPEG library to cleanup */
jpeg_destroy_decompress(&cinfo); /* Destroy JPEG decompression context */
fclose(ifp); /* Close the input file */
return IMAGENOERR; /* No fatal errors */
}
#endif

View File

@@ -0,0 +1,52 @@
/*
Copyright (c) 2005-2020 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*
The original source for this example is
Copyright (c) 1994-2008 John E. Stone
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
*/
/*
* jpeg.h - This file deals with JPEG format image files (reading/writing)
*
* $Id: jpeg.h,v 1.2 2007-02-22 17:54:15 Exp $
*/
int readjpeg(char * name, int * xres, int * yres, unsigned char **imgdata);

View File

@@ -0,0 +1,124 @@
/*
Copyright (c) 2005-2020 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*
The original source for this example is
Copyright (c) 1994-2008 John E. Stone
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
*/
/*
* light.cpp - This file contains declarations and defines for light sources.
*/
#include "machine.h"
#include "types.h"
#include "macros.h"
#include "vector.h"
#include "intersect.h"
#include "util.h"
#define LIGHT_PRIVATE
#include "light.h"
static object_methods light_methods = {
(void (*)(void *, void *))(light_intersect),
(void (*)(void *, void *, void *, void *))(light_normal),
light_bbox,
free
};
point_light * newlight(void * tex, vector ctr, flt rad) {
point_light * l;
l=(point_light *) rt_getmem(sizeof(point_light));
memset(l, 0, sizeof(point_light));
l->methods = &light_methods;
l->tex=(texture *)tex;
l->ctr=ctr;
l->rad=rad;
return l;
}
static int light_bbox(void * obj, vector * min, vector * max) {
return 0; /* lights are unbounded currently */
}
static void light_intersect(point_light * l, ray * ry) {
flt b, disc, t1, t2, temp;
vector V;
/* Lights do not cast shadows.. */
if (ry->flags & RT_RAY_SHADOW)
return;
VSUB(l->ctr, ry->o, V);
VDOT(b, V, ry->d);
VDOT(temp, V, V);
disc=b*b + l->rad*l->rad - temp;
if (disc<=0.0) return;
disc=sqrt(disc);
t2=b+disc;
if (t2 <= SPEPSILON)
return;
add_intersection(t2, (object *) l, ry);
t1=b-disc;
if (t1 > SPEPSILON)
add_intersection(t1, (object *) l, ry);
}
static void light_normal(point_light * l, vector * pnt, ray * incident, vector * N) {
VSub((vector *) pnt, &(l->ctr), N);
VNorm(N);
if (VDot(N, &(incident->d)) > 0.0) {
N->x=-N->x;
N->y=-N->y;
N->z=-N->z;
}
}

View File

@@ -0,0 +1,67 @@
/*
Copyright (c) 2005-2020 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*
The original source for this example is
Copyright (c) 1994-2008 John E. Stone
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
*/
/*
* light.h - this file includes declarations and defines for light sources.
*
* $Id: light.h,v 1.2 2007-02-22 17:54:15 Exp $
*/
typedef struct {
unsigned int id; /* Unique Object serial number */
void * nextobj; /* pointer to next object in list */
object_methods * methods; /* this object's methods */
texture * tex; /* object texture */
vector ctr;
flt rad;
} point_light;
point_light * newlight(void *, vector, flt);
#ifdef LIGHT_PRIVATE
static int light_bbox(void * obj, vector * min, vector * max);
static void light_intersect(point_light *, ray *);
static void light_normal(point_light *, vector *, ray *, vector *);
#endif

View File

@@ -0,0 +1,62 @@
/*
Copyright (c) 2005-2020 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*
The original source for this example is
Copyright (c) 1994-2008 John E. Stone
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
*/
/*
* machine.h - This is the machine specific include file
*
* $Id: machine.h,v 1.2 2007-02-22 17:54:15 Exp $
*/
#include <stdio.h>
#include <cstdlib>
#include <string.h>
#include <math.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
using namespace std;
#define STDTIME

View File

@@ -0,0 +1,75 @@
/*
Copyright (c) 2005-2020 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*
The original source for this example is
Copyright (c) 1994-2008 John E. Stone
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
*/
/*
* macros.h - This file contains macro versions of functions that would be best
* used as inlined code rather than function calls.
*
* $Id: macros.h,v 1.2 2007-02-22 17:54:15 Exp $
*/
#define MYMAX(a , b) ((a) > (b) ? (a) : (b))
#define MYMIN(a , b) ((a) < (b) ? (a) : (b))
#define VDOT(return, a, b) \
return=(a.x * b.x + a.y * b.y + a.z * b.z); \
#define RAYPNT(c, a, b) \
c.x = a.o.x + ( a.d.x * b ); \
c.y = a.o.y + ( a.d.y * b ); \
c.z = a.o.z + ( a.d.z * b ); \
#define VSUB(a, b, c) \
c.x = (a.x - b.x); \
c.y = (a.y - b.y); \
c.z = (a.z - b.z); \
#define VCROSS(a, b, c) \
c->x = (a->y * b->z) - (a->z * b->y); \
c->y = (a->z * b->x) - (a->x * b->z); \
c->z = (a->x * b->y) - (a->y * b->x); \

View File

@@ -0,0 +1,381 @@
/*
Copyright (c) 2005-2020 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*
The original source for this example is
Copyright (c) 1994-2008 John E. Stone
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define VIDEO_WINMAIN_ARGS
#include "types.h"
#include "api.h" /* The ray tracing library API */
#include "parse.h" /* Support for my own file format */
#include "ui.h"
#include "util.h"
#include "tachyon_video.h"
#include "../../../common/utility/utility.h"
#if WIN8UI_EXAMPLE
#include "tbb/tbb.h"
volatile long global_startTime = 0;
volatile long global_elapsedTime = 0;
volatile bool global_isCancelled = false;
volatile int global_number_of_threads;
#endif
SceneHandle global_scene;
int global_xsize; /* size of graphic image rendered in window (from hres, vres) */
int global_ysize;
int global_xwinsize; /* size of window (may be larger than above) */
int global_ywinsize;
char *global_window_title;
bool global_usegraphics;
bool silent_mode = false; /* silent mode */
class tachyon_video *video = 0;
typedef struct {
int foundfilename; /* was a model file name found in the args? */
char filename[1024]; /* model file to render */
int useoutfilename; /* command line override of output filename */
char outfilename[1024]; /* name of output image file */
int verbosemode; /* verbose flags */
int antialiasing; /* antialiasing setting */
int displaymode; /* display mode */
int boundmode; /* bounding mode */
int boundthresh; /* bounding threshold */
int usecamfile; /* use camera file */
char camfilename[1024]; /* camera filename */
} argoptions;
void initoptions(argoptions * opt) {
memset(opt, 0, sizeof(argoptions));
opt->foundfilename = -1;
opt->useoutfilename = -1;
opt->verbosemode = -1;
opt->antialiasing = -1;
opt->displaymode = -1;
opt->boundmode = -1;
opt->boundthresh = -1;
opt->usecamfile = -1;
}
#if WIN8UI_EXAMPLE
int CreateScene() {
char* filename = "Assets/balls.dat";
global_scene = rt_newscene();
rt_initialize();
if ( readmodel(filename, global_scene) != 0 ) {
rt_finalize();
return -1;
}
// need these early for create_graphics_window() so grab these here...
scenedef *scene = (scenedef *) global_scene;
// scene->hres and scene->vres should be equal to screen resolution
scene->hres = global_xwinsize = global_xsize;
scene->vres = global_ywinsize = global_ysize;
return 0;
}
unsigned int __stdcall example_main(void *)
{
try {
if ( CreateScene() != 0 )
exit(-1);
tachyon_video tachyon;
tachyon.threaded = true;
tachyon.init_console();
// always using window even if(!global_usegraphics)
global_usegraphics =
tachyon.init_window(global_xwinsize, global_ywinsize);
if(!tachyon.running)
exit(-1);
video = &tachyon;
for(;;) {
global_elapsedTime = 0;
global_startTime=(long) time(NULL);
global_isCancelled=false;
if (video)video->running = true;
tbb::global_control c(tbb::global_control::max_allowed_parallelism, global_number_of_threads);
memset(g_pImg, 0, sizeof(unsigned int) * global_xsize * global_ysize);
tachyon.main_loop();
global_elapsedTime = (long)(time(NULL)-global_startTime);
video->running=false;
//The timer to restart drawing then it is complete.
int timer=50;
while( ( !global_isCancelled && (timer--)>0 ) ){
rt_sleep( 100 );
}
}
return NULL;
} catch ( std::exception& e ) {
std::cerr<<"error occurred. error text is :\"" <<e.what()<<"\"\n";
return 1;
}
}
#elif __TBB_IOS
#include "tbb/tbb.h"
#include "CoreFoundation/CoreFoundation.h"
extern "C" void get_screen_resolution(int *x, int *y);
int CreateScene() {
CFURLRef balls_dat_url = CFBundleCopyResourceURL(CFBundleGetMainBundle(), CFSTR("balls"), CFSTR("dat"),NULL);
char filename[1024];
CFURLGetFileSystemRepresentation(balls_dat_url, true, (UInt8*)filename, (CFIndex)sizeof(filename));
CFRelease(balls_dat_url);
global_scene = rt_newscene();
rt_initialize();
if ( readmodel(filename, global_scene) != 0 ) {
rt_finalize();
return -1;
}
// need these early for create_graphics_window() so grab these here...
scenedef *scene = (scenedef *) global_scene;
get_screen_resolution(&global_xsize, &global_ysize);
// scene->hres and scene->vres should be equal to screen resolution
scene->hres = global_xwinsize = global_xsize;
scene->vres = global_ywinsize = global_ysize;
return 0;
}
int main (int argc, char *argv[]) {
try {
if ( CreateScene() != 0 ) return -1;
tachyon_video tachyon;
tachyon.threaded = true;
tachyon.init_console();
global_usegraphics = tachyon.init_window(global_xwinsize, global_ywinsize);
if(!tachyon.running) return -1;
//TODO: add a demo loop.
video = &tachyon;
if (video)video->running = true;
memset(g_pImg, 0, sizeof(unsigned int) * global_xsize * global_ysize);
tachyon.main_loop();
video->running=false;
return NULL;
} catch ( std::exception& e ) {
std::cerr<<"error occurred. error text is :\"" <<e.what()<<"\"\n";
return 1;
}
}
#else
static char *window_title_string (int argc, const char **argv)
{
int i;
char *name;
name = (char *) malloc (8192);
char *title = getenv ("TITLE");
if( title ) strcpy( name, title );
else {
if(strrchr(argv[0], '\\')) strcpy (name, strrchr(argv[0], '\\')+1);
else if(strrchr(argv[0], '/')) strcpy (name, strrchr(argv[0], '/')+1);
else strcpy (name, *argv[0]?argv[0]:"Tachyon");
}
for (i = 1; i < argc; i++) {
strcat (name, " ");
strcat (name, argv[i]);
}
#ifdef _DEBUG
strcat (name, " (DEBUG BUILD)");
#endif
return name;
}
int useoptions(argoptions * opt, SceneHandle scene) {
if (opt->useoutfilename == 1) {
rt_outputfile(scene, opt->outfilename);
}
if (opt->verbosemode == 1) {
rt_verbose(scene, 1);
}
if (opt->antialiasing != -1) {
/* need new api code for this */
}
if (opt->displaymode != -1) {
rt_displaymode(scene, opt->displaymode);
}
if (opt->boundmode != -1) {
rt_boundmode(scene, opt->boundmode);
}
if (opt->boundthresh != -1) {
rt_boundthresh(scene, opt->boundthresh);
}
return 0;
}
argoptions ParseCommandLine(int argc, const char *argv[]) {
argoptions opt;
initoptions(&opt);
bool nobounding = false;
bool nodisp = false;
string filename;
utility::parse_cli_arguments(argc,argv,
utility::cli_argument_pack()
.positional_arg(filename,"dataset", "Model file")
.positional_arg(opt.boundthresh,"boundthresh","bounding threshold value")
.arg(nodisp,"no-display-updating","disable run-time display updating")
.arg(nobounding,"no-bounding","disable bounding technique")
.arg(silent_mode,"silent","no output except elapsed time")
);
strcpy(opt.filename, filename.c_str());
opt.displaymode = nodisp ? RT_DISPLAY_DISABLED : RT_DISPLAY_ENABLED;
opt.boundmode = nobounding ? RT_BOUNDING_DISABLED : RT_BOUNDING_ENABLED;
return opt;
}
int CreateScene(argoptions &opt) {
char *filename;
global_scene = rt_newscene();
rt_initialize();
/* process command line overrides */
useoptions(&opt, global_scene);
#ifdef DEFAULT_MODELFILE
#if _WIN32||_WIN64
#define _GLUE_FILENAME(x) "..\\dat\\" #x
#else
#define _GLUE_FILENAME(x) #x
#endif
#define GLUE_FILENAME(x) _GLUE_FILENAME(x)
if(opt.foundfilename == -1)
filename = GLUE_FILENAME(DEFAULT_MODELFILE);
else
#endif//DEFAULT_MODELFILE
filename = opt.filename;
if ( readmodel(filename, global_scene) != 0 ) {
fprintf(stderr, "Parser returned a non-zero error code reading %s\n", filename);
fprintf(stderr, "Aborting Render...\n");
rt_finalize();
return -1;
}
// need these early for create_graphics_window() so grab these here...
scenedef *scene = (scenedef *) global_scene;
global_xsize = scene->hres;
global_ysize = scene->vres;
global_xwinsize = global_xsize;
global_ywinsize = global_ysize; // add some here to leave extra blank space on bottom for status etc.
return 0;
}
int main (int argc, char *argv[]) {
try {
timer mainStartTime = gettimer();
global_window_title = window_title_string (argc, (const char**)argv);
argoptions opt = ParseCommandLine(argc, (const char**)argv);
if ( CreateScene(opt) != 0 )
return -1;
tachyon_video tachyon;
tachyon.threaded = true;
tachyon.init_console();
tachyon.title = global_window_title;
// always using window even if(!global_usegraphics)
global_usegraphics =
tachyon.init_window(global_xwinsize, global_ywinsize);
if(!tachyon.running)
return -1;
video = &tachyon;
tachyon.main_loop();
utility::report_elapsed_time(timertime(mainStartTime, gettimer()));
return 0;
} catch ( std::exception& e ) {
std::cerr<<"error occurred. error text is :\"" <<e.what()<<"\"\n";
return 1;
}
}
#endif

View File

@@ -0,0 +1,332 @@
/*
Copyright (c) 2005-2020 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*
The original source for this example is
Copyright (c) 1994-2008 John E. Stone
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
*/
/*
* objbound.cpp - This file contains the functions to find bounding boxes
* for the various primitives
*/
#include "machine.h"
#include "types.h"
#include "macros.h"
#include "bndbox.h"
#define OBJBOUND_PRIVATE
#include "objbound.h"
static void globalbound(object ** rootlist, vector * gmin, vector * gmax) {
vector min, max;
object * cur;
if (*rootlist == NULL) /* don't bound non-existent objects */
return;
gmin->x = FHUGE; gmin->y = FHUGE; gmin->z = FHUGE;
gmax->x = -FHUGE; gmax->y = -FHUGE; gmax->z = -FHUGE;
cur=*rootlist;
while (cur != NULL) { /* Go! */
min.x = -FHUGE; min.y = -FHUGE; min.z = -FHUGE;
max.x = FHUGE; max.y = FHUGE; max.z = FHUGE;
cur->methods->bbox((void *) cur, &min, &max);
gmin->x = MYMIN( gmin->x , min.x);
gmin->y = MYMIN( gmin->y , min.y);
gmin->z = MYMIN( gmin->z , min.z);
gmax->x = MYMAX( gmax->x , max.x);
gmax->y = MYMAX( gmax->y , max.y);
gmax->z = MYMAX( gmax->z , max.z);
cur=(object *)cur->nextobj;
}
}
static int objinside(object * obj, vector * min, vector * max) {
vector omin, omax;
if (obj == NULL) /* non-existent object, shouldn't get here */
return 0;
if (obj->methods->bbox((void *) obj, &omin, &omax)) {
if ((min->x <= omin.x) && (min->y <= omin.y) && (min->z <= omin.z) &&
(max->x >= omax.x) && (max->y >= omax.y) && (max->z >= omax.z)) {
return 1;
}
}
return 0;
}
static int countobj(object * root) {
object * cur; /* counts the number of objects on a list */
int numobj;
numobj=0;
cur=root;
while (cur != NULL) {
cur=(object *)cur->nextobj;
numobj++;
}
return numobj;
}
static void movenextobj(object * thisobj, object ** root) {
object * cur, * tmp;
/* move the object after thisobj to the front of the object list */
/* headed by root */
if (thisobj != NULL) {
if (thisobj->nextobj != NULL) {
cur=(object *)thisobj->nextobj; /* the object to be moved */
thisobj->nextobj = cur->nextobj; /* link around the moved obj */
tmp=*root; /* store the root node */
cur->nextobj=tmp; /* attach root to cur */
*root=cur; /* make cur, the new root */
}
}
}
static void octreespace(object ** rootlist, int maxoctnodes) {
object * cur;
vector gmin, gmax, gctr;
vector cmin1, cmin2, cmin3, cmin4, cmin5, cmin6, cmin7, cmin8;
vector cmax1, cmax2, cmax3, cmax4, cmax5, cmax6, cmax7, cmax8;
bndbox * box1, * box2, * box3, * box4;
bndbox * box5, * box6, * box7, * box8;
int skipobj;
if (*rootlist == NULL) /* don't subdivide non-existent data */
return;
skipobj=0;
globalbound(rootlist, &gmin, &gmax); /* find global min and max */
gctr.x = ((gmax.x - gmin.x) / 2.0) + gmin.x;
gctr.y = ((gmax.y - gmin.y) / 2.0) + gmin.y;
gctr.z = ((gmax.z - gmin.z) / 2.0) + gmin.z;
cmin1=gmin;
cmax1=gctr;
box1 = newbndbox(cmin1, cmax1);
cmin2=gmin;
cmin2.x=gctr.x;
cmax2=gmax;
cmax2.y=gctr.y;
cmax2.z=gctr.z;
box2 = newbndbox(cmin2, cmax2);
cmin3=gmin;
cmin3.y=gctr.y;
cmax3=gmax;
cmax3.x=gctr.x;
cmax3.z=gctr.z;
box3 = newbndbox(cmin3, cmax3);
cmin4=gmin;
cmin4.x=gctr.x;
cmin4.y=gctr.y;
cmax4=gmax;
cmax4.z=gctr.z;
box4 = newbndbox(cmin4, cmax4);
cmin5=gmin;
cmin5.z=gctr.z;
cmax5=gctr;
cmax5.z=gmax.z;
box5 = newbndbox(cmin5, cmax5);
cmin6=gctr;
cmin6.y=gmin.y;
cmax6=gmax;
cmax6.y=gctr.y;
box6 = newbndbox(cmin6, cmax6);
cmin7=gctr;
cmin7.x=gmin.x;
cmax7=gctr;
cmax7.y=gmax.y;
cmax7.z=gmax.z;
box7 = newbndbox(cmin7, cmax7);
cmin8=gctr;
cmax8=gmax;
box8 = newbndbox(cmin8, cmax8);
cur = *rootlist;
while (cur != NULL) {
if (objinside((object *)cur->nextobj, &cmin1, &cmax1)) {
movenextobj(cur, &box1->objlist);
}
else if (objinside((object *)cur->nextobj, &cmin2, &cmax2)) {
movenextobj(cur, &box2->objlist);
}
else if (objinside((object *)cur->nextobj, &cmin3, &cmax3)) {
movenextobj(cur, &box3->objlist);
}
else if (objinside((object *)cur->nextobj, &cmin4, &cmax4)) {
movenextobj(cur, &box4->objlist);
}
else if (objinside((object *)cur->nextobj, &cmin5, &cmax5)) {
movenextobj(cur, &box5->objlist);
}
else if (objinside((object *)cur->nextobj, &cmin6, &cmax6)) {
movenextobj(cur, &box6->objlist);
}
else if (objinside((object *)cur->nextobj, &cmin7, &cmax7)) {
movenextobj(cur, &box7->objlist);
}
else if (objinside((object *)cur->nextobj, &cmin8, &cmax8)) {
movenextobj(cur, &box8->objlist);
}
else {
skipobj++;
cur=(object *)cur->nextobj;
}
}
/* new scope, for redefinition of cur, and old */
{ bndbox * cur, * old;
old=box1;
cur=box2;
if (countobj(cur->objlist) > 0) {
old->nextobj=cur;
globalbound(&cur->objlist, &cur->min, &cur->max);
old=cur;
}
cur=box3;
if (countobj(cur->objlist) > 0) {
old->nextobj=cur;
globalbound(&cur->objlist, &cur->min, &cur->max);
old=cur;
}
cur=box4;
if (countobj(cur->objlist) > 0) {
old->nextobj=cur;
globalbound(&cur->objlist, &cur->min, &cur->max);
old=cur;
}
cur=box5;
if (countobj(cur->objlist) > 0) {
old->nextobj=cur;
globalbound(&cur->objlist, &cur->min, &cur->max);
old=cur;
}
cur=box6;
if (countobj(cur->objlist) > 0) {
old->nextobj=cur;
globalbound(&cur->objlist, &cur->min, &cur->max);
old=cur;
}
cur=box7;
if (countobj(cur->objlist) > 0) {
old->nextobj=cur;
globalbound(&cur->objlist, &cur->min, &cur->max);
old=cur;
}
cur=box8;
if (countobj(cur->objlist) > 0) {
old->nextobj=cur;
globalbound(&cur->objlist, &cur->min, &cur->max);
old=cur;
}
old->nextobj=*rootlist;
if (countobj(box1->objlist) > 0) {
globalbound(&box1->objlist, &box1->min, &box1->max);
*rootlist=(object *) box1;
}
else {
*rootlist=(object *) box1->nextobj;
}
} /**** end of special cur and old scope */
if (countobj(box1->objlist) > maxoctnodes) {
octreespace(&box1->objlist, maxoctnodes);
}
if (countobj(box2->objlist) > maxoctnodes) {
octreespace(&box2->objlist, maxoctnodes);
}
if (countobj(box3->objlist) > maxoctnodes) {
octreespace(&box3->objlist, maxoctnodes);
}
if (countobj(box4->objlist) > maxoctnodes) {
octreespace(&box4->objlist, maxoctnodes);
}
if (countobj(box5->objlist) > maxoctnodes) {
octreespace(&box5->objlist, maxoctnodes);
}
if (countobj(box6->objlist) > maxoctnodes) {
octreespace(&box6->objlist, maxoctnodes);
}
if (countobj(box7->objlist) > maxoctnodes) {
octreespace(&box7->objlist, maxoctnodes);
}
if (countobj(box8->objlist) > maxoctnodes) {
octreespace(&box8->objlist, maxoctnodes);
}
}
void dividespace(int maxoctnodes, object **toplist) {
bndbox * gbox;
vector gmin, gmax;
if (countobj(*toplist) > maxoctnodes) {
globalbound(toplist, &gmin, &gmax);
octreespace(toplist, maxoctnodes);
gbox = newbndbox(gmin, gmax);
gbox->objlist = NULL;
gbox->tex = NULL;
gbox->nextobj=NULL;
gbox->objlist=*toplist;
*toplist=(object *) gbox;
}
}

View File

@@ -0,0 +1,62 @@
/*
Copyright (c) 2005-2020 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*
The original source for this example is
Copyright (c) 1994-2008 John E. Stone
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
*/
/*
* objbound.h - defines for object bounding code.
*
* $Id: objbound.h,v 1.2 2007-02-22 17:54:15 Exp $
*/
void dividespace(int, object **);
#ifdef OBJBOUND_PRIVATE
static void globalbound(object **, vector *, vector *);
static int objinside(object * obj, vector * min, vector * max);
static int countobj(object *);
static void movenextobj(object *, object **);
static void octreespace(object **, int);
#endif

View File

@@ -0,0 +1,859 @@
/*
Copyright (c) 2005-2020 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*
The original source for this example is
Copyright (c) 1994-2008 John E. Stone
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
*/
/*
* parse.cpp - an UltraLame (tm) parser for simple data files...
*/
// Try preventing lots of GCC warnings about ignored results of fscanf etc.
#if !__INTEL_COMPILER
#if __GNUC__<4 || __GNUC__==4 && __GNUC_MINOR__<5
// For older versions of GCC, disable use of __wur in GLIBC
#undef _FORTIFY_SOURCE
#define _FORTIFY_SOURCE 0
#else
// Starting from 4.5, GCC has a suppression option
#pragma GCC diagnostic ignored "-Wunused-result"
#endif
#endif //__INTEL_COMPILER
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h> /* needed for toupper(), macro.. */
#include "types.h"
#include "api.h" /* rendering API */
#define PARSE_INTERNAL
#include "parse.h" /* self protos */
#undef PARSE_INTERNAL
static texentry textable[NUMTEXS]; /* texture lookup table */
static texentry defaulttex; /* The default texture when a lookup fails */
static int numtextures; /* number of TEXDEF textures */
static int numobjectsparsed; /* total number of objects parsed so far */
static color scenebackcol; /* scene background color */
static int stringcmp(const char * a, const char * b) {
size_t i, s, l;
s=strlen(a);
l=strlen(b);
if (s != l)
return 1;
for (i=0; i<s; i++) {
if (toupper(a[i]) != toupper(b[i])) {
return 1;
}
}
return 0;
}
static void reset_tex_table(void) {
apitexture apitex;
numtextures=0;
memset(&textable, 0, sizeof(textable));
apitex.col.r=1.0;
apitex.col.g=1.0;
apitex.col.b=1.0;
apitex.ambient=0.1;
apitex.diffuse=0.9;
apitex.specular=0.0;
apitex.opacity=1.0;
apitex.texturefunc=0;
defaulttex.tex=rt_texture(&apitex);
}
static errcode add_texture(void * tex, char name[TEXNAMELEN]) {
textable[numtextures].tex=tex;
strcpy(textable[numtextures].name, name);
numtextures++;
if (numtextures > NUMTEXS) {
fprintf(stderr, "Parse: %d textures allocated, texture slots full!\n", numtextures);
numtextures--; /* keep writing over last texture if we've run out.. */
return PARSEALLOCERR;
}
return PARSENOERR;
}
static void * find_texture(char name[TEXNAMELEN]) {
int i;
for (i=0; i<numtextures; i++) {
if (strcmp(name, textable[i].name) == 0)
return textable[i].tex;
}
fprintf(stderr, "Undefined texture '%s', using default. \n",name);
return(defaulttex.tex);
}
apiflt degtorad(apiflt deg) {
apiflt tmp;
tmp=deg * 3.1415926 / 180.0;
return tmp;
}
static void degvectoradvec(vector * degvec) {
vector tmp;
tmp.x=degtorad(degvec->x);
tmp.y=degtorad(degvec->y);
tmp.z=degtorad(degvec->z);
*degvec=tmp;
}
static void InitRot3d(RotMat * rot, apiflt x, apiflt y, apiflt z) {
rot->rx1=cos(y)*cos(z);
rot->rx2=sin(x)*sin(y)*cos(z) - cos(x)*sin(z);
rot->rx3=sin(x)*sin(z) + cos(x)*cos(z)*sin(y);
rot->ry1=cos(y)*sin(z);
rot->ry2=cos(x)*cos(z) + sin(x)*sin(y)*sin(z);
rot->ry3=cos(x)*sin(y)*sin(z) - sin(x)*cos(z);
rot->rz1=sin(y);
rot->rz2=sin(x)*cos(y);
rot->rz3=cos(x)*cos(y);
}
static void Rotate3d(RotMat * rot, vector * vec) {
vector tmp;
tmp.x=(vec->x*(rot->rx1) + vec->y*(rot->rx2) + vec->z*(rot->rx3));
tmp.y=(vec->x*(rot->ry1) + vec->y*(rot->ry2) + vec->z*(rot->ry3));
tmp.z=(vec->x*(rot->rz1) + vec->y*(rot->rz2) + vec->z*(rot->rz3));
*vec=tmp;
}
static void Scale3d(vector * scale, vector * vec) {
vec->x=vec->x * scale->x;
vec->y=vec->y * scale->y;
vec->z=vec->z * scale->z;
}
static void Trans3d(vector * trans, vector * vec) {
vec->x+=trans->x;
vec->y+=trans->y;
vec->z+=trans->z;
}
static errcode GetString(FILE * dfile, const char * string) {
char data[255];
fscanf(dfile,"%s",data);
if (stringcmp(data, string) != 0) {
fprintf(stderr, "parse: Expected %s, got %s \n",string, data);
fprintf(stderr, "parse: Error while parsing object: %d \n",numobjectsparsed);
return PARSEBADSYNTAX;
}
return PARSENOERR;
}
unsigned int readmodel(char * modelfile, SceneHandle scene) {
FILE * dfile;
errcode rc;
reset_tex_table();
dfile=NULL;
dfile=fopen(modelfile,"r");
if (dfile==NULL) {
return PARSEBADFILE;
}
rc = GetScenedefs(dfile, scene);
if (rc != PARSENOERR) {
fclose(dfile);
return rc;
}
scenebackcol.r = 0.0; /* default background is black */
scenebackcol.g = 0.0;
scenebackcol.b = 0.0;
numobjectsparsed=0;
while ((rc = GetObject(dfile, scene)) == PARSENOERR) {
numobjectsparsed++;
}
fclose(dfile);
if (rc == PARSEEOF)
rc = PARSENOERR;
rt_background(scene, scenebackcol);
return rc;
}
static errcode GetScenedefs(FILE * dfile, SceneHandle scene) {
vector Ccenter, Cview, Cup;
apiflt zoom, aspectratio;
int raydepth, antialiasing;
char outfilename[200];
int xres, yres, verbose;
float a,b,c;
errcode rc = PARSENOERR;
rc |= GetString(dfile, "BEGIN_SCENE");
rc |= GetString(dfile, "OUTFILE");
fscanf(dfile, "%s", outfilename);
#ifdef _WIN32
if (strcmp (outfilename, "/dev/null") == 0) {
strcpy (outfilename, "NUL:");
}
#endif
rc |= GetString(dfile, "RESOLUTION");
fscanf(dfile, "%d %d", &xres, &yres);
rc |= GetString(dfile, "VERBOSE");
fscanf(dfile, "%d", &verbose);
rt_scenesetup(scene, outfilename, xres, yres, verbose);
rc |= GetString(dfile, "CAMERA");
rc |= GetString(dfile, "ZOOM");
fscanf(dfile, "%f", &a);
zoom=a;
rc |= GetString(dfile, "ASPECTRATIO");
fscanf(dfile, "%f", &b);
aspectratio=b;
rc |= GetString(dfile, "ANTIALIASING");
fscanf(dfile, "%d", &antialiasing);
rc |= GetString(dfile, "RAYDEPTH");
fscanf(dfile, "%d", &raydepth);
rc |= GetString(dfile, "CENTER");
fscanf(dfile,"%f %f %f", &a, &b, &c);
Ccenter.x = a;
Ccenter.y = b;
Ccenter.z = c;
rc |= GetString(dfile, "VIEWDIR");
fscanf(dfile,"%f %f %f", &a, &b, &c);
Cview.x = a;
Cview.y = b;
Cview.z = c;
rc |= GetString(dfile, "UPDIR");
fscanf(dfile,"%f %f %f", &a, &b, &c);
Cup.x = a;
Cup.y = b;
Cup.z = c;
rc |= GetString(dfile, "END_CAMERA");
rt_camerasetup(scene, zoom, aspectratio, antialiasing, raydepth,
Ccenter, Cview, Cup);
return rc;
}
static errcode GetObject(FILE * dfile, SceneHandle scene) {
char objtype[80];
fscanf(dfile, "%s", objtype);
if (!stringcmp(objtype, "END_SCENE")) {
return PARSEEOF; /* end parsing */
}
if (!stringcmp(objtype, "TEXDEF")) {
return GetTexDef(dfile);
}
if (!stringcmp(objtype, "TEXALIAS")) {
return GetTexAlias(dfile);
}
if (!stringcmp(objtype, "BACKGROUND")) {
return GetBackGnd(dfile);
}
if (!stringcmp(objtype, "CYLINDER")) {
return GetCylinder(dfile);
}
if (!stringcmp(objtype, "FCYLINDER")) {
return GetFCylinder(dfile);
}
if (!stringcmp(objtype, "POLYCYLINDER")) {
return GetPolyCylinder(dfile);
}
if (!stringcmp(objtype, "SPHERE")) {
return GetSphere(dfile);
}
if (!stringcmp(objtype, "PLANE")) {
return GetPlane(dfile);
}
if (!stringcmp(objtype, "RING")) {
return GetRing(dfile);
}
if (!stringcmp(objtype, "BOX")) {
return GetBox(dfile);
}
if (!stringcmp(objtype, "SCALARVOL")) {
return GetVol(dfile);
}
if (!stringcmp(objtype, "TRI")) {
return GetTri(dfile);
}
if (!stringcmp(objtype, "STRI")) {
return GetSTri(dfile);
}
if (!stringcmp(objtype, "LIGHT")) {
return GetLight(dfile);
}
if (!stringcmp(objtype, "SCAPE")) {
return GetLandScape(dfile);
}
if (!stringcmp(objtype, "TPOLYFILE")) {
return GetTPolyFile(dfile);
}
fprintf(stderr, "Found bad token: %s expected an object type\n", objtype);
return PARSEBADSYNTAX;
}
static errcode GetVector(FILE * dfile, vector * v1) {
float a, b, c;
fscanf(dfile, "%f %f %f", &a, &b, &c);
v1->x=a;
v1->y=b;
v1->z=c;
return PARSENOERR;
}
static errcode GetColor(FILE * dfile, color * c1) {
float r, g, b;
int rc;
rc = GetString(dfile, "COLOR");
fscanf(dfile, "%f %f %f", &r, &g, &b);
c1->r=r;
c1->g=g;
c1->b=b;
return rc;
}
static errcode GetTexDef(FILE * dfile) {
char texname[TEXNAMELEN];
fscanf(dfile, "%s", texname);
add_texture(GetTexBody(dfile), texname);
return PARSENOERR;
}
static errcode GetTexAlias(FILE * dfile) {
char texname[TEXNAMELEN];
char aliasname[TEXNAMELEN];
fscanf(dfile, "%s", texname);
fscanf(dfile, "%s", aliasname);
add_texture(find_texture(aliasname), texname);
return PARSENOERR;
}
static errcode GetTexture(FILE * dfile, void ** tex) {
char tmp[255];
errcode rc = PARSENOERR;
fscanf(dfile, "%s", tmp);
if (!stringcmp("TEXTURE", tmp)) {
*tex = GetTexBody(dfile);
}
else
*tex = find_texture(tmp);
return rc;
}
void * GetTexBody(FILE * dfile) {
char tmp[255];
float a,b,c,d, phong, phongexp, phongtype;
apitexture tex;
void * voidtex;
errcode rc;
rc = GetString(dfile, "AMBIENT");
fscanf(dfile, "%f", &a);
tex.ambient=a;
rc |= GetString(dfile, "DIFFUSE");
fscanf(dfile, "%f", &b);
tex.diffuse=b;
rc |= GetString(dfile, "SPECULAR");
fscanf(dfile, "%f", &c);
tex.specular=c;
rc |= GetString(dfile, "OPACITY");
fscanf(dfile, "%f", &d);
tex.opacity=d;
fscanf(dfile, "%s", tmp);
if (!stringcmp("PHONG", tmp)) {
fscanf(dfile, "%s", tmp);
if (!stringcmp("METAL", tmp)) {
phongtype = RT_PHONG_METAL;
}
else if (!stringcmp("PLASTIC", tmp)) {
phongtype = RT_PHONG_PLASTIC;
}
else {
phongtype = RT_PHONG_PLASTIC;
}
fscanf(dfile, "%f", &phong);
GetString(dfile, "PHONG_SIZE");
fscanf(dfile, "%f", &phongexp);
fscanf(dfile, "%s", tmp);
}
else {
phong = 0.0;
phongexp = 100.0;
phongtype = RT_PHONG_PLASTIC;
}
fscanf(dfile, "%f %f %f", &a, &b, &c);
tex.col.r = a;
tex.col.g = b;
tex.col.b = c;
rc |= GetString(dfile, "TEXFUNC");
fscanf(dfile, "%d", &tex.texturefunc);
if (tex.texturefunc >= 7) { /* if its an image map, we need a filename */
fscanf(dfile, "%s", tex.imap);
}
if (tex.texturefunc != 0) {
rc |= GetString(dfile, "CENTER");
rc |= GetVector(dfile, &tex.ctr);
rc |= GetString(dfile, "ROTATE");
rc |= GetVector(dfile, &tex.rot);
rc |= GetString(dfile, "SCALE");
rc |= GetVector(dfile, &tex.scale);
}
if (tex.texturefunc == 9) {
rc |= GetString(dfile, "UAXIS");
rc |= GetVector(dfile, &tex.uaxs);
rc |= GetString(dfile, "VAXIS");
rc |= GetVector(dfile, &tex.vaxs);
}
voidtex = rt_texture(&tex);
rt_tex_phong(voidtex, phong, phongexp, (int) phongtype);
return voidtex;
}
static errcode GetLight(FILE * dfile) {
apiflt rad;
vector ctr;
apitexture tex;
float a;
errcode rc;
memset(&tex, 0, sizeof(apitexture));
rc = GetString(dfile,"CENTER");
rc |= GetVector(dfile, &ctr);
rc |= GetString(dfile,"RAD");
fscanf(dfile,"%f",&a); /* read in radius */
rad=a;
rc |= GetColor(dfile, &tex.col);
rt_light(rt_texture(&tex), ctr, rad);
return rc;
}
static errcode GetBackGnd(FILE * dfile) {
float r,g,b;
fscanf(dfile, "%f %f %f", &r, &g, &b);
scenebackcol.r=r;
scenebackcol.g=g;
scenebackcol.b=b;
return PARSENOERR;
}
static errcode GetCylinder(FILE * dfile) {
apiflt rad;
vector ctr, axis;
void * tex;
float a;
errcode rc;
rc = GetString(dfile, "CENTER");
rc |= GetVector(dfile, &ctr);
rc |= GetString(dfile, "AXIS");
rc |= GetVector(dfile, &axis);
rc |= GetString(dfile, "RAD");
fscanf(dfile, "%f", &a);
rad=a;
rc |= GetTexture(dfile, &tex);
rt_cylinder(tex, ctr, axis, rad);
return rc;
}
static errcode GetFCylinder(FILE * dfile) {
apiflt rad;
vector ctr, axis;
vector pnt1, pnt2;
void * tex;
float a;
errcode rc;
rc = GetString(dfile, "BASE");
rc |= GetVector(dfile, &pnt1);
rc |= GetString(dfile, "APEX");
rc |= GetVector(dfile, &pnt2);
ctr=pnt1;
axis.x=pnt2.x - pnt1.x;
axis.y=pnt2.y - pnt1.y;
axis.z=pnt2.z - pnt1.z;
rc |= GetString(dfile, "RAD");
fscanf(dfile, "%f", &a);
rad=a;
rc |= GetTexture(dfile, &tex);
rt_fcylinder(tex, ctr, axis, rad);
return rc;
}
static errcode GetPolyCylinder(FILE * dfile) {
apiflt rad;
vector * temp;
void * tex;
float a;
int numpts, i;
errcode rc;
rc = GetString(dfile, "POINTS");
fscanf(dfile, "%d", &numpts);
temp = (vector *) malloc(numpts * sizeof(vector));
for (i=0; i<numpts; i++) {
rc |= GetVector(dfile, &temp[i]);
}
rc |= GetString(dfile, "RAD");
fscanf(dfile, "%f", &a);
rad=a;
rc |= GetTexture(dfile, &tex);
rt_polycylinder(tex, temp, numpts, rad);
free(temp);
return rc;
}
static errcode GetSphere(FILE * dfile) {
apiflt rad;
vector ctr;
void * tex;
float a;
errcode rc;
rc = GetString(dfile,"CENTER");
rc |= GetVector(dfile, &ctr);
rc |= GetString(dfile, "RAD");
fscanf(dfile,"%f",&a);
rad=a;
rc |= GetTexture(dfile, &tex);
rt_sphere(tex, ctr, rad);
return rc;
}
static errcode GetPlane(FILE * dfile) {
vector normal;
vector ctr;
void * tex;
errcode rc;
rc = GetString(dfile, "CENTER");
rc |= GetVector(dfile, &ctr);
rc |= GetString(dfile, "NORMAL");
rc |= GetVector(dfile, &normal);
rc |= GetTexture(dfile, &tex);
rt_plane(tex, ctr, normal);
return rc;
}
static errcode GetVol(FILE * dfile) {
vector min, max;
int x,y,z;
char fname[255];
void * tex;
errcode rc;
rc = GetString(dfile, "MIN");
rc |= GetVector(dfile, &min);
rc |= GetString(dfile, "MAX");
rc |= GetVector(dfile, &max);
rc |= GetString(dfile, "DIM");
fscanf(dfile, "%d %d %d ", &x, &y, &z);
rc |= GetString(dfile, "FILE");
fscanf(dfile, "%s", fname);
rc |= GetTexture(dfile, &tex);
rt_scalarvol(tex, min, max, x, y, z, fname, NULL);
return rc;
}
static errcode GetBox(FILE * dfile) {
vector min, max;
void * tex;
errcode rc;
rc = GetString(dfile, "MIN");
rc |= GetVector(dfile, &min);
rc |= GetString(dfile, "MAX");
rc |= GetVector(dfile, &max);
rc |= GetTexture(dfile, &tex);
rt_box(tex, min, max);
return rc;
}
static errcode GetRing(FILE * dfile) {
vector normal;
vector ctr;
void * tex;
float a,b;
errcode rc;
rc = GetString(dfile, "CENTER");
rc |= GetVector(dfile, &ctr);
rc |= GetString(dfile, "NORMAL");
rc |= GetVector(dfile, &normal);
rc |= GetString(dfile, "INNER");
fscanf(dfile, " %f ", &a);
rc |= GetString(dfile, "OUTER");
fscanf(dfile, " %f ", &b);
rc |= GetTexture(dfile, &tex);
rt_ring(tex, ctr, normal, a, b);
return rc;
}
static errcode GetTri(FILE * dfile) {
vector v0,v1,v2;
void * tex;
errcode rc;
rc = GetString(dfile, "V0");
rc |= GetVector(dfile, &v0);
rc |= GetString(dfile, "V1");
rc |= GetVector(dfile, &v1);
rc |= GetString(dfile, "V2");
rc |= GetVector(dfile, &v2);
rc |= GetTexture(dfile, &tex);
rt_tri(tex, v0, v1, v2);
return rc;
}
static errcode GetSTri(FILE * dfile) {
vector v0,v1,v2,n0,n1,n2;
void * tex;
errcode rc;
rc = GetString(dfile, "V0");
rc |= GetVector(dfile, &v0);
rc |= GetString(dfile, "V1");
rc |= GetVector(dfile, &v1);
rc |= GetString(dfile, "V2");
rc |= GetVector(dfile, &v2);
rc |= GetString(dfile, "N0");
rc |= GetVector(dfile, &n0);
rc |= GetString(dfile, "N1");
rc |= GetVector(dfile, &n1);
rc |= GetString(dfile, "N2");
rc |= GetVector(dfile, &n2);
rc |= GetTexture(dfile, &tex);
rt_stri(tex, v0, v1, v2, n0, n1, n2);
return rc;
}
static errcode GetLandScape(FILE * dfile) {
void * tex;
vector ctr;
apiflt wx, wy;
int m, n;
float a,b;
errcode rc;
rc = GetString(dfile, "RES");
fscanf(dfile, "%d %d", &m, &n);
rc |= GetString(dfile, "SCALE");
fscanf(dfile, "%f %f", &a, &b);
wx=a;
wy=b;
rc |= GetString(dfile, "CENTER");
rc |= GetVector(dfile, &ctr);
rc |= GetTexture(dfile, &tex);
rt_landscape(tex, m, n, ctr, wx, wy);
return rc;
}
static errcode GetTPolyFile(FILE * dfile) {
void * tex;
vector ctr, rot, scale;
vector v1, v2, v0;
char ifname[255];
FILE *ifp;
int v, totalpolys;
RotMat RotA;
errcode rc;
totalpolys=0;
rc = GetString(dfile, "SCALE");
rc |= GetVector(dfile, &scale);
rc |= GetString(dfile, "ROT");
rc |= GetVector(dfile, &rot);
degvectoradvec(&rot);
InitRot3d(&RotA, rot.x, rot.y, rot.z);
rc |= GetString(dfile, "CENTER");
rc |= GetVector(dfile, &ctr);
rc |= GetString(dfile, "FILE");
fscanf(dfile, "%s", ifname);
rc |= GetTexture(dfile, &tex);
if ((ifp=fopen(ifname, "r")) == NULL) {
fprintf(stderr, "Can't open data file %s for input!! Aborting...\n", ifname);
return PARSEBADSUBFILE;
}
while (!feof(ifp)) {
fscanf(ifp, "%d", &v);
if (v != 3) { break; }
totalpolys++;
v=0;
rc |= GetVector(ifp, &v0);
rc |= GetVector(ifp, &v1);
rc |= GetVector(ifp, &v2);
Scale3d(&scale, &v0);
Scale3d(&scale, &v1);
Scale3d(&scale, &v2);
Rotate3d(&RotA, &v0);
Rotate3d(&RotA, &v1);
Rotate3d(&RotA, &v2);
Trans3d(&ctr, &v0);
Trans3d(&ctr, &v1);
Trans3d(&ctr, &v2);
rt_tri(tex, v1, v0, v2);
}
fclose(ifp);
return rc;
}

View File

@@ -0,0 +1,107 @@
/*
Copyright (c) 2005-2020 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*
The original source for this example is
Copyright (c) 1994-2008 John E. Stone
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
*/
/*
* parse.h - this file contains defines for model file reading.
*
* $Id: parse.h,v 1.2 2007-02-22 17:54:16 Exp $
*/
#define PARSENOERR 0
#define PARSEBADFILE 1
#define PARSEBADSUBFILE 2
#define PARSEBADSYNTAX 4
#define PARSEEOF 8
#define PARSEALLOCERR 16
unsigned int readmodel(char *, SceneHandle);
#ifdef PARSE_INTERNAL
#define NUMTEXS 32768
#define TEXNAMELEN 24
typedef struct {
double rx1; double rx2; double rx3;
double ry1; double ry2; double ry3;
double rz1; double rz2; double rz3;
} RotMat;
typedef struct {
char name[TEXNAMELEN];
void * tex;
} texentry;
#ifdef _ERRCODE_DEFINED
#define errcode errcode_t
#endif//_ERRCODE_DEFINED
typedef unsigned int errcode;
static errcode add_texture(void * tex, char name[TEXNAMELEN]);
static errcode GetString(FILE *, const char *);
static errcode GetScenedefs(FILE *, SceneHandle);
static errcode GetColor(FILE *, color *);
static errcode GetVector(FILE *, vector *);
static errcode GetTexDef(FILE *);
static errcode GetTexAlias(FILE *);
static errcode GetTexture(FILE *, void **);
void * GetTexBody(FILE *);
static errcode GetBackGnd(FILE *);
static errcode GetCylinder(FILE *);
static errcode GetFCylinder(FILE *);
static errcode GetPolyCylinder(FILE *);
static errcode GetSphere(FILE *);
static errcode GetPlane(FILE *);
static errcode GetRing(FILE *);
static errcode GetBox(FILE *);
static errcode GetVol(FILE *);
static errcode GetTri(FILE *);
static errcode GetSTri(FILE *);
static errcode GetLight(FILE *);
static errcode GetLandScape(FILE *);
static errcode GetTPolyFile(FILE *);
static errcode GetMGFFile(FILE *, SceneHandle);
static errcode GetObject(FILE *, SceneHandle);
#endif

View File

@@ -0,0 +1,101 @@
/*
Copyright (c) 2005-2020 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*
The original source for this example is
Copyright (c) 1994-2008 John E. Stone
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
*/
/*
* plane.cpp - This file contains the functions for dealing with planes.
*/
#include "machine.h"
#include "types.h"
#include "macros.h"
#include "vector.h"
#include "intersect.h"
#include "util.h"
#define PLANE_PRIVATE
#include "plane.h"
static object_methods plane_methods = {
(void (*)(void *, void *))(plane_intersect),
(void (*)(void *, void *, void *, void *))(plane_normal),
plane_bbox,
free
};
object * newplane(void * tex, vector ctr, vector norm) {
plane * p;
p=(plane *) rt_getmem(sizeof(plane));
memset(p, 0, sizeof(plane));
p->methods = &plane_methods;
p->tex = (texture *)tex;
p->norm = norm;
VNorm(&p->norm);
p->d = -VDot(&ctr, &p->norm);
return (object *) p;
}
static int plane_bbox(void * obj, vector * min, vector * max) {
return 0;
}
static void plane_intersect(plane * pln, ray * ry) {
flt t,td;
t=-(pln->d + VDot(&pln->norm, &ry->o));
td=VDot(&pln->norm, &ry->d);
if (td != 0.0) {
t /= td;
if (t > 0.0)
add_intersection(t,(object *) pln, ry);
}
}
static void plane_normal(plane * pln, vector * pnt, ray * incident, vector * N) {
*N=pln->norm;
}

View File

@@ -0,0 +1,68 @@
/*
Copyright (c) 2005-2020 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*
The original source for this example is
Copyright (c) 1994-2008 John E. Stone
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
*/
/*
* plane.h - This file contains the defines for planes etc.
*
* $Id: plane.h,v 1.2 2007-02-22 17:54:16 Exp $
*/
object * newplane(void * tex, vector ctr, vector norm);
#ifdef PLANE_PRIVATE
typedef struct {
unsigned int id; /* Unique Object serial number */
void * nextobj; /* pointer to next object in list */
object_methods * methods; /* this object's methods */
texture * tex; /* object texture */
flt d;
vector norm;
} plane;
static void plane_intersect(plane *, ray *);
static int plane_bbox(void * obj, vector * min, vector * max);
static void plane_normal(plane *, vector *, ray * incident, vector *);
#endif

View File

@@ -0,0 +1,125 @@
/*
Copyright (c) 2005-2020 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*
The original source for this example is
Copyright (c) 1994-2008 John E. Stone
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
*/
/*
* ppm.cpp - This file deals with PPM format image files (reading/writing)
*/
/* For our puposes, we're interested only in the 3 byte per pixel 24 bit
truecolor sort of file.. Probably won't implement any decent checking
at this point, probably choke on things like the # comments.. */
// Try preventing lots of GCC warnings about ignored results of fscanf etc.
#if !__INTEL_COMPILER
#if __GNUC__<4 || __GNUC__==4 && __GNUC_MINOR__<5
// For older versions of GCC, disable use of __wur in GLIBC
#undef _FORTIFY_SOURCE
#define _FORTIFY_SOURCE 0
#else
// Starting from 4.5, GCC has a suppression option
#pragma GCC diagnostic ignored "-Wunused-result"
#endif
#endif //__INTEL_COMPILER
#include <stdio.h>
#include "machine.h"
#include "types.h"
#include "util.h"
#include "imageio.h" /* error codes etc */
#include "ppm.h"
static int getint(FILE * dfile) {
char ch[200];
int i;
int num;
num=0;
while (num==0) {
fscanf(dfile, "%s", ch);
while (ch[0]=='#') {
fgets(ch, 200, dfile);
}
num=sscanf(ch, "%d", &i);
}
return i;
}
int readppm(char * name, int * xres, int * yres, unsigned char **imgdata) {
char data[200];
FILE * ifp;
int i;
size_t bytesread;
int datasize;
ifp=fopen(name, "r");
if (ifp==NULL) {
return IMAGEBADFILE; /* couldn't open the file */
}
fscanf(ifp, "%s", data);
if (strcmp(data, "P6")) {
fclose(ifp);
return IMAGEUNSUP; /* not a format we support */
}
*xres=getint(ifp);
*yres=getint(ifp);
i=getint(ifp); /* eat the maxval number */
fread(&i, 1, 1, ifp); /* eat the newline */
datasize = 3 * (*xres) * (*yres);
*imgdata=(unsigned char *)rt_getmem(datasize);
bytesread=fread(*imgdata, 1, datasize, ifp);
fclose(ifp);
if (bytesread != datasize)
return IMAGEREADERR;
return IMAGENOERR;
}

View File

@@ -0,0 +1,56 @@
/*
Copyright (c) 2005-2020 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*
The original source for this example is
Copyright (c) 1994-2008 John E. Stone
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
*/
/*
* ppm.h - This file deals with PPM format image files (reading/writing)
*
* $Id: ppm.h,v 1.2 2007-02-22 17:54:16 Exp $
*/
/* For our puposes, we're interested only in the 3 byte per pixel 24 bit
truecolor sort of file.. Probably won't implement any decent checking
at this point, probably choke on things like the # comments.. */
int readppm(char * name, int * xres, int * yres, unsigned char **imgdata);

View File

@@ -0,0 +1,152 @@
/*
Copyright (c) 2005-2020 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*
The original source for this example is
Copyright (c) 1994-2008 John E. Stone
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
*/
#ifdef EMULATE_PTHREADS
#include <assert.h>
#include "pthread_w.h"
/*
Basics
*/
int
pthread_create (pthread_t *thread, pthread_attr_t *attr, void *(*start_routine) (void *), void *arg)
{
pthread_t th;
if (thread == NULL) return EINVAL;
*thread = NULL;
if (start_routine == NULL) return EINVAL;
th = (pthread_t) malloc (sizeof (pthread_s));
memset (th, 0, sizeof (pthread_s));
th->winthread_handle = CreateThread (
NULL,
0,
(LPTHREAD_START_ROUTINE) start_routine,
arg,
0,
&th->winthread_id);
if (th->winthread_handle == NULL) return EAGAIN; /* GetLastError() */
*thread = th;
return 0;
}
int
pthread_join (pthread_t th, void **thread_return)
{
BOOL b_ret;
DWORD dw_ret;
if (thread_return) *thread_return = NULL;
if ((th == NULL) || (th->winthread_handle == NULL)) return EINVAL;
dw_ret = WaitForSingleObject (th->winthread_handle, INFINITE);
if (dw_ret != WAIT_OBJECT_0) return ERROR_PTHREAD; /* dw_ret == WAIT_FAILED; GetLastError() */
if (thread_return) {
BOOL e_ret;
DWORD exit_val;
e_ret = GetExitCodeThread (th->winthread_handle, &exit_val);
if (!e_ret) return ERROR_PTHREAD; /* GetLastError() */
*thread_return = (void *)(size_t) exit_val;
}
b_ret = CloseHandle (th->winthread_handle);
if (!b_ret) return ERROR_PTHREAD; /* GetLastError() */
memset (th, 0, sizeof (pthread_s));
free (th);
th = NULL;
return 0;
}
void
pthread_exit (void *retval)
{
/* specific to PTHREAD_TO_WINTHREAD */
ExitThread ((DWORD) ((size_t) retval)); /* thread becomes signalled so its death can be waited upon */
/*NOTREACHED*/
assert (0); return; /* void fnc; can't return an error code */
}
/*
Mutex
*/
int
pthread_mutex_init (pthread_mutex_t *mutex, pthread_mutexattr_t *mutex_attr)
{
InitializeCriticalSection (&mutex->critsec);
return 0;
}
int
pthread_mutex_destroy (pthread_mutex_t *mutex)
{
return 0;
}
int
pthread_mutex_lock (pthread_mutex_t *mutex)
{
EnterCriticalSection (&mutex->critsec);
return 0;
}
int
pthread_mutex_unlock (pthread_mutex_t *mutex)
{
LeaveCriticalSection (&mutex->critsec);
return 0;
}
#endif /* EMULATE_PTHREADS */

View File

@@ -0,0 +1,105 @@
/*
Copyright (c) 2005-2020 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*
The original source for this example is
Copyright (c) 1994-2008 John E. Stone
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
*/
#ifdef EMULATE_PTHREADS
#ifndef _PTHREAD_H_DEFINED
#define _PTHREAD_H_DEFINED
#include <windows.h>
#include <errno.h>
#ifndef ENOTSUP
#define ENOTSUP EPERM
#endif
/* just need <stddef.h> on Windows to get size_t defined */
#include <stddef.h>
#define ERROR_PTHREAD 1000
#define ERROR_MODE 1001
#define ERROR_UNIMPL 1002
/*
Basics
*/
struct pthread_s {
HANDLE winthread_handle;
DWORD winthread_id;
};
typedef struct pthread_s *pthread_t; /* one of the few types that's pointer, not struct */
typedef struct {
int i; /* not yet defined... */
} pthread_attr_t;
/*
Mutex
*/
typedef struct {
int i; /* not yet defined... */
} pthread_mutexattr_t;
typedef struct {
CRITICAL_SECTION critsec;
} pthread_mutex_t;
/*
Function prototypes
*/
extern int pthread_create (pthread_t *thread, pthread_attr_t *attr, void *(*start_routine) (void *), void *arg);
extern int pthread_join (pthread_t th, void **thread_return);
extern void pthread_exit (void *retval);
extern int pthread_mutex_init (pthread_mutex_t *mutex, pthread_mutexattr_t *mutex_attr);
extern int pthread_mutex_destroy (pthread_mutex_t *mutex);
extern int pthread_mutex_lock (pthread_mutex_t *mutex);
extern int pthread_mutex_unlock (pthread_mutex_t *mutex);
#endif /* _PTHREAD_H_DEFINED */
#endif /* EMULATE_PTHREADS */

View File

@@ -0,0 +1,166 @@
/*
Copyright (c) 2005-2020 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*
The original source for this example is
Copyright (c) 1994-2008 John E. Stone
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
*/
/*
* quadric.cpp - This file contains the functions for dealing with quadrics.
*/
#include "machine.h"
#include "types.h"
#include "macros.h"
#include "quadric.h"
#include "vector.h"
#include "intersect.h"
#include "util.h"
int quadric_bbox(void * obj, vector * min, vector * max) {
return 0;
}
static object_methods quadric_methods = {
(void (*)(void *, void *))(quadric_intersect),
(void (*)(void *, void *, void *, void *))(quadric_normal),
quadric_bbox,
free
};
quadric * newquadric() {
quadric * q;
q=(quadric *) rt_getmem(sizeof(quadric));
memset(q, 0, sizeof(quadric));
q->ctr.x=0.0;
q->ctr.y=0.0;
q->ctr.z=0.0;
q->methods = &quadric_methods;
return q;
}
void quadric_intersect(quadric * q, ray * ry) {
flt Aq, Bq, Cq;
flt t1, t2;
flt disc;
vector rd;
vector ro;
rd=ry->d;
VNorm(&rd);
ro.x = ry->o.x - q->ctr.x;
ro.y = ry->o.y - q->ctr.y;
ro.z = ry->o.z - q->ctr.z;
Aq = (q->mat.a*(rd.x * rd.x)) +
(2.0 * q->mat.b * rd.x * rd.y) +
(2.0 * q->mat.c * rd.x * rd.z) +
(q->mat.e * (rd.y * rd.y)) +
(2.0 * q->mat.f * rd.y * rd.z) +
(q->mat.h * (rd.z * rd.z));
Bq = 2.0 * (
(q->mat.a * ro.x * rd.x) +
(q->mat.b * ((ro.x * rd.y) + (rd.x * ro.y))) +
(q->mat.c * ((ro.x * rd.z) + (rd.x * ro.z))) +
(q->mat.d * rd.x) +
(q->mat.e * ro.y * rd.y) +
(q->mat.f * ((ro.y * rd.z) + (rd.y * ro.z))) +
(q->mat.g * rd.y) +
(q->mat.h * ro.z * rd.z) +
(q->mat.i * rd.z)
);
Cq = (q->mat.a * (ro.x * ro.x)) +
(2.0 * q->mat.b * ro.x * ro.y) +
(2.0 * q->mat.c * ro.x * ro.z) +
(2.0 * q->mat.d * ro.x) +
(q->mat.e * (ro.y * ro.y)) +
(2.0 * q->mat.f * ro.y * ro.z) +
(2.0 * q->mat.g * ro.y) +
(q->mat.h * (ro.z * ro.z)) +
(2.0 * q->mat.i * ro.z) +
q->mat.j;
if (Aq == 0.0) {
t1 = - Cq / Bq;
add_intersection(t1, (object *) q, ry);
}
else {
disc=(Bq*Bq - 4.0 * Aq * Cq);
if (disc > 0.0) {
disc=sqrt(disc);
t1 = (-Bq + disc) / (2.0 * Aq);
t2 = (-Bq - disc) / (2.0 * Aq);
add_intersection(t1, (object *) q, ry);
add_intersection(t2, (object *) q, ry);
}
}
}
void quadric_normal(quadric * q, vector * pnt, ray * incident, vector * N) {
N->x = (q->mat.a*(pnt->x - q->ctr.x) +
q->mat.b*(pnt->y - q->ctr.y) +
q->mat.c*(pnt->z - q->ctr.z) + q->mat.d);
N->y = (q->mat.b*(pnt->x - q->ctr.x) +
q->mat.e*(pnt->y - q->ctr.y) +
q->mat.f*(pnt->z - q->ctr.z) + q->mat.g);
N->z = (q->mat.c*(pnt->x - q->ctr.x) +
q->mat.f*(pnt->y - q->ctr.y) +
q->mat.h*(pnt->z - q->ctr.z) + q->mat.i);
VNorm(N);
if (VDot(N, &(incident->d)) > 0.0) {
N->x=-N->x;
N->y=-N->y;
N->z=-N->z;
}
}

View File

@@ -0,0 +1,71 @@
/*
Copyright (c) 2005-2020 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*
The original source for this example is
Copyright (c) 1994-2008 John E. Stone
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
*/
/*
* quadric.h - This file contains the defines for quadrics.
*
* $Id: quadric.h,v 1.2 2007-02-22 17:54:16 Exp $
*/
typedef struct {
flt a; flt b; flt c;
flt d; flt e; flt f;
flt g; flt h; flt i; flt j;
} quadmatrix;
typedef struct {
unsigned int id; /* Unique Object serial number */
void * nextobj; /* pointer to next object in list */
object_methods * methods; /* this object's methods */
texture * tex; /* object texture */
vector ctr;
quadmatrix mat;
} quadric;
quadric * newquadric(void);
void quadric_intersect(quadric *, ray *);
void quadric_normal(quadric *, vector *, ray *, vector *);

View File

@@ -0,0 +1,87 @@
/*
Copyright (c) 2005-2020 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*
The original source for this example is
Copyright (c) 1994-2008 John E. Stone
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
*/
/*
* render.cpp - This file contains the main program and driver for the raytracer.
*/
#include "machine.h"
#include "types.h"
#include "macros.h"
#include "tgafile.h"
#include "trace.h"
#include "render.h"
#include "util.h"
#include "light.h"
#include "global.h"
#include "ui.h"
#include "tachyon_video.h"
#include "objbound.h"
#include "grid.h"
/* how many pieces to divide each scanline into */
#define NUMHORZDIV 1
void renderscene(scenedef scene) {
//char msgtxt[2048];
//void * outfile;
/* Grid based accerlation scheme */
if (scene.boundmode == RT_BOUNDING_ENABLED)
engrid_scene(&rootobj); /* grid */
/* Not used now
if (scene.verbosemode) {
sprintf(msgtxt, "Opening %s for output.", scene.outfilename);
rt_ui_message(MSG_0, msgtxt);
}
createtgafile(scene.outfilename,
(unsigned short) scene.hres,
(unsigned short) scene.vres);
outfile = opentgafile(scene.outfilename);
*/
trace_region (scene, 0/*outfile*/, 0, 0, scene.hres, scene.vres);
//fclose((FILE *)outfile);
} /* end of renderscene() */

View File

@@ -0,0 +1,53 @@
/*
Copyright (c) 2005-2020 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*
The original source for this example is
Copyright (c) 1994-2008 John E. Stone
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
*/
/*
* render.h - This file contains the defines for the top level functions
*
* $Id: render.h,v 1.2 2007-02-22 17:54:16 Exp $
*/
void renderscene(scenedef);

View File

@@ -0,0 +1,127 @@
/*
Copyright (c) 2005-2020 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*
The original source for this example is
Copyright (c) 1994-2008 John E. Stone
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
*/
/*
* ring.cpp - This file contains the functions for dealing with rings.
*/
#include "machine.h"
#include "types.h"
#include "macros.h"
#include "vector.h"
#include "intersect.h"
#include "util.h"
#define RING_PRIVATE
#include "ring.h"
static object_methods ring_methods = {
(void (*)(void *, void *))(ring_intersect),
(void (*)(void *, void *, void *, void *))(ring_normal),
ring_bbox,
free
};
object * newring(void * tex, vector ctr, vector norm, flt inrad, flt outrad) {
ring * r;
r=(ring *) rt_getmem(sizeof(ring));
memset(r, 0, sizeof(ring));
r->methods = &ring_methods;
r->tex = (texture *)tex;
r->ctr = ctr;
r->norm = norm;
r->inrad = inrad;
r->outrad= outrad;
return (object *) r;
}
static int ring_bbox(void * obj, vector * min, vector * max) {
ring * r = (ring *) obj;
min->x = r->ctr.x - r->outrad;
min->y = r->ctr.y - r->outrad;
min->z = r->ctr.z - r->outrad;
max->x = r->ctr.x + r->outrad;
max->y = r->ctr.y + r->outrad;
max->z = r->ctr.z + r->outrad;
return 1;
}
static void ring_intersect(ring * rng, ray * ry) {
flt d;
flt t,td;
vector hit, pnt;
d = -VDot(&(rng->ctr), &(rng->norm));
t=-(d+VDot(&(rng->norm), &(ry->o)));
td=VDot(&(rng->norm),&(ry->d));
if (td != 0.0) {
t= t / td;
if (t>=0.0) {
hit=Raypnt(ry, t);
VSUB(hit, rng->ctr, pnt);
VDOT(td, pnt, pnt);
td=sqrt(td);
if ((td > rng->inrad) && (td < rng->outrad))
add_intersection(t,(object *) rng, ry);
}
}
}
static void ring_normal(ring * rng, vector * pnt, ray * incident, vector * N) {
*N=rng->norm;
VNorm(N);
if (VDot(N, &(incident->d)) > 0.0) {
N->x=-N->x;
N->y=-N->y;
N->z=-N->z;
}
}

View File

@@ -0,0 +1,69 @@
/*
Copyright (c) 2005-2020 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*
The original source for this example is
Copyright (c) 1994-2008 John E. Stone
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
*/
/*
* ring.h - This file contains the defines for rings etc.
*
* $Id: ring.h,v 1.2 2007-02-22 17:54:16 Exp $
*/
object * newring(void * tex, vector ctr, vector norm, flt in, flt out);
#ifdef RING_PRIVATE
typedef struct {
unsigned int id; /* Unique Object serial number */
void * nextobj; /* pointer to next object in list */
object_methods * methods; /* this object's methods */
texture * tex; /* object texture */
vector ctr;
vector norm;
flt inrad;
flt outrad;
} ring;
static int ring_bbox(void * obj, vector * min, vector * max);
static void ring_intersect(ring *, ray *);
static void ring_normal(ring *, vector *, ray * incident, vector *);
#endif

View File

@@ -0,0 +1,254 @@
/*
Copyright (c) 2005-2020 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*
The original source for this example is
Copyright (c) 1994-2008 John E. Stone
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
*/
/*
* shade.cpp - This file contains the functions that perform surface shading.
*/
#include "machine.h"
#include "types.h"
#include "macros.h"
#include "light.h"
#include "intersect.h"
#include "vector.h"
#include "trace.h"
#include "global.h"
#include "shade.h"
void reset_lights(void) {
numlights=0;
}
void add_light(point_light * li) {
lightlist[numlights]=li;
numlights++;
}
color shader(ray * incident) {
color col, diffuse, phongcol;
vector N, L, hit;
ray shadowray;
flt inten, t, Llen;
object * obj;
int numints, i;
point_light * li;
numints=closest_intersection(&t, &obj, incident->intstruct);
/* find the number of intersections */
/* and return the closest one. */
if (numints < 1) {
/* if there weren't any object intersections then return the */
/* background color for the pixel color. */
return incident->scene->background;
}
if (obj->tex->islight) { /* if the current object is a light, then we */
return obj->tex->col; /* will only use the objects ambient color */
}
RAYPNT(hit, (*incident), t) /* find the point of intersection from t */
obj->methods->normal(obj, &hit, incident, &N); /* find the surface normal */
/* execute the object's texture function */
col = obj->tex->texfunc(&hit, obj->tex, incident);
diffuse.r = 0.0;
diffuse.g = 0.0;
diffuse.b = 0.0;
phongcol = diffuse;
if ((obj->tex->diffuse > 0.0) || (obj->tex->phong > 0.0)) {
for (i=0; i<numlights; i++) { /* loop for light contributions */
li=lightlist[i]; /* set li=to the current light */
VSUB(li->ctr, hit, L) /* find the light vector */
/* calculate the distance to the light from the hit point */
Llen = sqrt(L.x*L.x + L.y*L.y + L.z*L.z) + EPSILON;
L.x /= Llen; /* normalize the light direction vector */
L.y /= Llen;
L.z /= Llen;
VDOT(inten, N, L) /* light intensity */
/* add in diffuse lighting for this light if we're facing it */
if (inten > 0.0) {
/* test for a shadow */
shadowray.intstruct = incident->intstruct;
shadowray.flags = RT_RAY_SHADOW | RT_RAY_BOUNDED;
incident->serial++;
shadowray.serial = incident->serial;
shadowray.mbox = incident->mbox;
shadowray.o = hit;
shadowray.d = L;
shadowray.maxdist = Llen;
shadowray.s = hit;
shadowray.e = li->ctr;
shadowray.scene = incident->scene;
reset_intersection(incident->intstruct);
intersect_objects(&shadowray);
if (!shadow_intersection(incident->intstruct, Llen)) {
/* XXX now that opacity is in the code, have to be more careful */
ColorAddS(&diffuse, &li->tex->col, inten);
/* phong type specular highlights */
if (obj->tex->phong > 0.0) {
flt phongval;
phongval = shade_phong(incident, &hit, &N, &L, obj->tex->phongexp);
if (obj->tex->phongtype)
ColorAddS(&phongcol, &col, phongval);
else
ColorAddS(&phongcol, &(li->tex->col), phongval);
}
}
}
}
}
ColorScale(&diffuse, obj->tex->diffuse);
col.r *= (diffuse.r + obj->tex->ambient); /* do a product of the */
col.g *= (diffuse.g + obj->tex->ambient); /* diffuse intensity with */
col.b *= (diffuse.b + obj->tex->ambient); /* object color + ambient */
if (obj->tex->phong > 0.0) {
ColorAccum(&col, &phongcol);
}
/* spawn reflection rays if necessary */
/* note: this will overwrite the old intersection list */
if (obj->tex->specular > 0.0) {
color specol;
specol = shade_reflection(incident, &hit, &N, obj->tex->specular);
ColorAccum(&col, &specol);
}
/* spawn transmission rays / refraction */
/* note: this will overwrite the old intersection list */
if (obj->tex->opacity < 1.0) {
color transcol;
transcol = shade_transmission(incident, &hit, 1.0 - obj->tex->opacity);
ColorAccum(&col, &transcol);
}
return col; /* return the color of the shaded pixel... */
}
color shade_reflection(ray * incident, vector * hit, vector * N, flt specular) {
ray specray;
color col;
vector R;
VAddS(-2.0 * (incident->d.x * N->x +
incident->d.y * N->y +
incident->d.z * N->z), N, &incident->d, &R);
specray.intstruct=incident->intstruct; /* what thread are we */
specray.depth=incident->depth - 1; /* go up a level in recursion depth */
specray.flags = RT_RAY_REGULAR; /* infinite ray, to start with */
specray.serial = incident->serial + 1; /* next serial number */
specray.mbox = incident->mbox;
specray.o=*hit;
specray.d=R; /* reflect incident ray about normal */
specray.o=Raypnt(&specray, EPSILON); /* avoid numerical precision bugs */
specray.maxdist = FHUGE; /* take any intersection */
specray.scene=incident->scene; /* global scenedef info */
col=trace(&specray); /* trace specular reflection ray */
incident->serial = specray.serial; /* update the serial number */
ColorScale(&col, specular);
return col;
}
color shade_transmission(ray * incident, vector * hit, flt trans) {
ray transray;
color col;
transray.intstruct=incident->intstruct; /* what thread are we */
transray.depth=incident->depth - 1; /* go up a level in recursion depth */
transray.flags = RT_RAY_REGULAR; /* infinite ray, to start with */
transray.serial = incident->serial + 1; /* update serial number */
transray.mbox = incident->mbox;
transray.o=*hit;
transray.d=incident->d; /* ray continues along incident path */
transray.o=Raypnt(&transray, EPSILON); /* avoid numerical precision bugs */
transray.maxdist = FHUGE; /* take any intersection */
transray.scene=incident->scene; /* global scenedef info */
col=trace(&transray); /* trace transmission ray */
incident->serial = transray.serial;
ColorScale(&col, trans);
return col;
}
flt shade_phong(ray * incident, vector * hit,
vector * N, vector * L, flt specpower){
vector H, V;
flt inten;
V = incident->d;
VScale(&V, -1.0);
VAdd(&V, L, &H);
VScale(&H, 0.5);
VNorm(&H);
inten = VDot(N, &H);
if (inten > 0.0)
inten = pow(inten, specpower);
else
inten = 0.0;
return inten;
}

View File

@@ -0,0 +1,58 @@
/*
Copyright (c) 2005-2020 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*
The original source for this example is
Copyright (c) 1994-2008 John E. Stone
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
*/
/*
* shade.h - This file contains declarations and definitions for the shader.
*
* $Id: shade.h,v 1.2 2007-02-22 17:54:16 Exp $
*/
void reset_lights(void);
void add_light(point_light *);
color shader(ray *);
color shade_reflection(ray *, vector *, vector *, flt);
color shade_transmission(ray *, vector *, flt);
flt shade_phong(ray * incident, vector * hit, vector * N, vector * L, flt specpower);

View File

@@ -0,0 +1,129 @@
/*
Copyright (c) 2005-2020 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*
The original source for this example is
Copyright (c) 1994-2008 John E. Stone
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
*/
/*
* sphere.cpp - This file contains the functions for dealing with spheres.
*/
#include "machine.h"
#include "types.h"
#include "macros.h"
#include "vector.h"
#include "intersect.h"
#include "util.h"
#define SPHERE_PRIVATE
#include "sphere.h"
static object_methods sphere_methods = {
(void (*)(void *, void *))(sphere_intersect),
(void (*)(void *, void *, void *, void *))(sphere_normal),
sphere_bbox,
free
};
object * newsphere(void * tex, vector ctr, flt rad) {
sphere * s;
s=(sphere *) rt_getmem(sizeof(sphere));
memset(s, 0, sizeof(sphere));
s->methods = &sphere_methods;
s->tex=(texture *)tex;
s->ctr=ctr;
s->rad=rad;
return (object *) s;
}
static int sphere_bbox(void * obj, vector * min, vector * max) {
sphere * s = (sphere *) obj;
min->x = s->ctr.x - s->rad;
min->y = s->ctr.y - s->rad;
min->z = s->ctr.z - s->rad;
max->x = s->ctr.x + s->rad;
max->y = s->ctr.y + s->rad;
max->z = s->ctr.z + s->rad;
return 1;
}
static void sphere_intersect(sphere * spr, ray * ry) {
flt b, disc, t1, t2, temp;
vector V;
VSUB(spr->ctr, ry->o, V);
VDOT(b, V, ry->d);
VDOT(temp, V, V);
disc=b*b + spr->rad*spr->rad - temp;
if (disc<=0.0) return;
disc=sqrt(disc);
t2=b+disc;
if (t2 <= SPEPSILON)
return;
add_intersection(t2, (object *) spr, ry);
t1=b-disc;
if (t1 > SPEPSILON)
add_intersection(t1, (object *) spr, ry);
}
static void sphere_normal(sphere * spr, vector * pnt, ray * incident, vector * N) {
VSub((vector *) pnt, &(spr->ctr), N);
VNorm(N);
if (VDot(N, &(incident->d)) > 0.0) {
N->x=-N->x;
N->y=-N->y;
N->z=-N->z;
}
}

View File

@@ -0,0 +1,69 @@
/*
Copyright (c) 2005-2020 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*
The original source for this example is
Copyright (c) 1994-2008 John E. Stone
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
*/
/*
* sphere.h - This file contains the defines for spheres etc.
*
* $Id: sphere.h,v 1.2 2007-02-22 17:54:16 Exp $
*/
object * newsphere(void *, vector, flt);
#ifdef SPHERE_PRIVATE
typedef struct {
unsigned int id; /* Unique Object serial number */
void * nextobj; /* pointer to next object in list */
object_methods * methods; /* this object's methods */
texture * tex; /* object texture */
vector ctr;
flt rad;
} sphere;
static int sphere_bbox(void * obj, vector * min, vector * max);
static void sphere_intersect(sphere *, ray *);
static void sphere_normal(sphere *, vector *, ray *, vector *);
#endif /* SPHERE_PRIVATE */

View File

@@ -0,0 +1,116 @@
/*
Copyright (c) 2005-2020 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*
The original source for this example is
Copyright (c) 1994-2008 John E. Stone
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "types.h"
#include "api.h" /* The ray tracing library API */
#include "ui.h"
#include "util.h"
#include "tachyon_video.h"
extern SceneHandle global_scene;
extern char *global_window_title;
extern bool global_usegraphics;
void tachyon_video::on_process() {
char buf[8192];
flt runtime;
scenedef *scene = (scenedef *) global_scene;
updating_mode = scene->displaymode == RT_DISPLAY_ENABLED;
recycling = false;
pausing = false;
do {
updating = updating_mode;
timer start_timer = gettimer();
rt_renderscene(global_scene);
timer end_timer = gettimer();
runtime = timertime(start_timer, end_timer);
sprintf(buf, "%s: %.3f seconds", global_window_title, runtime);
rt_ui_message(MSG_0, buf);
title = buf; show_title(); // show time spent for rendering
if(!updating) {
updating = true;
drawing_memory dm = get_drawing_memory();
drawing_area drawing(0, 0, dm.sizex, dm.sizey);// invalidate whole screen
}
rt_finalize();
title = global_window_title; show_title(); // reset title to default
} while(recycling && running);
}
void tachyon_video::on_key(int key) {
key &= 0xff;
recycling = true;
if(key == esc_key) running = false;
else if(key == ' ') {
if(!updating) {
updating = true;
drawing_memory dm = get_drawing_memory();
drawing_area drawing(0, 0, dm.sizex, dm.sizey);// invalidate whole screen
}
updating = updating_mode = !updating_mode;
}
else if(key == 'p') {
pausing = !pausing;
if(pausing) {
title = "Press ESC to exit or 'p' to continue after rendering completion";
show_title();
}
}
}
void rt_finalize(void) {
timer t0, t1;
t0 = gettimer();
if(global_usegraphics)
do { rt_sleep(1); t1 = gettimer(); }
while( (timertime(t0, t1) < 10 || video->pausing) && video->next_frame());
#ifdef _WINDOWS
else rt_sleep(10000);
#endif
}

View File

@@ -0,0 +1,58 @@
/*
Copyright (c) 2005-2020 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*
The original source for this example is
Copyright (c) 1994-2008 John E. Stone
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
*/
#include "../../../common/gui/video.h"
class tachyon_video : public video
{
public:
bool updating_mode;
bool recycling;
bool pausing;
void on_process();
void on_key(int key);
};
extern class tachyon_video *video;

View File

@@ -0,0 +1,381 @@
/*
Copyright (c) 2005-2020 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*
The original source for this example is
Copyright (c) 1994-2008 John E. Stone
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
*/
/*
* texture.cpp - This file contains functions for implementing textures.
*/
#include "machine.h"
#include "types.h"
#include "macros.h"
#include "texture.h"
#include "coordsys.h"
#include "imap.h"
#include "vector.h"
#include "box.h"
/* plain vanilla texture solely based on object color */
color standard_texture(vector * hit, texture * tex, ray * ry) {
return tex->col;
}
/* cylindrical image map */
color image_cyl_texture(vector * hit, texture * tex, ray * ry) {
vector rh;
flt u,v;
rh.x=hit->x - tex->ctr.x;
rh.z=hit->y - tex->ctr.y;
rh.y=hit->z - tex->ctr.z;
xyztocyl(rh, 1.0, &u, &v);
u = u * tex->scale.x;
u = u + tex->rot.x;
u=fmod(u, 1.0);
if (u < 0.0) u+=1.0;
v = v * tex->scale.y;
v = v + tex->rot.y;
v=fmod(v, 1.0);
if (v < 0.0) v+=1.0;
return ImageMap((rawimage *)tex->img, u, v);
}
/* spherical image map */
color image_sphere_texture(vector * hit, texture * tex, ray * ry) {
vector rh;
flt u,v;
rh.x=hit->x - tex->ctr.x;
rh.y=hit->y - tex->ctr.y;
rh.z=hit->z - tex->ctr.z;
xyztospr(rh, &u, &v);
u = u * tex->scale.x;
u = u + tex->rot.x;
u=fmod(u, 1.0);
if (u < 0.0) u+=1.0;
v = v * tex->scale.y;
v = v + tex->rot.y;
v=fmod(v, 1.0);
if (v < 0.0) v+=1.0;
return ImageMap((rawimage *)tex->img, u, v);
}
/* planar image map */
color image_plane_texture(vector * hit, texture * tex, ray * ry) {
vector pnt;
flt u,v;
pnt.x=hit->x - tex->ctr.x;
pnt.y=hit->y - tex->ctr.y;
pnt.z=hit->z - tex->ctr.z;
VDOT(u, tex->uaxs, pnt);
/* VDOT(len, tex->uaxs, tex->uaxs);
u = u / sqrt(len); */
VDOT(v, tex->vaxs, pnt);
/* VDOT(len, tex->vaxs, tex->vaxs);
v = v / sqrt(len); */
u = u * tex->scale.x;
u = u + tex->rot.x;
u = fmod(u, 1.0);
if (u < 0.0) u += 1.0;
v = v * tex->scale.y;
v = v + tex->rot.y;
v = fmod(v, 1.0);
if (v < 0.0) v += 1.0;
return ImageMap((rawimage *)tex->img, u, v);
}
color grit_texture(vector * hit, texture * tex, ray * ry) {
int rnum;
flt fnum;
color col;
rnum=rand() % 4096;
fnum=(rnum / 4096.0 * 0.2) + 0.8;
col.r=tex->col.r * fnum;
col.g=tex->col.g * fnum;
col.b=tex->col.b * fnum;
return col;
}
color checker_texture(vector * hit, texture * tex, ray * ry) {
long x,y,z;
flt xh,yh,zh;
color col;
xh=hit->x - tex->ctr.x;
x=(long) ((fabs(xh) * 3) + 0.5);
x=x % 2;
yh=hit->y - tex->ctr.y;
y=(long) ((fabs(yh) * 3) + 0.5);
y=y % 2;
zh=hit->z - tex->ctr.z;
z=(long) ((fabs(zh) * 3) + 0.5);
z=z % 2;
if (((x + y + z) % 2)==1) {
col.r=1.0;
col.g=0.2;
col.b=0.0;
}
else {
col.r=0.0;
col.g=0.2;
col.b=1.0;
}
return col;
}
color cyl_checker_texture(vector * hit, texture * tex, ray * ry) {
long x,y;
vector rh;
flt u,v;
color col;
rh.x=hit->x - tex->ctr.x;
rh.y=hit->y - tex->ctr.y;
rh.z=hit->z - tex->ctr.z;
xyztocyl(rh, 1.0, &u, &v);
x=(long) (fabs(u) * 18.0);
x=x % 2;
y=(long) (fabs(v) * 10.0);
y=y % 2;
if (((x + y) % 2)==1) {
col.r=1.0;
col.g=0.2;
col.b=0.0;
}
else {
col.r=0.0;
col.g=0.2;
col.b=1.0;
}
return col;
}
color wood_texture(vector * hit, texture * tex, ray * ry) {
flt radius, angle;
int grain;
color col;
flt x,y,z;
x=(hit->x - tex->ctr.x) * 1000;
y=(hit->y - tex->ctr.y) * 1000;
z=(hit->z - tex->ctr.z) * 1000;
radius=sqrt(x*x + z*z);
if (z == 0.0)
angle=3.1415926/2.0;
else
angle=atan(x / z);
radius=radius + 3.0 * sin(20 * angle + y / 150.0);
grain=((int) (radius + 0.5)) % 60;
if (grain < 40) {
col.r=0.8;
col.g=1.0;
col.b=0.2;
}
else {
col.r=0.0;
col.g=0.0;
col.b=0.0;
}
return col;
}
#define NMAX 28
short int NoiseMatrix[NMAX][NMAX][NMAX];
void InitNoise(void) {
byte x,y,z,i,j,k;
for (x=0; x<NMAX; x++) {
for (y=0; y<NMAX; y++) {
for (z=0; z<NMAX; z++) {
NoiseMatrix[x][y][z]=rand() % 12000;
if (x==NMAX-1) i=0;
else i=x;
if (y==NMAX-1) j=0;
else j=y;
if (z==NMAX-1) k=0;
else k=z;
NoiseMatrix[x][y][z]=NoiseMatrix[i][j][k];
}
}
}
}
int Noise(flt x, flt y, flt z) {
byte ix, iy, iz;
flt ox, oy, oz;
int p000, p001, p010, p011;
int p100, p101, p110, p111;
int p00, p01, p10, p11;
int p0, p1;
int d00, d01, d10, d11;
int d0, d1, d;
x=fabs(x);
y=fabs(y);
z=fabs(z);
ix=((int) x) % (NMAX-1);
iy=((int) y) % (NMAX-1);
iz=((int) z) % (NMAX-1);
ox=(x - ((int) x));
oy=(y - ((int) y));
oz=(z - ((int) z));
p000=NoiseMatrix[ix][iy][iz];
p001=NoiseMatrix[ix][iy][iz+1];
p010=NoiseMatrix[ix][iy+1][iz];
p011=NoiseMatrix[ix][iy+1][iz+1];
p100=NoiseMatrix[ix+1][iy][iz];
p101=NoiseMatrix[ix+1][iy][iz+1];
p110=NoiseMatrix[ix+1][iy+1][iz];
p111=NoiseMatrix[ix+1][iy+1][iz+1];
d00=p100-p000;
d01=p101-p001;
d10=p110-p010;
d11=p111-p011;
p00=(int) ((int) d00*ox) + p000;
p01=(int) ((int) d01*ox) + p001;
p10=(int) ((int) d10*ox) + p010;
p11=(int) ((int) d11*ox) + p011;
d0=p10-p00;
d1=p11-p01;
p0=(int) ((int) d0*oy) + p00;
p1=(int) ((int) d1*oy) + p01;
d=p1-p0;
return (int) ((int) d*oz) + p0;
}
color marble_texture(vector * hit, texture * tex, ray * ry) {
flt i,d;
flt x,y,z;
color col;
x=hit->x;
y=hit->y;
z=hit->z;
x=x * 1.0;
d=x + 0.0006 * Noise(x, (y * 1.0), (z * 1.0));
d=d*(((int) d) % 25);
i=0.0 + 0.10 * fabs(d - 10.0 - 20.0 * ((int) d * 0.05));
if (i > 1.0) i=1.0;
if (i < 0.0) i=0.0;
/*
col.r=i * tex->col.r;
col.g=i * tex->col.g;
col.b=i * tex->col.b;
*/
col.r = (1.0 + sin(i * 6.28)) / 2.0;
col.g = (1.0 + sin(i * 16.28)) / 2.0;
col.b = (1.0 + cos(i * 30.28)) / 2.0;
return col;
}
color gnoise_texture(vector * hit, texture * tex, ray * ry) {
color col;
flt f;
f=Noise((hit->x - tex->ctr.x),
(hit->y - tex->ctr.y),
(hit->z - tex->ctr.z));
if (f < 0.01) f=0.01;
if (f > 1.0) f=1.0;
col.r=tex->col.r * f;
col.g=tex->col.g * f;
col.b=tex->col.b * f;
return col;
}
void InitTextures(void) {
InitNoise();
ResetImages();
}

View File

@@ -0,0 +1,65 @@
/*
Copyright (c) 2005-2020 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*
The original source for this example is
Copyright (c) 1994-2008 John E. Stone
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
*/
/*
* texture.h This file contains all of the includes and defines for the texture
* mapping part of the shader.
*
* $Id: texture.h,v 1.2 2007-02-22 17:54:16 Exp $
*/
void InitTextures(void);
color standard_texture(vector *, texture *, ray *);
color image_cyl_texture(vector *, texture *, ray *);
color image_sphere_texture(vector *, texture *, ray *);
color image_plane_texture(vector *, texture *, ray *);
color checker_texture(vector *, texture *, ray *);
color cyl_checker_texture(vector *, texture *, ray *);
color grit_texture(vector *, texture *, ray *);
color wood_texture(vector *, texture *, ray *);
color marble_texture(vector *, texture *, ray *);
color gnoise_texture(vector *, texture *, ray *);
int Noise(flt, flt, flt);
void InitTextures(void);

View File

@@ -0,0 +1,233 @@
/*
Copyright (c) 2005-2020 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*
The original source for this example is
Copyright (c) 1994-2008 John E. Stone
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
*/
/*
* tgafile.cpp - This file contains the code to write 24 bit targa files...
*/
#include "machine.h"
#include "types.h"
#include "util.h"
#include "ui.h"
#include "imageio.h"
#include "tgafile.h"
void createtgafile(char *name, unsigned short width, unsigned short height) {
int filesize;
FILE * ofp;
filesize = 3*width*height + 18 - 10;
if (name==NULL)
exit(1);
else {
ofp=fopen(name, "w+b");
if (ofp == NULL) {
char msgtxt[2048];
sprintf(msgtxt, "Cannot create %s for output!", name);
rt_ui_message(MSG_ERR, msgtxt);
rt_ui_message(MSG_ABORT, "Rendering Aborted.");
exit(1);
}
fputc(0, ofp); /* IdLength */
fputc(0, ofp); /* ColorMapType */
fputc(2, ofp); /* ImageTypeCode */
fputc(0, ofp); /* ColorMapOrigin, low byte */
fputc(0, ofp); /* ColorMapOrigin, high byte */
fputc(0, ofp); /* ColorMapLength, low byte */
fputc(0, ofp); /* ColorMapLength, high byte */
fputc(0, ofp); /* ColorMapEntrySize */
fputc(0, ofp); /* XOrigin, low byte */
fputc(0, ofp); /* XOrigin, high byte */
fputc(0, ofp); /* YOrigin, low byte */
fputc(0, ofp); /* YOrigin, high byte */
fputc((width & 0xff), ofp); /* Width, low byte */
fputc(((width >> 8) & 0xff), ofp); /* Width, high byte */
fputc((height & 0xff), ofp); /* Height, low byte */
fputc(((height >> 8) & 0xff), ofp); /* Height, high byte */
fputc(24, ofp); /* ImagePixelSize */
fputc(0x20, ofp); /* ImageDescriptorByte 0x20 == flip vertically */
fseek(ofp, filesize, 0);
fprintf(ofp, "9876543210");
fclose(ofp);
}
}
void * opentgafile(char * filename) {
FILE * ofp;
ofp=fopen(filename, "r+b");
if (ofp == NULL) {
char msgtxt[2048];
sprintf(msgtxt, "Cannot open %s for output!", filename);
rt_ui_message(MSG_ERR, msgtxt);
rt_ui_message(MSG_ABORT, "Rendering Aborted.");
exit(1);
}
return ofp;
}
void writetgaregion(void * voidofp,
int iwidth, int iheight,
int startx, int starty,
int stopx, int stopy, char * buffer) {
int y, totalx, totaly;
char * bufpos;
long filepos;
size_t numbytes;
FILE * ofp = (FILE *) voidofp;
totalx = stopx - startx + 1;
totaly = stopy - starty + 1;
for (y=0; y<totaly; y++) {
bufpos=buffer + (totalx*3)*(totaly-y-1);
filepos=18 + iwidth*3*(iheight - starty - totaly + y + 1) + (startx - 1)*3;
if (filepos >= 18) {
fseek(ofp, filepos, 0);
numbytes = fwrite(bufpos, 3, totalx, ofp);
if (numbytes != totalx) {
char msgtxt[256];
sprintf(msgtxt, "File write problem, %d bytes written.", (int)numbytes);
rt_ui_message(MSG_ERR, msgtxt);
}
}
else {
rt_ui_message(MSG_ERR, "writetgaregion: file ptr out of range!!!\n");
return; /* don't try to continue */
}
}
}
int readtga(char * name, int * xres, int * yres, unsigned char **imgdata) {
int format, width, height, w1, w2, h1, h2, depth, flags;
int imgsize, i, tmp;
size_t bytesread;
FILE * ifp;
ifp=fopen(name, "r");
if (ifp==NULL) {
return IMAGEBADFILE; /* couldn't open the file */
}
/* read the targa header */
getc(ifp); /* ID length */
getc(ifp); /* colormap type */
format = getc(ifp); /* image type */
getc(ifp); /* color map origin */
getc(ifp); /* color map origin */
getc(ifp); /* color map length */
getc(ifp); /* color map length */
getc(ifp); /* color map entry size */
getc(ifp); /* x origin */
getc(ifp); /* x origin */
getc(ifp); /* y origin */
getc(ifp); /* y origin */
w1 = getc(ifp); /* width (low) */
w2 = getc(ifp); /* width (hi) */
h1 = getc(ifp); /* height (low) */
h2 = getc(ifp); /* height (hi) */
depth = getc(ifp); /* image pixel size */
flags = getc(ifp); /* image descriptor byte */
if ((format != 2) || (depth != 24)) {
fclose(ifp);
return IMAGEUNSUP; /* unsupported targa format */
}
width = ((w2 << 8) | w1);
height = ((h2 << 8) | h1);
imgsize = 3 * width * height;
*imgdata = (unsigned char *)rt_getmem(imgsize);
bytesread = fread(*imgdata, 1, imgsize, ifp);
fclose(ifp);
/* flip image vertically */
if (flags == 0x20) {
int rowsize = 3 * width;
unsigned char * copytmp;
copytmp = (unsigned char *)malloc(rowsize);
for (i=0; i<height / 2; i++) {
memcpy(copytmp, &((*imgdata)[rowsize*i]), rowsize);
memcpy(&(*imgdata)[rowsize*i], &(*imgdata)[rowsize*(height - 1 - i)], rowsize);
memcpy(&(*imgdata)[rowsize*(height - 1 - i)], copytmp, rowsize);
}
free(copytmp);
}
/* convert from BGR order to RGB order */
for (i=0; i<imgsize; i+=3) {
tmp = (*imgdata)[i]; /* Blue */
(*imgdata)[i] = (*imgdata)[i+2]; /* Red */
(*imgdata)[i+2] = tmp; /* Blue */
}
*xres = width;
*yres = height;
if (bytesread != imgsize)
return IMAGEREADERR;
return IMAGENOERR;
}

View File

@@ -0,0 +1,57 @@
/*
Copyright (c) 2005-2020 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*
The original source for this example is
Copyright (c) 1994-2008 John E. Stone
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
*/
/*
* tgafile.h - this file contains defines and structures for tgafile.c
*
* $Id: tgafile.h,v 1.2 2007-02-22 17:54:16 Exp $
*/
/* declare other functions */
void createtgafile(char *, unsigned short, unsigned short);
void * opentgafile(char *);
void writetgaregion(void *, int, int, int, int, int, int, char *);
int readtga(char * name, int * xres, int * yres, unsigned char **imgdata);

View File

@@ -0,0 +1,94 @@
/*
Copyright (c) 2005-2020 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*
The original source for this example is
Copyright (c) 1994-2008 John E. Stone
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
*/
/*
* trace.h - This file contains the declarations and defines for the trace module
*
* $Id: trace.h,v 1.2 2007-02-22 17:54:16 Exp $
*/
extern char *global_buffer;
typedef struct {
int tid;
int nthr;
scenedef scene;
char * buffer;
int startx;
int stopx;
int starty;
int stopy;
} thr_parms;
typedef struct {
int startx;
int stopx;
int starty;
int stopy;
} patch;
typedef struct {
void * tga;
int iwidth;
int iheight;
int startx;
int starty;
int stopx;
int stopy;
char * buffer;
} thr_io_parms;
color trace(ray *);
void * thread_trace(thr_parms * parms);
void thread_trace1(thr_parms *, patch *, int depth);
void thread_trace2(thr_parms *, patch *);
void * thread_io(void *);
void trace_shm(scenedef, /*char *,*/ int, int, int, int);
void trace_region(scenedef, void *, int, int, int, int);

View File

@@ -0,0 +1,173 @@
/*
Copyright (c) 2005-2020 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*
The original source for this example is
Copyright (c) 1994-2008 John E. Stone
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
*/
#include "machine.h"
#include "types.h"
#include "macros.h"
#include "vector.h"
#include "tgafile.h"
#include "trace.h"
#include "light.h"
#include "shade.h"
#include "camera.h"
#include "util.h"
#include "intersect.h"
#include "global.h"
#include "ui.h"
#include "tachyon_video.h"
// shared but read-only so could be private too
static thr_parms *all_parms;
static scenedef scene;
static int startx;
static int stopx;
static int starty;
static int stopy;
static flt jitterscale;
static int totaly;
static color_t render_one_pixel (int x, int y, unsigned int *local_mbox, unsigned int &serial,
int startx, int stopx, int starty, int stopy)
{
/* private vars moved inside loop */
ray primary, sample;
color col, avcol;
int R,G,B;
intersectstruct local_intersections;
int alias;
/* end private */
primary=camray(&scene, x, y);
primary.intstruct = &local_intersections;
primary.flags = RT_RAY_REGULAR;
serial++;
primary.serial = serial;
primary.mbox = local_mbox;
primary.maxdist = FHUGE;
primary.scene = &scene;
col=trace(&primary);
serial = primary.serial;
/* perform antialiasing if enabled.. */
if (scene.antialiasing > 0) {
for (alias=0; alias < scene.antialiasing; alias++) {
serial++; /* increment serial number */
sample=primary; /* copy the regular primary ray to start with */
sample.serial = serial;
{
sample.d.x+=((std::rand() % 100) - 50) / jitterscale;
sample.d.y+=((std::rand() % 100) - 50) / jitterscale;
sample.d.z+=((std::rand() % 100) - 50) / jitterscale;
}
avcol=trace(&sample);
serial = sample.serial; /* update our overall serial # */
col.r += avcol.r;
col.g += avcol.g;
col.b += avcol.b;
}
col.r /= (scene.antialiasing + 1.0);
col.g /= (scene.antialiasing + 1.0);
col.b /= (scene.antialiasing + 1.0);
}
/* Handle overexposure and underexposure here... */
R=(int) (col.r*255);
if (R > 255) R = 255;
else if (R < 0) R = 0;
G=(int) (col.g*255);
if (G > 255) G = 255;
else if (G < 0) G = 0;
B=(int) (col.b*255);
if (B > 255) B = 255;
else if (B < 0) B = 0;
return video->get_color(R, G, B);
}
static void parallel_thread (void)
{
// thread-local storage
unsigned int serial = 1;
unsigned int mboxsize = sizeof(unsigned int)*(max_objectid() + 20);
unsigned int * local_mbox = (unsigned int *) alloca(mboxsize);
memset(local_mbox,0,mboxsize);
for (int y = starty; y < stopy; y++) { {
drawing_area drawing(startx, totaly-y, stopx-startx, 1);
for (int x = startx; x < stopx; x++) {
color_t c = render_one_pixel (x, y, local_mbox, serial, startx, stopx, starty, stopy);
drawing.put_pixel(c);
} }
if(!video->next_frame()) return;
}
}
void * thread_trace(thr_parms * parms)
{
// shared but read-only so could be private too
all_parms = parms;
scene = parms->scene;
startx = parms->startx;
stopx = parms->stopx;
starty = parms->starty;
stopy = parms->stopy;
jitterscale = 40.0*(scene.hres + scene.vres);
totaly = parms->scene.vres-1;
parallel_thread ();
return(NULL);
}

View File

@@ -0,0 +1,178 @@
/*
Copyright (c) 2005-2020 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*
The original source for this example is
Copyright (c) 1994-2008 John E. Stone
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
*/
#include "machine.h"
#include "types.h"
#include "macros.h"
#include "vector.h"
#include "tgafile.h"
#include "trace.h"
#include "light.h"
#include "shade.h"
#include "camera.h"
#include "util.h"
#include "intersect.h"
#include "global.h"
#include "ui.h"
#include "tachyon_video.h"
// shared but read-only so could be private too
static thr_parms *all_parms;
static scenedef scene;
static int startx;
static int stopx;
static int starty;
static int stopy;
static flt jitterscale;
static int totaly;
static color_t render_one_pixel (int x, int y, unsigned int *local_mbox, unsigned int &serial,
int startx, int stopx, int starty, int stopy)
{
/* private vars moved inside loop */
ray primary;
color col;
int R,G,B;
intersectstruct local_intersections;
/* end private */
primary = camray(&scene, x, y);
primary.intstruct = &local_intersections;
primary.flags = RT_RAY_REGULAR;
serial++;
primary.serial = serial;
primary.mbox = local_mbox;
primary.maxdist = FHUGE;
primary.scene = &scene;
col = trace(&primary);
serial = primary.serial;
/* Handle overexposure and underexposure here... */
R = (int)(col.r * 255);
if ( R > 255 ) R = 255;
else if ( R < 0 ) R = 0;
G = (int)(col.g * 255);
if ( G > 255 ) G = 255;
else if ( G < 0 ) G = 0;
B = (int)(col.b * 255);
if ( B > 255 ) B = 255;
else if ( B < 0 ) B = 0;
return video->get_color(R, G, B);
}
#if DO_ITT_NOTIFY
#include"ittnotify.h"
#endif
#define RUNTIME_SERIAL 1
#define RUNTIME_OPENMP 2
#define RUNTIME_CILK 3
#define RUNTIME_TBB 4
#ifndef RUNTIME
#define RUNTIME RUNTIME_TBB
#endif
#if RUNTIME == RUNTIME_OPENMP
#include <omp.h>
#elif RUNTIME == RUNTIME_TBB
#include <tbb/tbb.h>
#endif
static void parallel_thread(void)
{
unsigned int mboxsize = sizeof(unsigned int)*(max_objectid() + 20);
#if RUNTIME == RUNTIME_SERIAL
for ( int y = starty; y < stopy; y++ )
#elif RUNTIME == RUNTIME_OPENMP
#pragma omp parallel for
for ( int y = starty; y < stopy; y++ )
#elif RUNTIME == RUNTIME_CILK
_Cilk_for(int y = starty; y < stopy; y++)
#elif RUNTIME == RUNTIME_TBB
tbb::parallel_for(starty, stopy, [mboxsize] (int y)
#endif
{
unsigned int serial = 1;
unsigned int local_mbox[mboxsize];
memset(local_mbox, 0, mboxsize);
drawing_area drawing(startx, totaly - y, stopx - startx, 1);
for ( int x = startx; x < stopx; x++ ) {
color_t c = render_one_pixel(x, y, local_mbox, serial, startx, stopx, starty, stopy);
drawing.put_pixel(c);
}
video->next_frame();
}
#if RUNTIME == RUNTIME_TBB
);
#endif
}
void * thread_trace(thr_parms * parms)
{
// shared but read-only so could be private too
all_parms = parms;
scene = parms->scene;
startx = parms->startx;
stopx = parms->stopx;
starty = parms->starty;
stopy = parms->stopy;
jitterscale = 40.0*(scene.hres + scene.vres);
totaly = parms->scene.vres - 1;
#if DO_ITT_NOTIFY
__itt_resume();
#endif
parallel_thread();
#if DO_ITT_NOTIFY
__itt_pause();
#endif
return(NULL);
}

View File

@@ -0,0 +1,266 @@
/*
Copyright (c) 2005-2020 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*
The original source for this example is
Copyright (c) 1994-2008 John E. Stone
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
*/
#include "machine.h"
#include "types.h"
#include "macros.h"
#include "vector.h"
#include "tgafile.h"
#include "trace.h"
#include "light.h"
#include "shade.h"
#include "camera.h"
#include "util.h"
#include "intersect.h"
#include "global.h"
#include "ui.h"
#include "tachyon_video.h"
// shared but read-only so could be private too
static thr_parms *all_parms;
static scenedef scene;
static int startx;
static int stopx;
static int starty;
static int stopy;
static flt jitterscale;
static int totaly;
#ifdef MARK_RENDERING_AREA
// rgb colors list for coloring image by each thread
static const float inner_alpha = 0.3;
static const float border_alpha = 0.5;
#define NUM_COLORS 24
static int colors[NUM_COLORS][3] = {
{255,110,0}, {220,254,0}, {102,254,0}, {0,21,254}, {97,0,254}, {254,30,0},
{20,41,8}, {144,238,38}, {184,214,139}, {28,95,20}, {139,173,148}, {188,228,183},
{145,47,56}, {204,147,193}, {45,202,143}, {204,171,143}, {143,160,204}, {220,173,3},
{1,152,231}, {79,235,237}, {52,193,72}, {67,136,151}, {78,87,179}, {143,255,9},
};
#include <atomic>
#include "tbb/enumerable_thread_specific.h"
// storage and counter for thread numbers in order of first task run
typedef tbb::enumerable_thread_specific< int > thread_id_t;
thread_id_t thread_ids (-1);
std::atomic<int> thread_number;
#endif
#include "tbb/parallel_for.h"
#include "tbb/spin_mutex.h"
#include "tbb/blocked_range2d.h"
#include "tbb/global_control.h"
#include "../../../common/utility/get_default_num_threads.h"
static tbb::spin_mutex MyMutex, MyMutex2;
static color_t render_one_pixel (int x, int y, unsigned int *local_mbox, unsigned int &serial,
int startx, int stopx, int starty, int stopy
#ifdef MARK_RENDERING_AREA
, int *blend, float alpha
#endif
)
{
/* private vars moved inside loop */
ray primary, sample;
color col, avcol;
int R,G,B;
intersectstruct local_intersections;
int alias;
/* end private */
primary=camray(&scene, x, y);
primary.intstruct = &local_intersections;
primary.flags = RT_RAY_REGULAR;
serial++;
primary.serial = serial;
primary.mbox = local_mbox;
primary.maxdist = FHUGE;
primary.scene = &scene;
col=trace(&primary);
serial = primary.serial;
/* perform antialiasing if enabled.. */
if (scene.antialiasing > 0) {
for (alias=0; alias < scene.antialiasing; alias++) {
serial++; /* increment serial number */
sample=primary; /* copy the regular primary ray to start with */
sample.serial = serial;
{
tbb::spin_mutex::scoped_lock lock (MyMutex);
sample.d.x+=((rand() % 100) - 50) / jitterscale;
sample.d.y+=((rand() % 100) - 50) / jitterscale;
sample.d.z+=((rand() % 100) - 50) / jitterscale;
}
avcol=trace(&sample);
serial = sample.serial; /* update our overall serial # */
col.r += avcol.r;
col.g += avcol.g;
col.b += avcol.b;
}
col.r /= (scene.antialiasing + 1.0);
col.g /= (scene.antialiasing + 1.0);
col.b /= (scene.antialiasing + 1.0);
}
/* Handle overexposure and underexposure here... */
R=(int) (col.r*255);
if (R > 255) R = 255;
else if (R < 0) R = 0;
G=(int) (col.g*255);
if (G > 255) G = 255;
else if (G < 0) G = 0;
B=(int) (col.b*255);
if (B > 255) B = 255;
else if (B < 0) B = 0;
#ifdef MARK_RENDERING_AREA
R = int((1.0 - alpha) * R + alpha * blend[0]);
G = int((1.0 - alpha) * G + alpha * blend[1]);
B = int((1.0 - alpha) * B + alpha * blend[2]);
#endif
return video->get_color(R, G, B);
}
class parallel_task {
public:
void operator() (const tbb::blocked_range2d<int> &r) const
{
// task-local storage
unsigned int serial = 1;
unsigned int mboxsize = sizeof(unsigned int)*(max_objectid() + 20);
unsigned int * local_mbox = (unsigned int *) alloca(mboxsize);
memset(local_mbox,0,mboxsize);
#ifdef MARK_RENDERING_AREA
// compute thread number while first task run
thread_id_t::reference thread_id = thread_ids.local();
if (thread_id == -1) thread_id = thread_number++;
// choose thread color
int pos = thread_id % NUM_COLORS;
if(video->running) {
drawing_area drawing(r.cols().begin(), totaly-r.rows().end(), r.cols().end() - r.cols().begin(), r.rows().end()-r.rows().begin());
for (int i = 1, y = r.rows().begin(); y != r.rows().end(); ++y, i++) {
drawing.set_pos(0, drawing.size_y-i);
for (int x = r.cols().begin(); x != r.cols().end(); x++) {
int d = (y % 3 == 0) ? 2 : 1;
drawing.put_pixel(video->get_color(colors[pos][0]/d, colors[pos][1]/d, colors[pos][2]/d));
}
}
}
#endif
if(video->next_frame()) {
drawing_area drawing(r.cols().begin(), totaly-r.rows().end(), r.cols().end() - r.cols().begin(), r.rows().end()-r.rows().begin());
for (int i = 1, y = r.rows().begin(); y != r.rows().end(); ++y, i++) {
drawing.set_pos(0, drawing.size_y-i);
for (int x = r.cols().begin(); x != r.cols().end(); x++) {
#ifdef MARK_RENDERING_AREA
float alpha = y==r.rows().begin()||y==r.rows().end()-1||x==r.cols().begin()||x==r.cols().end()-1
? border_alpha : inner_alpha;
color_t c = render_one_pixel (x, y, local_mbox, serial, startx, stopx, starty, stopy, colors[pos], alpha);
#else
color_t c = render_one_pixel (x, y, local_mbox, serial, startx, stopx, starty, stopy);
#endif
drawing.put_pixel(c);
}
}
}
}
parallel_task () {}
};
void * thread_trace(thr_parms * parms)
{
#if !WIN8UI_EXAMPLE
int n, nthreads = utility::get_default_num_threads();
char *nthreads_str = getenv ("TBB_NUM_THREADS");
if (nthreads_str && (sscanf (nthreads_str, "%d", &n) > 0) && (n > 0)) nthreads = n;
tbb::global_control c(tbb::global_control::max_allowed_parallelism, nthreads);
#endif
// shared but read-only so could be private too
all_parms = parms;
scene = parms->scene;
startx = parms->startx;
stopx = parms->stopx;
starty = parms->starty;
stopy = parms->stopy;
jitterscale = 40.0*(scene.hres + scene.vres);
totaly = parms->scene.vres;
#ifdef MARK_RENDERING_AREA
thread_ids.clear();
#endif
int grain_size = 8;
//WIN8UI does not support getenv() function so using auto_partitioner unconditionally
#if !WIN8UI_EXAMPLE
int g;
char *grain_str = getenv ("TBB_GRAINSIZE");
if (grain_str && (sscanf (grain_str, "%d", &g) > 0) && (g > 0)) grain_size = g;
char *sched_str = getenv ("TBB_PARTITIONER");
static tbb::affinity_partitioner g_ap; // reused across calls to thread_trace
if ( sched_str && !strncmp(sched_str, "aff", 3) )
tbb::parallel_for (tbb::blocked_range2d<int> (starty, stopy, grain_size, startx, stopx, grain_size), parallel_task (), g_ap);
else if ( sched_str && !strncmp(sched_str, "simp", 4) )
tbb::parallel_for (tbb::blocked_range2d<int> (starty, stopy, grain_size, startx, stopx, grain_size), parallel_task (), tbb::simple_partitioner());
else
#endif
tbb::parallel_for (tbb::blocked_range2d<int> (starty, stopy, grain_size, startx, stopx, grain_size), parallel_task (), tbb::auto_partitioner());
return(NULL);
}

View File

@@ -0,0 +1,202 @@
/*
Copyright (c) 2005-2020 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*
The original source for this example is
Copyright (c) 1994-2008 John E. Stone
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
*/
#include "machine.h"
#include "types.h"
#include "macros.h"
#include "vector.h"
#include "tgafile.h"
#include "trace.h"
#include "light.h"
#include "shade.h"
#include "camera.h"
#include "util.h"
#include "intersect.h"
#include "global.h"
#include "ui.h"
#include "tachyon_video.h"
// shared but read-only so could be private too
static thr_parms *all_parms;
static scenedef scene;
static int startx;
static int stopx;
static int starty;
static int stopy;
static flt jitterscale;
static int totaly;
#include "tbb/parallel_for.h"
#include "tbb/spin_mutex.h"
#include "tbb/blocked_range.h"
#include "tbb/global_control.h"
#include "../../../common/utility/get_default_num_threads.h"
static tbb::spin_mutex MyMutex, MyMutex2;
static color_t render_one_pixel (int x, int y, unsigned int *local_mbox, unsigned int &serial,
int startx, int stopx, int starty, int stopy)
{
/* private vars moved inside loop */
ray primary, sample;
color col, avcol;
int R,G,B;
intersectstruct local_intersections;
int alias;
/* end private */
primary=camray(&scene, x, y);
primary.intstruct = &local_intersections;
primary.flags = RT_RAY_REGULAR;
serial++;
primary.serial = serial;
primary.mbox = local_mbox;
primary.maxdist = FHUGE;
primary.scene = &scene;
col=trace(&primary);
serial = primary.serial;
/* perform antialiasing if enabled.. */
if (scene.antialiasing > 0) {
for (alias=0; alias < scene.antialiasing; alias++) {
serial++; /* increment serial number */
sample=primary; /* copy the regular primary ray to start with */
sample.serial = serial;
{
tbb::spin_mutex::scoped_lock lock (MyMutex);
sample.d.x+=((rand() % 100) - 50) / jitterscale;
sample.d.y+=((rand() % 100) - 50) / jitterscale;
sample.d.z+=((rand() % 100) - 50) / jitterscale;
}
avcol=trace(&sample);
serial = sample.serial; /* update our overall serial # */
col.r += avcol.r;
col.g += avcol.g;
col.b += avcol.b;
}
col.r /= (scene.antialiasing + 1.0);
col.g /= (scene.antialiasing + 1.0);
col.b /= (scene.antialiasing + 1.0);
}
/* Handle overexposure and underexposure here... */
R=(int) (col.r*255);
if (R > 255) R = 255;
else if (R < 0) R = 0;
G=(int) (col.g*255);
if (G > 255) G = 255;
else if (G < 0) G = 0;
B=(int) (col.b*255);
if (B > 255) B = 255;
else if (B < 0) B = 0;
return video->get_color(R, G, B);
}
class parallel_task {
public:
void operator() (const tbb::blocked_range<int> &r) const
{
// task-local storage
unsigned int serial = 1;
unsigned int mboxsize = sizeof(unsigned int)*(max_objectid() + 20);
unsigned int * local_mbox = (unsigned int *) alloca(mboxsize);
memset(local_mbox,0,mboxsize);
for (int y = r.begin(); y != r.end(); ++y) { {
drawing_area drawing(startx, totaly-y, stopx-startx, 1);
for (int x = startx; x < stopx; x++) {
color_t c = render_one_pixel (x, y, local_mbox, serial, startx, stopx, starty, stopy);
drawing.put_pixel(c);
} }
if(!video->next_frame()) return;
}
}
parallel_task () {}
};
void * thread_trace(thr_parms * parms)
{
int n, nthreads = utility::get_default_num_threads();
char *nthreads_str = getenv ("TBB_NUM_THREADS");
if (nthreads_str && (sscanf (nthreads_str, "%d", &n) > 0) && (n > 0)) nthreads = n;
tbb::global_control c(tbb::global_control::max_allowed_parallelism, nthreads);
// shared but read-only so could be private too
all_parms = parms;
scene = parms->scene;
startx = parms->startx;
stopx = parms->stopx;
starty = parms->starty;
stopy = parms->stopy;
jitterscale = 40.0*(scene.hres + scene.vres);
totaly = parms->scene.vres-1;
int g, grain_size = 1;
char *grain_str = getenv ("TBB_GRAINSIZE");
if (grain_str && (sscanf (grain_str, "%d", &g) > 0) && (g > 0)) grain_size = g;
char *sched_str = getenv ("TBB_PARTITIONER");
static tbb::affinity_partitioner g_ap;
if ( sched_str && !strncmp(sched_str, "aff", 3) )
tbb::parallel_for (tbb::blocked_range<int> (starty, stopy, grain_size), parallel_task (), g_ap );
else if ( sched_str && !strncmp(sched_str, "simp", 4) )
tbb::parallel_for (tbb::blocked_range<int> (starty, stopy, grain_size), parallel_task (), tbb::simple_partitioner() );
else
tbb::parallel_for (tbb::blocked_range<int> (starty, stopy, grain_size), parallel_task (), tbb::auto_partitioner() );
return(NULL);
}

View File

@@ -0,0 +1,134 @@
/*
Copyright (c) 2005-2020 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*
The original source for this example is
Copyright (c) 1994-2008 John E. Stone
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
*/
/*
* trace.cpp - This file contains the functions for firing primary rays
* and handling subsequent calculations
*/
#include "machine.h"
#include "types.h"
#include "macros.h"
#include "vector.h"
#include "tgafile.h"
#include "trace.h"
#include "light.h"
#include "shade.h"
#include "camera.h"
#include "util.h"
#include "intersect.h"
#include "global.h"
#include "ui.h"
#include "tachyon_video.h"
color trace(ray * primary) {
if (primary->depth > 0) {
VNorm(&primary->d);
reset_intersection(primary->intstruct);
intersect_objects(primary);
return shader(primary);
}
/* if ray is truncated, return the background as its color */
return primary->scene->background;
}
void * thread_io(void * parms) {
thr_io_parms p;
p= *((thr_io_parms *) parms);
writetgaregion(p.tga, p.iwidth, p.iheight, p.startx, p.starty,
p.stopx, p.stopy, p.buffer);
free(p.buffer); /* free the buffer once we are done with it.. */
free(parms);
return(NULL);
}
void trace_shm(scenedef scene, /*char * buffer, */ int startx, int stopx, int starty, int stopy) {
thr_parms * parms;
parms = (thr_parms *) rt_getmem(sizeof(thr_parms));
parms->tid=0;
parms->nthr=1;
parms->scene=scene;
parms->startx=startx;
parms->stopx=stopx;
parms->starty=starty;
parms->stopy=stopy;
thread_trace(parms);
rt_freemem(parms);
}
void trace_region(scenedef scene, void * tga, int startx, int starty, int stopx, int stopy) {
if (scene.verbosemode) {
char msgtxt[2048];
sprintf(msgtxt, "Node %3d tracing region %4d, %4d ---> %4d, %4d \n", 0, startx,starty,stopx,stopy);
rt_ui_message(MSG_0, msgtxt);
}
trace_shm(scene, /*buffer,*/ startx, stopx, starty, stopy);
/* not used now
writetgaregion(tga, scene.hres, scene.vres,
startx, starty, stopx, stopy, global_buffer);
if (scene.rawimage != NULL) {
int x, y;
int totalx = stopx - startx + 1;
for (y=starty; y<=stopy; y++) {
for (x=0; x<scene.hres; x++) {
scene.rawimage[(scene.vres-y)*scene.hres*3 + x*3] = global_buffer[(y-starty)*totalx*3 + x*3 + 2];
scene.rawimage[(scene.vres-y)*scene.hres*3 + x*3 +1] = global_buffer[(y-starty)*totalx*3 + x*3 + 1];
scene.rawimage[(scene.vres-y)*scene.hres*3 + x*3 +2] = global_buffer[(y-starty)*totalx*3 + x*3];
}
}
}
*/
}

View File

@@ -0,0 +1,241 @@
/*
Copyright (c) 2005-2020 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*
The original source for this example is
Copyright (c) 1994-2008 John E. Stone
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
*/
/*
* triangle.cpp - This file contains the functions for dealing with triangles.
*/
#include "machine.h"
#include "types.h"
#include "vector.h"
#include "macros.h"
#include "intersect.h"
#include "util.h"
#define TRIANGLE_PRIVATE
#include "triangle.h"
static object_methods tri_methods = {
(void (*)(void *, void *))(tri_intersect),
(void (*)(void *, void *, void *, void *))(tri_normal),
tri_bbox,
free
};
static object_methods stri_methods = {
(void (*)(void *, void *))(tri_intersect),
(void (*)(void *, void *, void *, void *))(stri_normal),
tri_bbox,
free
};
object * newtri(void * tex, vector v0, vector v1, vector v2) {
tri * t;
vector edge1, edge2, edge3;
VSub(&v1, &v0, &edge1);
VSub(&v2, &v0, &edge2);
VSub(&v2, &v1, &edge3);
/* check to see if this will be a degenerate triangle before creation */
if ((VLength(&edge1) >= EPSILON) &&
(VLength(&edge2) >= EPSILON) &&
(VLength(&edge3) >= EPSILON)) {
t=(tri *) rt_getmem(sizeof(tri));
t->nextobj = NULL;
t->methods = &tri_methods;
t->tex = (texture *)tex;
t->v0 = v0;
t->edge1 = edge1;
t->edge2 = edge2;
return (object *) t;
}
return NULL; /* was a degenerate triangle */
}
object * newstri(void * tex, vector v0, vector v1, vector v2,
vector n0, vector n1, vector n2) {
stri * t;
vector edge1, edge2, edge3;
VSub(&v1, &v0, &edge1);
VSub(&v2, &v0, &edge2);
VSub(&v2, &v1, &edge3);
/* check to see if this will be a degenerate triangle before creation */
if ((VLength(&edge1) >= EPSILON) &&
(VLength(&edge2) >= EPSILON) &&
(VLength(&edge3) >= EPSILON)) {
t=(stri *) rt_getmem(sizeof(stri));
t->nextobj = NULL;
t->methods = &stri_methods;
t->tex = (texture *)tex;
t->v0 = v0;
t->edge1 = edge1;
t->edge2 = edge2;
t->n0 = n0;
t->n1 = n1;
t->n2 = n2;
return (object *) t;
}
return NULL; /* was a degenerate triangle */
}
#define CROSS(dest,v1,v2) \
dest.x=v1.y*v2.z-v1.z*v2.y; \
dest.y=v1.z*v2.x-v1.x*v2.z; \
dest.z=v1.x*v2.y-v1.y*v2.x;
#define DOT(v1,v2) (v1.x*v2.x+v1.y*v2.y+v1.z*v2.z)
#define SUB(dest,v1,v2) \
dest.x=v1.x-v2.x; \
dest.y=v1.y-v2.y; \
dest.z=v1.z-v2.z;
static int tri_bbox(void * obj, vector * min, vector * max) {
tri * t = (tri *) obj;
vector v1, v2;
VAdd(&t->v0, &t->edge1, &v1);
VAdd(&t->v0, &t->edge2, &v2);
min->x = MYMIN( t->v0.x , MYMIN( v1.x , v2.x ));
min->y = MYMIN( t->v0.y , MYMIN( v1.y , v2.y ));
min->z = MYMIN( t->v0.z , MYMIN( v1.z , v2.z ));
max->x = MYMAX( t->v0.x , MYMAX( v1.x , v2.x ));
max->y = MYMAX( t->v0.y , MYMAX( v1.y , v2.y ));
max->z = MYMAX( t->v0.z , MYMAX( v1.z , v2.z ));
return 1;
}
static void tri_intersect(tri * trn, ray * ry) {
vector tvec, pvec, qvec;
flt det, inv_det, t, u, v;
/* begin calculating determinant - also used to calculate U parameter */
CROSS(pvec, ry->d, trn->edge2);
/* if determinant is near zero, ray lies in plane of triangle */
det = DOT(trn->edge1, pvec);
if (det > -EPSILON && det < EPSILON)
return;
inv_det = 1.0 / det;
/* calculate distance from vert0 to ray origin */
SUB(tvec, ry->o, trn->v0);
/* calculate U parameter and test bounds */
u = DOT(tvec, pvec) * inv_det;
if (u < 0.0 || u > 1.0)
return;
/* prepare to test V parameter */
CROSS(qvec, tvec, trn->edge1);
/* calculate V parameter and test bounds */
v = DOT(ry->d, qvec) * inv_det;
if (v < 0.0 || u + v > 1.0)
return;
/* calculate t, ray intersects triangle */
t = DOT(trn->edge2, qvec) * inv_det;
add_intersection(t,(object *) trn, ry);
}
static void tri_normal(tri * trn, vector * pnt, ray * incident, vector * N) {
CROSS((*N), trn->edge1, trn->edge2);
VNorm(N);
if (VDot(N, &(incident->d)) > 0.0) {
N->x=-N->x;
N->y=-N->y;
N->z=-N->z;
}
}
static void stri_normal(stri * trn, vector * pnt, ray * incident, vector * N) {
flt U, V, W, lensqr;
vector P, tmp, norm;
CROSS(norm, trn->edge1, trn->edge2);
lensqr = DOT(norm, norm);
VSUB((*pnt), trn->v0, P);
CROSS(tmp, P, trn->edge2);
U = DOT(tmp, norm) / lensqr;
CROSS(tmp, trn->edge1, P);
V = DOT(tmp, norm) / lensqr;
W = 1.0 - (U + V);
N->x = W*trn->n0.x + U*trn->n1.x + V*trn->n2.x;
N->y = W*trn->n0.y + U*trn->n1.y + V*trn->n2.y;
N->z = W*trn->n0.z + U*trn->n1.z + V*trn->n2.z;
VNorm(N);
}

View File

@@ -0,0 +1,90 @@
/*
Copyright (c) 2005-2020 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*
The original source for this example is
Copyright (c) 1994-2008 John E. Stone
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
*/
/*
* triangle.h - This file contains the defines for triangles etc.
*
* $Id: triangle.h,v 1.2 2007-02-22 17:54:16 Exp $
*/
object * newtri(void *, vector, vector, vector);
object * newstri(void *, vector, vector, vector, vector, vector, vector);
#ifdef TRIANGLE_PRIVATE
#define TRIXMAJOR 0
#define TRIYMAJOR 1
#define TRIZMAJOR 2
typedef struct {
unsigned int id; /* Unique Object serial number */
void * nextobj; /* pointer to next object in list */
object_methods * methods; /* this object's methods */
texture * tex; /* object texture */
vector edge2;
vector edge1;
vector v0;
} tri;
typedef struct {
unsigned int id; /* Unique Object serial number */
void * nextobj; /* pointer to next object in list */
object_methods * methods; /* this object's methods */
texture * tex; /* object texture */
vector edge2;
vector edge1;
vector v0;
vector n0;
vector n1;
vector n2;
} stri;
static int tri_bbox(void * obj, vector * min, vector * max);
static void tri_intersect(tri *, ray *);
static void tri_normal(tri *, vector *, ray *, vector *);
static void stri_normal(stri *, vector *, ray *, vector *);
#endif

View File

@@ -0,0 +1,222 @@
/*
Copyright (c) 2005-2020 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*
The original source for this example is
Copyright (c) 1994-2008 John E. Stone
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
*/
#if __MINGW32__
#include <malloc.h>
#elif _WIN32
#include <malloc.h>
#define alloca _alloca
#elif __FreeBSD__||__NetBSD__||__OpenBSD__
#include <stdlib.h>
#else
#include <alloca.h>
#endif
/*
* types.h - This file contains all of the type definitions for the raytracer
*
* $Id: types.h,v 1.2 2007-02-22 17:54:16 Exp $
*/
#define MAXOCTNODES 25 /* subdivide octants /w > # of children */
#define SPEPSILON 0.000001 /* amount to crawl down a ray */
#define EPSILON 0.000001 /* amount to crawl down a ray */
#define TWOPI 6.2831853 /* guess */
#define FHUGE 1e18 /* biggest fp number we can represent */
/* Maximum internal table sizes */
/* Use prime numbers for best memory system performance */
#define INTTBSIZE 1024 /* maximum intersections we can hold */
#define MAXLIGHTS 39 /* maximum number of lights in a scene */
#define MAXIMGS 39 /* maximum number of distinct images */
#define RPCQSIZE 113 /* number of RPC messages to queue */
/* Parameter values for rt_boundmode() */
#define RT_BOUNDING_DISABLED 0 /* spatial subdivision/bounding disabled */
#define RT_BOUNDING_ENABLED 1 /* spatial subdivision/bounding enabled */
/* Parameter values for rt_displaymode() */
#define RT_DISPLAY_DISABLED 0 /* video output enabled */
#define RT_DISPLAY_ENABLED 1 /* video output disabled */
/* Ray flags */
#define RT_RAY_REGULAR 1
#define RT_RAY_SHADOW 2
#define RT_RAY_BOUNDED 4
#define RT_RAY_FINISHED 8
#ifdef USESINGLEFLT
typedef float flt; /* generic floating point number, using float */
#else
typedef double flt; /* generic floating point number, using double */
#endif
typedef unsigned char byte; /* 1 byte */
typedef signed int word; /* 32 bit integer */
typedef struct {
flt x; /* X coordinate value */
flt y; /* Y coordinate value */
flt z; /* Z coordinate value */
} vector;
typedef struct {
flt r; /* Red component */
flt g; /* Green component */
flt b; /* Blue component */
} color;
typedef struct {
byte r; /* Red component */
byte g; /* Green component */
byte b; /* Blue component */
} bytecolor;
typedef struct { /* Raw 24 bit image structure, for tga, ppm etc */
int loaded; /* image memory residence flag */
int xres; /* image X axis size */
int yres; /* image Y axis size */
int bpp; /* image bits per pixel */
char name[96]; /* image filename (with path) */
unsigned char * data; /* pointer to raw byte image data */
} rawimage;
typedef struct { /* Scalar Volume Data */
int loaded; /* Volume data memory residence flag */
int xres; /* volume X axis size */
int yres; /* volume Y axis size */
int zres; /* volume Z axis size */
flt opacity; /* opacity per unit length */
char name[96]; /* Volume data filename */
unsigned char * data; /* pointer to raw byte volume data */
} scalarvol;
typedef struct {
color (* texfunc)(void *, void *, void *);
int shadowcast; /* does the object cast a shadow */
int islight; /* light flag... */
color col; /* base object color */
flt ambient; /* ambient lighting */
flt diffuse; /* diffuse reflection */
flt phong; /* phong specular highlights */
flt phongexp; /* phong exponent/shininess factor */
int phongtype; /* phong type: 0 == plastic, nonzero == metal */
flt specular; /* specular reflection */
flt opacity; /* how opaque the object is */
vector ctr; /* origin of texture */
vector rot; /* rotation of texture about origin */
vector scale; /* scale of texture in x,y,z */
vector uaxs; /* planar map U axis */
vector vaxs; /* planar map V axis */
void * img; /* pointer to image for image mapping */
void * obj; /* object ptr, hack for volume shaders for now */
} texture;
typedef struct {
void (* intersect)(void *, void *); /* intersection func ptr */
void (* normal)(void *, void *, void *, void *); /* normal function ptr */
int (* bbox)(void *, vector *, vector *); /* return the object bbox */
void (* free)(void *); /* free the object */
} object_methods;
typedef struct {
unsigned int id; /* Unique Object serial number */
void * nextobj; /* pointer to next object in list */
object_methods * methods; /* this object's methods */
texture * tex; /* object texture */
} object;
typedef struct {
object * obj; /* to object we hit */
flt t; /* distance along the ray to the hit point */
} intersection;
typedef struct {
int num; /* number of intersections */
intersection closest; /* closest intersection > 0.0 */
intersection list[INTTBSIZE]; /* list of all intersections */
} intersectstruct;
typedef struct {
char outfilename[200]; /* name of the output image */
unsigned char * rawimage; /* pointer to a raw rgb image to be stored */
int hres; /* horizontal output image resolution */
int vres; /* vertical output image resolution */
flt aspectratio; /* aspect ratio of output image */
int raydepth; /* maximum recursion depth */
int antialiasing; /* number of antialiasing rays to fire */
int verbosemode; /* verbose reporting flag */
int boundmode; /* automatic spatial subdivision flag */
int boundthresh; /* threshold number of subobjects */
int displaymode; /* run-time X11 display flag */
vector camcent; /* center of the camera in world coords */
vector camviewvec; /* view direction of the camera (Z axis) */
vector camrightvec; /* right axis for the camera (X axis) */
vector camupvec; /* up axis for the camera (Y axis) */
flt camzoom; /* zoom factor for the camera */
color background; /* scene background color */
} scenedef;
typedef struct {
intersectstruct * intstruct; /* ptr to thread's intersection data */
unsigned int depth; /* levels left to recurse.. (maxdepth - curdepth) */
unsigned int flags; /* ray flags, any special treatment needed etc */
unsigned int serial; /* serial number of the ray */
unsigned int * mbox; /* mailbox array for optimizing intersections */
vector o; /* origin of the ray X,Y,Z */
vector d; /* normalized direction of the ray */
flt maxdist; /* maximum distance to search for intersections */
vector s; /* startpoint of the ray (may differ from origin */
vector e; /* endpoint of the ray if bounded */
scenedef * scene; /* pointer to the scene, for global parms such as */
/* background colors etc */
} ray;
typedef struct {
int type; /* RPC call type */
int from; /* Sending processor */
int len; /* length of parms in bytes */
void * parms; /* Parameters to RPC */
} rpcmsg;

Some files were not shown because too many files have changed in this diff Show More