From 56cc59cf44ec64440ba4d1c0d005196195c758e6 Mon Sep 17 00:00:00 2001 From: hugues Date: Sat, 25 Mar 2006 15:07:51 +0000 Subject: Nettoyage du repository glagen git-svn-id: file:///usr/local/opt/svn/repos/glagen@12 0f7e0d06-a6f9-0310-a55f-d5f984f55e4c --- 3d/Archs.txt | 13 + 3d/FIXME | 13 + 3d/Glagen.dev | 345 +++++++++++++++++++++++++ 3d/Glagen.ico | Bin 0 -> 29766 bytes 3d/Makefile | 139 ++++++++++ 3d/Makefile.mac | 138 ++++++++++ 3d/Makefile.macosx | 133 ++++++++++ 3d/Makefile.windows | 98 +++++++ 3d/data_glagen.hh | 115 +++++++++ 3d/display.cc | 411 +++++++++++++++++++++++++++++ 3d/display.hh | 44 ++++ 3d/dot.cc | 184 +++++++++++++ 3d/dot.hh | 84 ++++++ 3d/dot_gl.cc | 83 ++++++ 3d/end.cc | 53 ++++ 3d/end.hh | 39 +++ 3d/frame.cc | 152 +++++++++++ 3d/frame.hh | 69 +++++ 3d/header.cc | 28 ++ 3d/isosahedron.cc | 220 ++++++++++++++++ 3d/isosahedron.hh | 38 +++ 3d/library.cc | 100 +++++++ 3d/library.hh | 40 +++ 3d/main.cc | 132 ++++++++++ 3d/matrix3d.cc | 216 ++++++++++++++++ 3d/matrix3d.hh | 80 ++++++ 3d/misc.cc | 43 ++++ 3d/misc.hh | 38 +++ 3d/perlin.cc | 347 +++++++++++++++++++++++++ 3d/perlin.hh | 39 +++ 3d/simul.cc | 409 +++++++++++++++++++++++++++++ 3d/simul.hh | 41 +++ 3d/time.hh | 36 +++ 3d/time_unix.cc | 51 ++++ 3d/time_windows.cc | 53 ++++ 3d/triangle.cc | 729 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 3d/triangle.hh | 122 +++++++++ 3d/triangle_gl.cc | 180 +++++++++++++ 3d/vector.cc | 252 ++++++++++++++++++ 3d/vector.hh | 77 ++++++ 40 files changed, 5384 insertions(+) create mode 100644 3d/Archs.txt create mode 100644 3d/FIXME create mode 100644 3d/Glagen.dev create mode 100644 3d/Glagen.ico create mode 100644 3d/Makefile create mode 100644 3d/Makefile.mac create mode 100644 3d/Makefile.macosx create mode 100644 3d/Makefile.windows create mode 100644 3d/data_glagen.hh create mode 100644 3d/display.cc create mode 100644 3d/display.hh create mode 100644 3d/dot.cc create mode 100644 3d/dot.hh create mode 100644 3d/dot_gl.cc create mode 100644 3d/end.cc create mode 100644 3d/end.hh create mode 100644 3d/frame.cc create mode 100644 3d/frame.hh create mode 100644 3d/header.cc create mode 100644 3d/isosahedron.cc create mode 100644 3d/isosahedron.hh create mode 100644 3d/library.cc create mode 100644 3d/library.hh create mode 100644 3d/main.cc create mode 100644 3d/matrix3d.cc create mode 100644 3d/matrix3d.hh create mode 100644 3d/misc.cc create mode 100644 3d/misc.hh create mode 100644 3d/perlin.cc create mode 100644 3d/perlin.hh create mode 100644 3d/simul.cc create mode 100644 3d/simul.hh create mode 100644 3d/time.hh create mode 100644 3d/time_unix.cc create mode 100644 3d/time_windows.cc create mode 100644 3d/triangle.cc create mode 100644 3d/triangle.hh create mode 100644 3d/triangle_gl.cc create mode 100644 3d/vector.cc create mode 100644 3d/vector.hh (limited to '3d') diff --git a/3d/Archs.txt b/3d/Archs.txt new file mode 100644 index 0000000..a39618d --- /dev/null +++ b/3d/Archs.txt @@ -0,0 +1,13 @@ + +The Glagen's 3D engine ha been ported on: + + * GNU/Linux (Debian, Mandrake); + * MacOS X; + * FreeBSD, NetBSD and OpenBSD; + * Microsoft Windows. + +To do : + + * Test on other GNU/Linux distributions (Redhat, Slackware at least); + * Test on GNU/Hurd, if possible; + * Maybe on Solaris. diff --git a/3d/FIXME b/3d/FIXME new file mode 100644 index 0000000..6a57b48 --- /dev/null +++ b/3d/FIXME @@ -0,0 +1,13 @@ +To fix : + + * Find a fast distace approximation. + + * The light! + + * Add 2D graphics (Head Up Display, fonts...). + + * Bug when near the ground; + + * Try different noise; + + * Increase definatly the precision depth. diff --git a/3d/Glagen.dev b/3d/Glagen.dev new file mode 100644 index 0000000..6dc18da --- /dev/null +++ b/3d/Glagen.dev @@ -0,0 +1,345 @@ +[Project] +FileName=Glagen.dev +Name=Glagen +UnitCount=20 +Type=0 +Ver=1 +ObjFiles= +Includes= +Libs= +PrivateResource=Glagen_private.rc +ResourceIncludes= +MakeIncludes= +Compiler= +CppCompiler=_@@_ +Linker=-lopengl32 -lglu32 -lglut32_@@_ +IsCpp=1 +Icon=Glagen.ico +ExeOutput= +ObjectOutput= +OverrideOutput=1 +OverrideOutputName=Glagen.exe +HostApplication= +Folders=Classes,Implementation +CommandLine= +IncludeVersionInfo=1 +SupportXPThemes=0 +CompilerSet=0 +CompilerSettings=000000000100100000 + +[Unit1] +FileName=display.cc +CompileCpp=1 +Folder=Implementation +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit2] +FileName=dot.cc +CompileCpp=1 +Folder=Implementation +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit3] +FileName=dot_gl.cc +CompileCpp=1 +Folder=Implementation +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit4] +FileName=end.cc +CompileCpp=1 +Folder=Implementation +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit5] +FileName=frame.cc +CompileCpp=1 +Folder=Implementation +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit6] +FileName=isosahedron.cc +CompileCpp=1 +Folder=Implementation +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit7] +FileName=library.cc +CompileCpp=1 +Folder=Implementation +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit8] +FileName=main.cc +CompileCpp=1 +Folder=Implementation +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit9] +FileName=matrix3d.cc +CompileCpp=1 +Folder=Implementation +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit10] +FileName=misc.cc +CompileCpp=1 +Folder=Implementation +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit11] +FileName=perlin.cc +CompileCpp=1 +Folder=Implementation +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit12] +FileName=simul.cc +CompileCpp=1 +Folder=Implementation +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit13] +FileName=triangle.cc +CompileCpp=1 +Folder=Implementation +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit14] +FileName=triangle_gl.cc +CompileCpp=1 +Folder=Implementation +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit15] +FileName=vector.cc +CompileCpp=1 +Folder=Implementation +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit16] +FileName=data_glagen.hh +CompileCpp=1 +Folder=Classes +Compile=0 +Link=0 +Priority=1000 +OverrideBuildCmd=1 +BuildCmd= + +[Unit17] +FileName=display.hh +CompileCpp=1 +Folder=Classes +Compile=0 +Link=0 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit18] +FileName=dot.hh +Folder=Classes +Compile=0 +Link=0 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit19] +FileName=end.hh +Folder=Classes +Compile=0 +Link=0 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit20] +FileName=frame.hh +Folder=Classes +Compile=0 +Link=0 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit21] +FileName=isosahedron.hh +Folder=Classes +Compile=0 +Link=0 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit22] +FileName=library.hh +Folder=Classes +Compile=0 +Link=0 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit23] +FileName=matrix3d.hh +Folder=Classes +Compile=0 +Link=0 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit24] +FileName=misc.hh +Folder=Classes +Compile=0 +Link=0 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit25] +FileName=perlin.hh +Folder=Classes +Compile=0 +Link=0 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit26] +FileName=simul.hh +Folder=Classes +Compile=0 +Link=0 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit27] +FileName=triangle.hh +Folder=Classes +Compile=0 +Link=0 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit28] +FileName=vector.hh +Folder=Classes +Compile=0 +Link=0 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit29] +FileName=time.hh +Folder=Classes +Compile=0 +Link=0 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit30] +FileName=time_windows.cc +Folder=Implementation +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= +CompileCpp=1 + +[Unit31] +FileName=time_windows.cc +CompileCpp=1 +Folder=Implementation +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[VersionInfo] +Major=0 +Minor=0 +Release=9 +Build=0 +LanguageID=1033 +CharsetID=1252 +CompanyName=www.glagen.org +FileVersion=0.0.9.0 +FileDescription=GPL Landscape Generator +InternalName=glagen.exe +LegalCopyright=Copyright 2003, www.glagen.org +LegalTrademarks= +OriginalFilename=glagen.exe +ProductName=Glagen +ProductVersion=Alpha 0.0.9.0 +AutoIncBuildNr=0 + diff --git a/3d/Glagen.ico b/3d/Glagen.ico new file mode 100644 index 0000000..acb0589 Binary files /dev/null and b/3d/Glagen.ico differ diff --git a/3d/Makefile b/3d/Makefile new file mode 100644 index 0000000..a7d46b5 --- /dev/null +++ b/3d/Makefile @@ -0,0 +1,139 @@ +##============================================================================= +## +## Glagen : a planet sized landscape generator +## Copyright (C) 2002 Julien Guertault, Hugues Hiegel, Meng-Tih Lam +## +## This program is free software; you can redistribute it and/or +## modify it under the terms of the GNU General Public License +## as published by the Free Software Foundation; either version 2 +## of the License, or (at your option) any later version. +## +## This program is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## GNU General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with this program; if not, write to the Free Software +## Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +## +##============================================================================= +## +## Glagen : GPL LAndscape GENerator +## +## Makefile for Glagen : made by Zavie (Julien Guertault) +## +## www.glagen.org +## +##============================================================================= + +NAME = glagen + +DIRECTORY = 3d + +ARCHIVE = tar -cvzf + +CC = g++ + +ECHO = @echo + +RM = rm -f + +SRC = main.cc \ + display.cc \ + dot.cc \ + dot_gl.cc \ + end.cc \ + frame.cc \ + isosahedron.cc \ + library.cc \ + matrix3d.cc \ + misc.cc \ + perlin.cc \ + simul.cc \ + time_unix.cc \ + triangle.cc \ + triangle_gl.cc \ + vector.cc + +DEBUG_FLAGS = -ggdb3 + +OPTIM_FLAGS = -O3 \ + -ffast-math \ + -funroll-loops \ + -felide-constructors \ + -fexpensive-optimizations \ + -finline-functions + +WARNING_FLAGS = -Wall \ + -W \ + -Wstrict-prototypes + +CFLAGS = $(DEBUG_FLAGS) \ + $(WARNING_FLAGS) + +# CFLAGS = $(OPTIM_FLAGS) \ +# $(WARNING_FLAGS) + +# CFLAGS = $(DEBUG_FLAGS) \ +# $(OPTIM_FLAGS) \ +# $(WARNING_FLAGS) + +#GTK_IFLAGS = `gtk-config --cflags` + +OPENGL_IFLAGS = -I/usr/include \ + -I/usr/include/GL \ + -I/usr/X11R6/include \ + -I/usr/X11R6/include/GL + +IFLAGS = $(OPENGL_IFLAGS) + +#GTK_LFLAGS = `gtk-config --libs` + +OPENGL_LFLAGS = -L/usr/X11R6/lib \ + -lX11 \ + -lGL \ + -lGLU \ + -lglut + +LFLAGS = -L/usr/lib \ + -L/usr/pkg/lib \ + -lc \ + -lm \ + $(OPENGL_LFLAGS) + +OBJ = $(SRC:.cc=.o) + +all : $(NAME) + +$(NAME) : $(OBJ) + $(CC) $(OBJ) $(LFLAGS) -o $(NAME) + +.cc.o : + $(CC) $(CFLAGS) $(IFLAGS) $< -c -o $@ + +clean : + $(RM) $(OBJ) + $(RM) *~ \#*\# + +distclean : clean + $(RM) $(NAME) + +separator : + $(ECHO) "------------------------------------------" + +re : clean all + +run : all + ./$(NAME) + +tarball : distclean separator + $(ECHO) "Archiving..." + cd .. && $(ARCHIVE) $(NAME).tar.gz $(DIRECTORY) + $(ECHO) "Done !" + +install : + $(ECHO) "Not implemented yet." + +love : + $(ECHO) "Sorry, I have a headache..." diff --git a/3d/Makefile.mac b/3d/Makefile.mac new file mode 100644 index 0000000..7e4d5d9 --- /dev/null +++ b/3d/Makefile.mac @@ -0,0 +1,138 @@ +##============================================================================= +## +## Glagen : a planet sized landscape generator +## Copyright (C) 2002 Julien Guertault, Hugues Hiegel, Meng-Tih Lam +## +## This program is free software; you can redistribute it and/or +## modify it under the terms of the GNU General Public License +## as published by the Free Software Foundation; either version 2 +## of the License, or (at your option) any later version. +## +## This program is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## GNU General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with this program; if not, write to the Free Software +## Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +## +##============================================================================= +## +## Glagen : GPL LAndscape GENerator +## +## Makefile.mac for Glagen : made by Zavie (Julien Guertault) +## +## www.glagen.org +## +##============================================================================= + +NAME = glagen + +DIRECTORY = 3d + +ARCHIVE = tar -cvzf + +CC = g++ + +ECHO = @echo + +RM = rm -f + +SRC = main.cc \ + display.cc \ + dot.cc \ + dot_gl.cc \ + end.cc \ + frame.cc \ + isosahedron.cc \ + library.cc \ + matrix3d.cc \ + misc.cc \ + perlin.cc \ + simul.cc \ + time_unix.cc \ + triangle.cc \ + triangle_gl.cc \ + vector.cc + +OPTIM_FLAGS = -O3 \ + -ffast-math \ + -funroll-loops \ + -felide-constructors \ + -fexpensive-optimizations \ + -finline-functions + +WARNING_FLAGS = -Wall \ + -W \ + -Wstrict-prototypes + +CFLAGS = $(DEBUG_FLAGS) \ + $(WARNING_FLAGS) \ + -DDARWIN + +# CFLAGS = $(OPTIM_FLAGS) \ +# $(WARNING_FLAGS) \ +# -DDARWIN + +# CFLAGS = $(DEBUG_FLAGS) \ +# $(OPTIM_FLAGS) \ +# $(WARNING_FLAGS) \ +# -DDARWIN + +# Sorry for that... +# I'll try to do something better soon. + +#GTK_IFLAGS = `gtk-config --cflags` + +OPENGL_IFLAGS = -I/usr/X11R6/include \ + -I/System/Library/Frameworks/OpenGL.framework/Versions/A/Headers \ + -I/System/Library/Frameworks/GLUT.framework/Versions/A/Headers + +IFLAGS = -I/usr/include \ + $(OPENGL_IFLAGS) + +#GTK_LFLAGS = `gtk-config --libs` + +OPENGL_LFLAGS = -L/usr/X11R6/lib \ + -L/sw/lib \ + -lX11 \ + -lGL \ + -lGLU \ + -lglut + +LFLAGS = -L/usr/lib \ + -L/usr/pkg/lib \ + -lc \ + -lm \ + $(OPENGL_LFLAGS) + +OBJ = $(SRC:.cc=.o) + +all : $(NAME) + +$(NAME) : $(OBJ) + $(CC) $(OBJ) $(LFLAGS) -o $(NAME) + +.cc.o : + $(CC) $(CFLAGS) $(IFLAGS) $< -c -o $@ + +clean : + $(RM) $(OBJ) + $(RM) *~ \#*\# + +distclean : clean + $(RM) $(NAME) + +separator : + $(ECHO) "------------------------------------------" + +re : clean all + +tarball : distclean separator + $(ECHO) "Archiving..." + cd .. && $(ARCHIVE) $(NAME).tar.gz $(DIRECTORY) + $(ECHO) "Done !" + +love : + $(ECHO) "Sorry, I have a headache..." diff --git a/3d/Makefile.macosx b/3d/Makefile.macosx new file mode 100644 index 0000000..37b8e5b --- /dev/null +++ b/3d/Makefile.macosx @@ -0,0 +1,133 @@ +##============================================================================= +## +## Glagen : a planet sized landscape generator +## Copyright (C) 2002 Julien Guertault, Hugues Hiegel, Meng-Tih Lam +## +## This program is free software; you can redistribute it and/or +## modify it under the terms of the GNU General Public License +## as published by the Free Software Foundation; either version 2 +## of the License, or (at your option) any later version. +## +## This program is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## GNU General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with this program; if not, write to the Free Software +## Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +## +##============================================================================= +## +## Glagen : GPL LAndscape GENerator +## +## Makefile.mac for Glagen : made by Zavie (Julien Guertault) +## +## www.glagen.org +## +##============================================================================= + +NAME = glagen + +DIRECTORY = 3d + +ARCHIVE = tar -cvzf + +CC = g++ + +ECHO = @echo + +RM = rm -f + +SRC = main.cc \ + display.cc \ + dot.cc \ + dot_gl.cc \ + end.cc \ + frame.cc \ + isosahedron.cc \ + library.cc \ + matrix3d.cc \ + perlin.cc \ + simul.cc \ + triangle.cc \ + triangle_gl.cc \ + vector.cc + +OPTIM_FLAGS = -O3 \ + -ffast-math \ + -funroll-loops \ + -felide-constructors \ + -fexpensive-optimizations \ + -finline-functions + +WARNING_FLAGS = -Wall \ + -W \ + -Wstrict-prototypes + +CFLAGS = $(DEBUG_FLAGS) \ + $(WARNING_FLAGS) \ + -DDARWIN + +# CFLAGS = $(OPTIM_FLAGS) \ +# $(WARNING_FLAGS) \ +# -DDARWIN + +# CFLAGS = $(DEBUG_FLAGS) \ +# $(OPTIM_FLAGS) \ +# $(WARNING_FLAGS) \ +# -DDARWIN + +# Sorry for that... +# I'll try to do something better soon. + +#GTK_IFLAGS = `gtk-config --cflags` + +OPENGL_IFLAGS = -I/usr/X11R6/include \ + -I/System/Library/Frameworks/OpenGL.framework/Versions/A/Headers \ + -I/System/Library/Frameworks/GLUT.framework/Versions/A/Headers + +IFLAGS = -I/usr/include \ + $(OPENGL_IFLAGS) + +#GTK_LFLAGS = `gtk-config --libs` + +OPENGL_LFLAGS = -L/usr/X11R6/lib \ + -L/sw/lib \ + -lX11 \ + -lGL \ + -lGLU \ + -lglut + +LFLAGS = -L/usr/lib \ + -L/usr/pkg/lib \ + -lc \ + -lm \ + $(OPENGL_LFLAGS) + +OBJ = $(SRC:.cc=.o) + +all : $(NAME) + +$(NAME) : $(OBJ) + $(CC) $(OBJ) $(LFLAGS) -o $(NAME) + +.cc.o : + $(CC) $(CFLAGS) $(IFLAGS) $< -c -o $@ + +clean : + $(RM) $(OBJ) + $(RM) *~ \#*\# + +distclean : clean + $(RM) $(NAME) + +re : clean all + +tarball : distclean + $(ECHO) "Archiving..." + cd .. && $(ARCHIVE) $(NAME).tar.gz $(DIRECTORY) + $(ECHO) "Done !" + +love : + $(ECHO) "Sorry, I have a headache..." diff --git a/3d/Makefile.windows b/3d/Makefile.windows new file mode 100644 index 0000000..1a9a741 --- /dev/null +++ b/3d/Makefile.windows @@ -0,0 +1,98 @@ +##============================================================================= +## +## Glagen : a planet sized landscape generator +## Copyright (C) 2002 Julien Guertault, Hugues Hiegel, Meng-Tih Lam +## +## This program is free software; you can redistribute it and/or +## modify it under the terms of the GNU General Public License +## as published by the Free Software Foundation; either version 2 +## of the License, or (at your option) any later version. +## +## This program is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## GNU General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with this program; if not, write to the Free Software +## Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +## +##============================================================================= +## +## Glagen : GPL LAndscape GENerator +## +## Makefile.win for Glagen : made by Zavie (Julien Guertault) +## +## www.glagen.org +## +##============================================================================= + +# Note : Makefile.win is overwritten by Dev-C++ when compiling + +NAME = glagen.exe + +CC = g++.exe + +WINDRES = windres.exe + +DEVCPP = # Put here the directory of the compiler : "C:/Dev-Cpp" + +SRC = main.cc \ + display.cc \ + dot.cc \ + dot_gl.cc \ + end.cc \ + frame.cc \ + isosahedron.cc \ + library.cc \ + matrix3d.cc \ + misc.cc \ + perlin.cc \ + simul.cc \ + time_unix.cc \ + triangle.cc \ + triangle_gl.cc \ + vector.cc + +RC = Glagen_private.rc + +RES = Glagen_private.res + +OPTIM_FLAGS = -fexpensive-optimizations -O3 + +IFLAGS = -I"$(DEVCPP)/include" \ + -I"$(DEVCPP)/include/c++" \ + -I"$(DEVCPP)/include/c++/mingw32" \ + -I"$(DEVCPP)/include/c++/backward" + +CFLAGS = $(OPTIM_FLAGS) \ + -DWINDOWS + +LFLAGS = -L"$(DEVCPP)/lib" \ + -mwindows \ + -lopengl32 \ + -lglu32 \ + -lglut32 + +OBJ = $(SRC:.cc=.o) + + +all: all-before $(NAME) all-after + +$(NAME): $(OBJ) + $(CPP) $(OBJ) -o $(NAME) $(LIBS) + +.cc.o : + $(CC) $(CFLAGS) $(IFLAGS) $< -c -o $@ + +$(RES): $(RC) + $(WINDRES) -i $(RC) -I rc -o $(RES) -O coff + +clean : + $(RM) $(OBJ) + $(RM) *~ \#*\# + +distclean : clean + $(RM) $(NAME) + +re : clean all diff --git a/3d/data_glagen.hh b/3d/data_glagen.hh new file mode 100644 index 0000000..e02332b --- /dev/null +++ b/3d/data_glagen.hh @@ -0,0 +1,115 @@ +//============================================================================= +// +// Glagen : a planet sized landscape generator +// Copyright (C) 2002 Julien Guertault, Hugues Hiegel, Meng-Tih Lam +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// +//============================================================================= +// +// Glagen : GPL LAndscape GENerator +// +// data_glagen.hh for Glagen : made by Zavie (Julien Guertault) +// +// www.glagen.org +// +//============================================================================= + +#ifndef DATA_GLAGEN_HH_ +# define DATA_GLAGEN_HH_ + +#ifdef DARWIN +# define float double +# define sqrtf sqrt +# define sinf sin +# define cosf cos +#endif + +#include +#include +#include "frame.hh" + +typedef struct +{ + class Frame frame; + float speed; + float altitude; +} observer_t; + +typedef enum + { + none, + surface, + object, + non_material, + other + } kind_lib_t; + +typedef struct +{ + kind_lib_t kind; + size_t size; + void *data; +} property_t; + +typedef struct +{ + kind_lib_t kind; + bool dynamic; + void (*run)(class Dot *, unsigned int); + char *name; +} library_t; + +typedef struct +{ + observer_t observer; + struct timeval time; + long start_time; + float float_time; + char step; + float size; + float square_size; + class Triangle *ref; + class Triangle *current; + int property; + library_t library[5]; + float split_dist_limit; + float split_norm_limit; + unsigned int triangles; + unsigned int max_triangles; + bool display_normal; + bool display_planet; + bool display_all; + bool third_view; + bool zoom; + bool light; + int mode; + int depth_test; + int x; + int y; +} glagen_t; + +extern glagen_t glagen; + +typedef struct +{ + float height; + float red; + float green; + float blue; + float alpha; +} surface_t; + +#endif // DATA_GLAGEN_HH_ diff --git a/3d/display.cc b/3d/display.cc new file mode 100644 index 0000000..a956274 --- /dev/null +++ b/3d/display.cc @@ -0,0 +1,411 @@ +//============================================================================= +// +// Glagen : a planet sized landscape generator +// Copyright (C) 2002 Julien Guertault, Hugues Hiegel, Meng-Tih Lam +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// +//============================================================================= +// +// Glagen : GPL LAndscape GENerator +// +// display.cc for Glagen : made by Zavie (Julien Guertault) +// +// www.glagen.org +// +//============================================================================= + +#include +#include +#include + +#ifndef DARWIN +# include +# include +# include +#else +# include +# include +# include +#endif + +#include "data_glagen.hh" +#include "end.hh" +#include "library.hh" +#include "time.hh" +#include "triangle.hh" + +bool pressed; +int x; +int y; +int xold; +int yold; + +static const GLfloat L0position[] = { 0.0, 1.0, -2.0, 0.0 }; +static const GLfloat L0ambient[] = { 0.0, 0.0, 0.0, 1.0 }; +static const GLfloat L0diffuse[] = { 1.0, 1.0, 1.0, 1.0 }; +static const GLfloat L0specular[] = { 1.0, 1.0, 1.0, 1.0 }; +static const GLfloat Mshiny = 50; + +void display_frame () +{ + Frame *o = &glagen.observer.frame; + + update_time (); + + glagen.step = glagen.step + 1; + if (glagen.display_planet == true) + library_caller (glagen.ref); + glagen.step = glagen.step + 1; + glagen.ref->Update_normal_visitor (); + glagen.step = glagen.step + 1; + + glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + glLoadIdentity (); + + // Third person view : the observer is represented by a frame + if (glagen.third_view == true) + { + // View initialization in third person view mode + gluPerspective(45, + float(glagen.x) / float(glagen.y), + 0.5, + 8.0); + gluLookAt (-4, 4, -4, + 1, -1, 1, + 0, 1, 0); + + // The frame representing the user's position + if (glagen.light == true) + glDisable(GL_LIGHTING); + glBegin (GL_LINES); + glColor3f(1.0, 1.0, 0.0); + glVertex3f(o->Origin_X (), o->Origin_Y (), o->Origin_Z ()); + glVertex3f(o->Origin_X () + o->Basis_X ().X () / 2, + o->Origin_Y () + o->Basis_X ().Y () / 2, + o->Origin_Z () + o->Basis_X ().Z () / 2); + glColor3f(0.0, 1.0, 1.0); + glVertex3f(o->Origin_X (), o->Origin_Y (), o->Origin_Z ()); + glVertex3f(o->Origin_X () + o->Basis_Y ().X () / 2, + o->Origin_Y () + o->Basis_Y ().Y () / 2, + o->Origin_Z () + o->Basis_Y ().Z () / 2); + glColor3f(1.0, 0.0, 1.0); + glVertex3f(o->Origin_X (), o->Origin_Y (), o->Origin_Z ()); + glVertex3f(o->Origin_X () + o->Basis_Z ().X () / 2, + o->Origin_Y () + o->Basis_Z ().Y () / 2, + o->Origin_Z () + o->Basis_Z ().Z () / 2); + + // Then the projection of the user's position on the planet's frame + glColor3f(1.0, 1.0, 1.0); + glVertex3f(0, 0, 0); + glVertex3f(o->Origin_X (), o->Origin_Y (), o->Origin_Z ()); + + glColor3f(1.0, 0.0, 0.0); + glVertex3f(0, 0, 0); + glVertex3f(o->Origin_X (), 0, 0); + + glColor3f(0.0, 1.0, 0.0); + glVertex3f(o->Origin_X (), 0, 0); + glVertex3f(o->Origin_X (), o->Origin_Y (), 0); + + glColor3f(0.0, 0.0, 1.0); + glVertex3f(o->Origin_X (), o->Origin_Y (), 0); + glVertex3f(o->Origin_X (), o->Origin_Y (), o->Origin_Z ()); + + glEnd (); + if (glagen.light == true) + glEnable(GL_LIGHTING); + } + else + { + // View initialization in normal view + if (glagen.x > glagen.y) + gluPerspective(45 * float(glagen.y) / float(glagen.x), + float(glagen.x) / float(glagen.y), + glagen.observer.altitude / 2, + glagen.observer.altitude + 1); + else + gluPerspective(45, + float(glagen.x) / float(glagen.y), + glagen.observer.altitude / 2, + glagen.observer.altitude + 1); + gluLookAt (o->Origin_X (), o->Origin_Y (), o->Origin_Z (), + o->Origin_X () + o->Basis_Z ().X (), + o->Origin_Y () + o->Basis_Z ().Y (), + o->Origin_Z () + o->Basis_Z ().Z (), + o->Basis_Y ().X (), o->Basis_Y ().Y (), o->Basis_Y (). Z ()); + } + + + // The light + if (glagen.light == true) + { + glLightfv(GL_LIGHT0, GL_POSITION, L0position); + glEnable(GL_LIGHTING); + } + + // The line calling the planet's display is just here + glagen.ref->Display (0); + glagen.step = glagen.step + 1; + + if (glagen.light == true) + glDisable (GL_LIGHTING); + +// // Uncomment those lines for an atmosphere === + glEnable (GL_BLEND); + glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); +// for (int current = 1; current < 100; current ++) +// { +// glagen.ref->Display (current); +// glagen.step = glagen.step + 1; +// } +// glDisable (GL_BLEND); +// // + + glFlush (); + + // On echange les buffers + glutSwapBuffers (); + glutPostRedisplay(); +} + +// +// Simple keyboard events catching +// +void Keyboard (unsigned char key_stroke, int, int) +{ + switch (key_stroke) + { + // Quit + case 'q': + case 'Q': + case 27: + end_all(); + } +} + +// +// Other keyboard events catching +// +void Keyboard_Special (int key_stroke, int, int) +{ + Frame *o = &glagen.observer.frame; + float ox = o->Origin_X (); + float oy = o->Origin_Y (); + float oz = o->Origin_Z (); + + switch (key_stroke) + { + case GLUT_KEY_UP: + o->Translate (o->Basis_Z () * glagen.observer.speed); + glagen.observer.speed = glagen.observer.altitude / 50; + glagen.observer.altitude = sqrtf (ox * ox + oy * oy + oz * oz) - 1; + if (glagen.zoom) + glagen.ref->Split_visitor (); + glagen.step = glagen.step + 1; + glagen.ref->Hide_visitor (); + glagen.step = glagen.step + 1; + break; + case GLUT_KEY_DOWN: + o->Translate (o->Basis_Z () * -glagen.observer.speed); + glagen.observer.speed = glagen.observer.altitude / 50; + glagen.observer.altitude = sqrtf (ox * ox + oy * oy + oz * oz) - 1; + if (glagen.zoom) + glagen.ref->Split_visitor (); + glagen.step = glagen.step + 1; + glagen.ref->Hide_visitor (); + glagen.step = glagen.step + 1; + break; + case GLUT_KEY_LEFT: + o->Translate (o->Basis_X () * glagen.observer.speed); + glagen.observer.speed = glagen.observer.altitude / 50; + glagen.observer.altitude = sqrtf (ox * ox + oy * oy + oz * oz) - 1; + if (glagen.zoom) + glagen.ref->Split_visitor (); + glagen.step = glagen.step + 1; + glagen.ref->Hide_visitor (); + glagen.step = glagen.step + 1; + break; + case GLUT_KEY_RIGHT: + o->Translate (o->Basis_X () * -glagen.observer.speed); + glagen.observer.speed = glagen.observer.altitude / 50; + glagen.observer.altitude = sqrtf (ox * ox + oy * oy + oz * oz) - 1; + if (glagen.zoom) + glagen.ref->Split_visitor (); + glagen.step = glagen.step + 1; + glagen.ref->Hide_visitor (); + glagen.step = glagen.step + 1; + break; + case GLUT_KEY_PAGE_UP: + o->Translate (o->Basis_Y () * glagen.observer.speed); + glagen.observer.speed = glagen.observer.altitude / 50; + glagen.observer.altitude = sqrtf (ox * ox + oy * oy + oz * oz) - 1; + if (glagen.zoom) + glagen.ref->Split_visitor (); + glagen.step = glagen.step + 1; + glagen.ref->Hide_visitor (); + glagen.step = glagen.step + 1; + break; + case GLUT_KEY_PAGE_DOWN: + o->Translate (o->Basis_Y () * -glagen.observer.speed); + glagen.observer.speed = glagen.observer.altitude / 50; + glagen.observer.altitude = sqrtf (ox * ox + oy * oy + oz * oz) - 1; + if (glagen.zoom) + glagen.ref->Split_visitor (); + glagen.step = glagen.step + 1; + glagen.ref->Hide_visitor (); + glagen.step = glagen.step + 1; + break; + case GLUT_KEY_F1: + if (glagen.mode == 1) + glPolygonMode (GL_FRONT_AND_BACK, GL_LINE); + else + { + if (glagen.mode == 2) + glPolygonMode (GL_FRONT_AND_BACK, GL_POINT); + else + glPolygonMode (GL_FRONT_AND_BACK, GL_FILL); + } + glagen.mode++; + if (glagen.mode > 3) + glagen.mode = 1; + glutPostRedisplay (); + break; + case GLUT_KEY_F2: + glagen.depth_test = !glagen.depth_test; + if (glagen.depth_test == true) + glEnable (GL_DEPTH_TEST); + else + glDisable (GL_DEPTH_TEST); + glutPostRedisplay (); + break; + case GLUT_KEY_F3: + glagen.display_normal = !glagen.display_normal; + break; + case GLUT_KEY_F4: + glagen.display_planet = !glagen.display_planet; + break; + case GLUT_KEY_F5: + glagen.display_all = !glagen.display_all; + break; + case GLUT_KEY_F6: + glagen.third_view = !glagen.third_view; + break; + case GLUT_KEY_F7: + glagen.light = !glagen.light; + break; + } +// { +// float alt = glagen.observer.altitude * 12000000; +// if (alt > 1000) +// printf ("%.3f km\n", alt / 1000); +// else +// printf ("%.3f m\n", alt); +// } +} + +void reshape (int x, int y) +{ + glagen.x = x; + glagen.y = y; + glViewport (0, 0, x, y); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glMatrixMode(GL_MODELVIEW); +} + +void mouse(int button, int state, int x, int y) +{ + // sleft button pressed + if (button == GLUT_LEFT_BUTTON && state == GLUT_DOWN) + pressed = true; + // left button released + if (button == GLUT_LEFT_BUTTON && state == GLUT_UP) + { + pressed = false; + if (glagen.zoom) + glagen.ref->Split_visitor (); + glagen.step = glagen.step + 1; + glagen.ref->Hide_visitor (); + glagen.step = glagen.step + 1; + } + xold = x; // saving position + yold = y; +} + +void mousemotion(int x, int y) +{ + float angle[3]; + + if (pressed) // left button + { + angle[0] = (y - yold) / 100.0; + angle[1] = (xold - x) / 100.0; + angle[2] = 0; + } + else + { + angle[0] = 0; + angle[1] = 0; + angle[2] = (xold - x) / 50.0; + } + + glagen.observer.frame.Rotate (angle[0], glagen.observer.frame.Basis_X ()); + glagen.observer.frame.Rotate (angle[1], glagen.observer.frame.Basis_Y ()); + glagen.observer.frame.Rotate (angle[2], glagen.observer.frame.Basis_Z ()); + glagen.ref->Hide_visitor (); + glagen.step = glagen.step + 1; + glutPostRedisplay (); + xold = x; + yold = y; +} + +void display(int *narg, char ***args) +{ + // Glut + glutInit (narg, *args); + glutInitDisplayMode (GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH); + glutInitWindowSize (600, 600); + glutCreateWindow ("Test Glagen"); + + // OpenGL + glClearColor (0.0, 0.0, 0.0, 0.0); + glColor3f (1.0, 1.0, 1.0); + glEnable (GL_DEPTH_TEST); + glagen.mode = 1; + glPolygonMode (GL_FRONT_AND_BACK, GL_FILL); + + // Light + glLightModeli (GL_LIGHT_MODEL_LOCAL_VIEWER, GL_TRUE); + glEnable (GL_LIGHTING); + glEnable (GL_LIGHT0); + glLightfv (GL_LIGHT0, GL_DIFFUSE, L0diffuse); + glLightfv (GL_LIGHT0, GL_SPECULAR, L0specular); + glLightfv (GL_LIGHT0, GL_AMBIENT, L0ambient); + glEnable (GL_COLOR_MATERIAL); + glDisable (GL_LIGHTING); + + // Events functions + glutDisplayFunc (display_frame); + glutKeyboardFunc (Keyboard); + glutSpecialFunc (Keyboard_Special); + glutReshapeFunc (reshape); + glutMouseFunc (mouse); + glutMotionFunc (mousemotion); + + // Glut main loop ;-) + glutMainLoop (); + return; +} diff --git a/3d/display.hh b/3d/display.hh new file mode 100644 index 0000000..da18a8f --- /dev/null +++ b/3d/display.hh @@ -0,0 +1,44 @@ +//============================================================================= +// +// Glagen : a planet sized landscape generator +// Copyright (C) 2002 Julien Guertault, Hugues Hiegel, Meng-Tih Lam +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// +//============================================================================= +// +// Glagen : GPL LAndscape GENerator +// +// display.hh for Glagen : made by Zavie (Julien Guertault) +// +// www.glagen.org +// +//============================================================================= + +#ifndef DISPLAY_HH_ +# define DISPLAY_HH_ + +#include "dot.hh" +#include "triangle.hh" + +void display_frame (); +void Keyboard (unsigned char, int, int); +void Keyboard_Special (int, int, int); +void reshape (int, int); +void mouse (int, int, int, int); +void mousemotion (int, int); +void display (int *, char ***); + +#endif // DISPLAY_HH_ diff --git a/3d/dot.cc b/3d/dot.cc new file mode 100644 index 0000000..86df62b --- /dev/null +++ b/3d/dot.cc @@ -0,0 +1,184 @@ +//============================================================================= +// +// Glagen : a planet sized landscape generator +// Copyright (C) 2002 Julien Guertault, Hugues Hiegel, Meng-Tih Lam +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// +//============================================================================= +// +// Glagen : GPL LAndscape GENerator +// +// dot.cc for Glagen : made by Zavie (Julien Guertault) +// +// www.glagen.org +// +//============================================================================= + +#include +#include +#include "data_glagen.hh" +#include "dot.hh" + +// Constructor and destructor +Dot :: Dot (const float x, const float y, const float z): + _x(x), _y(y), _z(z), _use(0), _computed(false) +{ + _normal = Vector (0, 0, 0); + _property = new property_t *[glagen.property]; // delete : dot.cc l61 + for (int current = 0; current < glagen.property; current++) + _property[current] = NULL; + for (int current = 0; current < 6; current++) + _owner[current] = NULL; + step = glagen.step; +} + +Dot :: ~Dot () +{ + if (_property != NULL) + { + for (int current = 0; current < glagen.property; current++) + if (_property[current] != NULL) + { + if (_property[current]->data != NULL) + delete _property[current]->data; // FIXME : warning here. + delete _property[current]; + } + delete _property; + } +} + + +// ======================================================================= Read + +float Dot :: x () const { return _x; } +float Dot :: y () const { return _y; } +float Dot :: z () const { return _z; } + +Triangle *Dot :: Owner (int triangle) const +{ + if (triangle >= 0 && triangle < 6) + return _owner[triangle]; + return NULL; +} + +Vector &Dot :: Normal () { return _normal; } + +property_t *Dot :: Property (const int i) const +{ + return _property[i]; +} + +bool Dot :: Is_computed () const +{ + return _computed; +} + +bool Dot :: Is_checked () const +{ + return (step == glagen.step); +} + + +// ====================================================================== Write + +void Dot :: Set (const float x, const float y, const float z) +{ + _x = x; + _y = y; + _z = z; +} + +void Dot :: Use (Triangle *old_one, Triangle *new_one) +{ + Change_owner (old_one, new_one); + _use = _use + 1; +} + +bool Dot :: Drop (Triangle *old_one, Triangle *new_one) +{ + Change_owner (old_one, new_one); + _use = _use - 1; + return (_use <= 0); +} + +void Dot :: Update_normal () +{ + int count = 0; + + if (step == glagen.step) + return; + step = glagen.step; + + _normal.Set (0, 0, 0); + for (int current = 0; current < 6; current++) + if (_owner[current] != NULL) + { + _normal = _normal + _owner[current]->Normal_real (); + count++; + } + if (count != 0) + _normal = _normal / count; +} + +void Dot :: Del_property (const int i) +{ + if (_property[i] != NULL) + { + delete _property[i]; + _property[i] = NULL; + } +} + +void Dot :: Set_property (const int i, property_t *property) +{ + _property[i] = property; +} + +void Dot :: Computed () { _computed = true; } + +void Dot :: Checked () { step = glagen.step; } + +// ====================================================================== Other + +Dot *Dot :: Middle (const Dot *b) +{ + float xc = (x () + b->x ()) / 2; + float yc = (y () + b->y ()) / 2; + float zc = (z () + b->z ()) / 2; + float adjust = sqrtf (glagen.square_size / (xc * xc + yc * yc + zc * zc)); + xc = xc * adjust; + yc = yc * adjust; + zc = zc * adjust; + return new Dot (xc, yc, zc); // delete : triangle.cc l99, 101, 103 +} + +// ================================================================== Protected + +void Dot :: Change_owner (Triangle *old_one, Triangle *new_one) +{ + for (int current = 0; current < 6; current++) + if (_owner[current] == old_one) + { + _owner[current] = new_one; + return; + } + for (int current = 0; current < 6; current++) + if (_owner[current] == NULL) + { + _owner[current] = new_one; + return; + } +} diff --git a/3d/dot.hh b/3d/dot.hh new file mode 100644 index 0000000..8e17049 --- /dev/null +++ b/3d/dot.hh @@ -0,0 +1,84 @@ +//============================================================================= +// +// Glagen : a planet sized landscape generator +// Copyright (C) 2002 Julien Guertault, Hugues Hiegel, Meng-Tih Lam +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// +//============================================================================= +// +// Glagen : GPL LAndscape GENerator +// +// dot.hh for Glagen : made by Zavie (Julien Guertault) +// +// www.glagen.org +// +//============================================================================= + +#ifndef DOT_HH_ +# define DOT_HH_ + +#include "data_glagen.hh" +#include "triangle.hh" + +class Dot +{ +public: + + // Constructor and destructor + Dot (const float, const float, const float); + ~Dot (); + + // Read + float x () const; + float y () const; + float z () const; + + class Triangle *Owner (const int) const; + class Vector &Normal (); + + property_t *Property (const int) const; + bool Is_computed () const; + bool Is_checked () const; + + // Write + void Set (const float, const float, const float); + void Use (class Triangle *, class Triangle *); + bool Drop (class Triangle *, class Triangle *); + void Update_normal (); + void Del_property (const int); + void Set_property (const int, property_t *); + void Computed (); + void Checked (); + + // Other + Dot *Middle (const Dot *); + void Display (const unsigned int); + +protected: + void Change_owner (class Triangle *, class Triangle *); + + float _x; + float _y; + float _z; + unsigned char _use; + class Triangle *_owner[6]; + class Vector _normal; + property_t **_property; + bool _computed; + char step; +}; + +#endif // DOT_HH_ diff --git a/3d/dot_gl.cc b/3d/dot_gl.cc new file mode 100644 index 0000000..463df20 --- /dev/null +++ b/3d/dot_gl.cc @@ -0,0 +1,83 @@ +//============================================================================= +// +// Glagen : a planet sized landscape generator +// Copyright (C) 2002 Julien Guertault, Hugues Hiegel, Meng-Tih Lam +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// +//============================================================================= +// +// Glagen : GPL LAndscape GENerator +// +// dot_gl.cc for Glagen : made by Zavie (Julien Guertault) +// +// www.glagen.org +// +//============================================================================= + +#ifndef DARWIN +# include +# include +#else +# include +# include +#endif + +#include "data_glagen.hh" +#include "dot.hh" + +// +// Call the appropriate OpenGl functions for the dot +// +void Dot :: Display (const unsigned int id) +{ + surface_t *surface; + float adjust; + + if (glagen.display_planet) + { + if (NULL == _property[id]) + { + adjust = 0; + glColor3f ((1 + _x) / 2, (1 + _y) / 2, (1 + _z) / 2); + } + else + { + surface = static_cast (_property[id]->data); + if (NULL == surface) + { + adjust = 0; + glColor3f ((1 + _x) / 2, (1 + _y) / 2, (1 + _z) / 2); + } + else + { + adjust = surface->height; + glColor4f (surface->red, + surface->green, + surface->blue, + surface->alpha); + } + } + } + else + { + adjust = 0; + glColor3f ((1 + _x) / 2, (1 + _y) / 2, (1 + _z) / 2); + } + glNormal3f(_normal.X (), _normal.Y (), _normal.Z ()); + glVertex3f ((glagen.size + adjust) * _x, + (glagen.size + adjust) * _y, + (glagen.size + adjust) * _z); +} diff --git a/3d/end.cc b/3d/end.cc new file mode 100644 index 0000000..a16a634 --- /dev/null +++ b/3d/end.cc @@ -0,0 +1,53 @@ +//============================================================================= +// +// Glagen : a planet sized landscape generator +// Copyright (C) 2002 Julien Guertault, Hugues Hiegel, Meng-Tih Lam +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// +//============================================================================= +// +// Glagen : GPL LAndscape GENerator +// +// main.cc for Glagen : made by Zavie (Julien Guertault) +// +// www.glagen.org +// +//============================================================================= + +#include "data_glagen.hh" +#include "triangle.hh" + +void destroy_tree (Triangle *triangle) +{ + Triangle *next; + bool continue_deleting = true; + + while (continue_deleting) + { + if (0 == (next = triangle->Neighbor_ab ())) + if (0 == (next = triangle->Neighbor_bc ())) + if (0 == (next = triangle->Neighbor_ca ())) + continue_deleting = false; + delete triangle; + triangle = next; + } + exit (0); +} + +void end_all () +{ + destroy_tree(glagen.ref); +} diff --git a/3d/end.hh b/3d/end.hh new file mode 100644 index 0000000..402c4b2 --- /dev/null +++ b/3d/end.hh @@ -0,0 +1,39 @@ +//============================================================================= +// +// Glagen : a planet sized landscape generator +// Copyright (C) 2002 Julien Guertault, Hugues Hiegel, Meng-Tih Lam +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// +//============================================================================= +// +// Glagen : GPL LAndscape GENerator +// +// main.cc for Glagen : made by Zavie (Julien Guertault) +// +// www.glagen.org +// +//============================================================================= + +#ifndef END_HH_ +# define END_HH_ + +#include "data_glagen.hh" +#include "triangle.hh" + +void destroy_tree (Triangle *); +void end_all (); + +#endif // END_HH_ diff --git a/3d/frame.cc b/3d/frame.cc new file mode 100644 index 0000000..6f3aabd --- /dev/null +++ b/3d/frame.cc @@ -0,0 +1,152 @@ +//============================================================================= +// +// Glagen : a planet sized landscape generator +// Copyright (C) 2002 Julien Guertault, Hugues Hiegel, Meng-Tih Lam +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// +//============================================================================= +// +// Glagen : GPL LAndscape GENerator +// +// frame.cc for Glagen : made by Zavie (Julien Guertault) +// +// www.glagen.org +// +//============================================================================= + +#include "data_glagen.hh" +#include "frame.hh" +#include "matrix3d.hh" +#include "vector.hh" + +// ================================================ Constructors and destructor + +Frame :: Frame () +{ + _origin[0] = 0; + _origin[1] = 0; + _origin[2] = 0; + _basis[0] = Vector(1, 0, 0); + _basis[1] = Vector(0, 1, 0); + _basis[2] = Vector(0, 0, 1); +} + +Frame :: Frame (float origin[3]) +{ + _origin[0] = origin[0]; + _origin[1] = origin[1]; + _origin[2] = origin[2]; + _basis[0] = Vector(1, 0, 0); + _basis[1] = Vector(0, 1, 0); + _basis[2] = Vector(0, 0, 1); +} + +Frame :: Frame (float origin[3], Vector basis[3]) +{ + _origin[0] = origin[0]; + _origin[1] = origin[1]; + _origin[2] = origin[2]; + _basis[0] = Vector(basis[0]); + _basis[1] = Vector(basis[1]); + _basis[2] = Vector(basis[2]); +} + +Frame :: ~Frame () {} + +// ==================================================================== Reading + +float Frame :: Origin_X () const { return _origin[0]; } +float Frame :: Origin_Y () const { return _origin[1]; } +float Frame :: Origin_Z () const { return _origin[2]; } +Vector Frame :: Basis_X () const { return _basis[0]; } +Vector Frame :: Basis_Y () const { return _basis[1]; } +Vector Frame :: Basis_Z () const { return _basis[2]; } + +Vector Frame :: View () { return Vector (_basis[2]); } + +Matrix44 Frame :: GetMatrix () +{ + int x; + float basis_matrix[3][3]; + + for (x = 0; x < 3; x++) + { + basis_matrix[x][0] = _basis[x].X (); + basis_matrix[x][1] = _basis[x].Y (); + basis_matrix[x][2] = _basis[x].Z (); + } + Matrix44 rot_matrix(basis_matrix); + Matrix44 trans_matrix(_origin); + return Matrix44 (trans_matrix * rot_matrix); +} + +Matrix44 Frame :: GetCamMatrix () +{ + int x; + float basis_matrix[3][3]; + + for (x = 0; x < 3; x++) + { + basis_matrix[x][0] = _basis[x].X (); + basis_matrix[x][1] = _basis[x].Y (); + basis_matrix[x][2] = _basis[x].Z (); + } + Matrix44 rot_matrix(basis_matrix); + Matrix44 trans_matrix(_origin); + return Matrix44 (rot_matrix * trans_matrix); +} + +// ==================================================================== Writing + +void Frame :: Reset_origin () +{ + _origin[0] = 0; + _origin[1] = 0; + _origin[2] = 0; +} + +void Frame :: Reset_basis () +{ + _basis[0].Set (1, 0, 0) ; + _basis[1].Set (0, 1, 0) ; + _basis[2].Set (0, 0, 1) ; +} + +void Frame :: Set_origin (const float origin[3]) +{ + _origin[0] = origin[0]; + _origin[1] = origin[1]; + _origin[2] = origin[2]; +} + +void Frame :: Translate (const Vector v) +{ + _origin[0] = _origin[0] + v.X (); + _origin[1] = _origin[1] + v.Y (); + _origin[2] = _origin[2] + v.Z (); +} + +void Frame :: Rotate (const float angle, const Vector v) +{ + Matrix33 rot (angle, v); + + _basis[0] = rot * _basis[0]; + _basis[1] = rot * _basis[1]; + _basis[2] = rot * _basis[2]; + _basis[0].Normalize (); + _basis[1].Normalize (); + _basis[2].Normalize (); +} diff --git a/3d/frame.hh b/3d/frame.hh new file mode 100644 index 0000000..2fd125f --- /dev/null +++ b/3d/frame.hh @@ -0,0 +1,69 @@ +//============================================================================= +// +// Glagen : a planet sized landscape generator +// Copyright (C) 2002 Julien Guertault, Hugues Hiegel, Meng-Tih Lam +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// +//============================================================================= +// +// Glagen : GPL LAndscape GENerator +// +// frame.hh for Glagen : made by Zavie (Julien Guertault) +// +// www.glagen.org +// +//============================================================================= + +#ifndef FRAME_HH_ +# define FRAME_HH_ + +#include "matrix3d.hh" +#include "vector.hh" + +class Frame +{ +public: + // Constructors and destructor + Frame (); + Frame (float origin[3]); + Frame (float origin[3], class Vector basis[3]); + ~Frame(); + + // Reading + float Origin_X () const; + float Origin_Y () const; + float Origin_Z () const; + class Vector Basis_X () const; + class Vector Basis_Y () const; + class Vector Basis_Z () const; + + class Vector View (); + Matrix44 GetMatrix (); + Matrix44 GetCamMatrix (); + + // Writing + void Reset_origin (); + void Reset_basis (); + void Set_origin (const float origin[3]); + void Translate (const class Vector); + void Rotate (const float, const class Vector); + +protected: + float _origin[3]; + class Vector _basis[3]; +}; + +#endif // FRAME_HH_ diff --git a/3d/header.cc b/3d/header.cc new file mode 100644 index 0000000..cdcdf6d --- /dev/null +++ b/3d/header.cc @@ -0,0 +1,28 @@ +//============================================================================= +// +// Glagen : a planet sized landscape generator +// Copyright (C) 2002 Julien Guertault, Hugues Hiegel, Meng-Tih Lam +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// +//============================================================================= +// +// Glagen : GPL LAndscape GENerator +// +// *******.** for Glagen : made by Zavie (Julien Guertault) +// +// www.glagen.org +// +//============================================================================= diff --git a/3d/isosahedron.cc b/3d/isosahedron.cc new file mode 100644 index 0000000..1f3fc71 --- /dev/null +++ b/3d/isosahedron.cc @@ -0,0 +1,220 @@ +//============================================================================= +// +// Glagen : a planet sized landscape generator +// Copyright (C) 2002 Julien Guertault, Hugues Hiegel, Meng-Tih Lam +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// +//============================================================================= +// +// Glagen : GPL LAndscape GENerator +// +// isosahedron.cc for Glagen : made by Zavie (Julien Guertault) +// +// www.glagen.org +// +//============================================================================= + +#include +#include "data_glagen.hh" +#include "dot.hh" +#include "triangle.hh" + +// The regular polyhedron we use to create the planet is an isosahedron : +// 20 triangular faces, 12 vertex and 30 edges +// +// Vertex coordinates : +// +// { 0, 1, 0 } = P0 +// { sqrtf((5 - sqrtf(5)) / 10), (sqrtf(5)) / 5, -(5 + sqrtf(5)) / 10 } = P1 +// { -sqrtf((5 - sqrtf(5)) / 10), (sqrtf(5)) / 5, -(5 + sqrtf(5)) / 10 } = P2 +// { -sqrtf((5 + sqrtf(5)) / 10), (sqrtf(5)) / 5, (5 - sqrtf(5)) / 10 } = P3 +// { 0, (sqrtf(5)) / 5, 2 x ((sqrtf(5)) / 5) } = P4 +// { sqrtf((5 + sqrtf(5)) / 10), (sqrtf(5)) / 5, (5 - sqrtf(5)) / 10 } = P5 +// { sqrtf((5 - sqrtf(5)) / 10), -(sqrtf(5)) / 5, (5 + sqrtf(5)) / 10 } = P6 +// { -sqrtf((5 - sqrtf(5)) / 10), -(sqrtf(5)) / 5, (5 + sqrtf(5)) / 10 } = P7 +// { -sqrtf((5 + sqrtf(5)) / 10), -(sqrtf(5)) / 5, -(5 - sqrtf(5)) / 10 } = P8 +// { 0, -(sqrtf(5)) / 5, -2 x ((sqrtf(5)) / 5) } = P9 +// { sqrtf((5 + sqrtf(5)) / 10), -(sqrtf(5)) / 5, -(5 + sqrtf(5)) / 10 } = P10 +// { 0, -1, 0 } = P11 +// +// Faces : +// +// F0 = P0, P1, P2 +// F1 = P0, P2, P3 +// F2 = P0, P3, P4 +// F3 = P0, P4, P5 +// F4 = P0, P5, P1 +// F5 = P2, P1, P9 +// F6 = P8, P2, P9 +// F7 = P3, P2, P8 +// F8 = P7, P3, P8 +// F9 = P4, P3, P7 +// F10 = P6, P4, P7 +// F11 = P5, P4, P6 +// F12 = P10, P5, P6 +// F13 = P10, P1, P5 +// F14 = P9, P1, P10 +// F15 = P11, P8, P9 +// F16 = P11, P7, P8 +// F17 = P11, P6, P7 +// F18 = P11, P10, P6 +// F19 = P11, P9, P10 + +Triangle *isosahedron (float size) +{ + Dot *vertex[12]; + Triangle *face[20]; + float expr_1 = size * sqrtf((5 + sqrtf(5)) / 10); + float expr_2 = size * sqrtf((5 - sqrtf(5)) / 10); + float expr_3 = size * (5 + sqrtf(5)) / 10; + float expr_4 = size * (5 - sqrtf(5)) / 10; + float expr_5 = size * (sqrtf(5)) / 5; + + // Creation of the vertex + vertex[0] = new Dot ( 0, 1, 0); + vertex[1] = new Dot ( expr_2, expr_5, -expr_3); + vertex[2] = new Dot (-expr_2, expr_5, -expr_3); + vertex[3] = new Dot (-expr_1, expr_5, expr_4); + vertex[4] = new Dot ( 0, expr_5, 2 * expr_5); + vertex[5] = new Dot ( expr_1, expr_5, expr_4); + vertex[6] = new Dot ( expr_2, -expr_5, expr_3); + vertex[7] = new Dot (-expr_2, -expr_5, expr_3); + vertex[8] = new Dot (-expr_1, -expr_5, -expr_4); + vertex[9] = new Dot ( 0, -expr_5, -2 * expr_5); + vertex[10] = new Dot ( expr_1, -expr_5, -expr_4); + vertex[11] = new Dot ( 0, -1, 0); + + // Creation of the triangles + face[0] = new Triangle (vertex[0], vertex[1], vertex[2], NULL); + face[1] = new Triangle (vertex[0], vertex[2], vertex[3], NULL); + face[2] = new Triangle (vertex[0], vertex[3], vertex[4], NULL); + face[3] = new Triangle (vertex[0], vertex[4], vertex[5], NULL); + face[4] = new Triangle (vertex[0], vertex[5], vertex[1], NULL); + face[5] = new Triangle (vertex[2], vertex[1], vertex[9], NULL); + face[6] = new Triangle (vertex[8], vertex[2], vertex[9], NULL); + face[7] = new Triangle (vertex[3], vertex[2], vertex[8], NULL); + face[8] = new Triangle (vertex[7], vertex[3], vertex[8], NULL); + face[9] = new Triangle (vertex[4], vertex[3], vertex[7], NULL); + face[10] = new Triangle (vertex[6], vertex[4], vertex[7], NULL); + face[11] = new Triangle (vertex[5], vertex[4], vertex[6], NULL); + face[12] = new Triangle (vertex[10], vertex[5], vertex[6], NULL); + face[13] = new Triangle (vertex[10], vertex[1], vertex[5], NULL); + face[14] = new Triangle (vertex[9], vertex[1], vertex[10], NULL); + face[15] = new Triangle (vertex[11], vertex[8], vertex[9], NULL); + face[16] = new Triangle (vertex[11], vertex[7], vertex[8], NULL); + face[17] = new Triangle (vertex[11], vertex[6], vertex[7], NULL); + face[18] = new Triangle (vertex[11], vertex[10], vertex[6], NULL); + face[19] = new Triangle (vertex[11], vertex[9], vertex[10], NULL); + + // Setting up of the connexity + face[0]->Make_connexity (face[1]); + face[0]->Make_connexity (face[4]); + face[0]->Make_connexity (face[5]); + + face[1]->Make_connexity (face[0]); + face[1]->Make_connexity (face[2]); + face[1]->Make_connexity (face[7]); + + face[2]->Make_connexity (face[1]); + face[2]->Make_connexity (face[3]); + face[2]->Make_connexity (face[9]); + + face[3]->Make_connexity (face[2]); + face[3]->Make_connexity (face[4]); + face[3]->Make_connexity (face[11]); + + face[4]->Make_connexity (face[0]); + face[4]->Make_connexity (face[3]); + face[4]->Make_connexity (face[13]); + + face[5]->Make_connexity (face[0]); + face[5]->Make_connexity (face[6]); + face[5]->Make_connexity (face[14]); + + face[6]->Make_connexity (face[5]); + face[6]->Make_connexity (face[7]); + face[6]->Make_connexity (face[15]); + + face[7]->Make_connexity (face[1]); + face[7]->Make_connexity (face[6]); + face[7]->Make_connexity (face[8]); + + face[8]->Make_connexity (face[7]); + face[8]->Make_connexity (face[9]); + face[8]->Make_connexity (face[16]); + + face[9]->Make_connexity (face[2]); + face[9]->Make_connexity (face[8]); + face[9]->Make_connexity (face[10]); + + face[10]->Make_connexity (face[9]); + face[10]->Make_connexity (face[11]); + face[10]->Make_connexity (face[17]); + + face[11]->Make_connexity (face[3]); + face[11]->Make_connexity (face[10]); + face[11]->Make_connexity (face[12]); + + face[12]->Make_connexity (face[11]); + face[12]->Make_connexity (face[13]); + face[12]->Make_connexity (face[18]); + + face[13]->Make_connexity (face[4]); + face[13]->Make_connexity (face[12]); + face[13]->Make_connexity (face[14]); + + face[14]->Make_connexity (face[5]); + face[14]->Make_connexity (face[13]); + face[14]->Make_connexity (face[19]); + + face[15]->Make_connexity (face[6]); + face[15]->Make_connexity (face[16]); + face[15]->Make_connexity (face[19]); + + face[16]->Make_connexity (face[8]); + face[16]->Make_connexity (face[15]); + face[16]->Make_connexity (face[17]); + + face[17]->Make_connexity (face[10]); + face[17]->Make_connexity (face[16]); + face[17]->Make_connexity (face[18]); + + face[18]->Make_connexity (face[12]); + face[18]->Make_connexity (face[17]); + face[18]->Make_connexity (face[19]); + + face[19]->Make_connexity (face[14]); + face[19]->Make_connexity (face[15]); + face[19]->Make_connexity (face[18]); + + return face[0]; +} + +void split_all (Triangle *triangle) +{ + if (triangle->Is_checked ()) + return; + triangle->Checked (); + + triangle->Split (); + + if (triangle->Neighbor_ab () != 0) + split_all (triangle->Neighbor_ab ()); + if (triangle->Neighbor_bc () != 0) + split_all (triangle->Neighbor_bc ()); + if (triangle->Neighbor_ca () != 0) + split_all (triangle->Neighbor_ca ()); +} diff --git a/3d/isosahedron.hh b/3d/isosahedron.hh new file mode 100644 index 0000000..f339154 --- /dev/null +++ b/3d/isosahedron.hh @@ -0,0 +1,38 @@ +//============================================================================= +// +// Glagen : a planet sized landscape generator +// Copyright (C) 2002 Julien Guertault, Hugues Hiegel, Meng-Tih Lam +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// +//============================================================================= +// +// Glagen : GPL LAndscape GENerator +// +// isosahedron.hh for Glagen : made by Zavie (Julien Guertault) +// +// www.glagen.org +// +//============================================================================= + +#ifndef ISOSAHEDRON_HH_ +# define ISOSAHEDRON_HH_ + +#include "triangle.hh" + +Triangle *isosahedron (float); +void split_all (Triangle *); + +#endif // ISOCAHEDRON_HH_ diff --git a/3d/library.cc b/3d/library.cc new file mode 100644 index 0000000..19d706f --- /dev/null +++ b/3d/library.cc @@ -0,0 +1,100 @@ +//============================================================================= +// +// Glagen : a planet sized landscape generator +// Copyright (C) 2002 Julien Guertault, Hugues Hiegel, Meng-Tih Lam +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// +//============================================================================= +// +// Glagen : GPL LAndscape GENerator +// +// library.cc for Glagen : made by Zavie (Julien Guertault) +// +// www.glagen.org +// +//============================================================================= + +#include "dot.hh" +#include "triangle.hh" +#include "data_glagen.hh" +#include "simul.hh" + +// This visitor applies the given library to each dot +void library_visitor (void (library)(Dot*, unsigned int), + bool dynamic, + Triangle *triangle) +{ + if (triangle->Is_checked ()) + return; + + if (triangle->A ()->Is_checked () == false && + (dynamic == true || + triangle->A ()->Is_computed () == false)) + { + library (triangle->A (), triangle->Level ()); + triangle->A ()->Computed (); + triangle->A ()->Checked (); + } + if (triangle->B ()->Is_checked () == false && + (dynamic == true || + triangle->B ()->Is_computed () == false)) + { + library (triangle->B (), triangle->Level ()); + triangle->B ()->Computed (); + triangle->B ()->Checked (); + } + if (triangle->C ()->Is_checked () == false && + (dynamic == true || + triangle->C ()->Is_computed () == false)) + { + library (triangle->C (), triangle->Level ()); + triangle->C ()->Computed (); + triangle->C ()->Checked (); + } + + if (triangle->Is_split ()) + { + library_visitor (library, dynamic, triangle->Child_center ()); + library_visitor (library, dynamic, triangle->Child_a ()); + library_visitor (library, dynamic, triangle->Child_b ()); + library_visitor (library, dynamic, triangle->Child_c ()); + } + + triangle->Checked (); + if (triangle->Father() == NULL) + { + if (triangle->Neighbor_ab () != NULL) + library_visitor (library, dynamic, triangle->Neighbor_ab ()); + if (triangle->Neighbor_bc () != NULL) + library_visitor (library, dynamic, triangle->Neighbor_bc ()); + if (triangle->Neighbor_ca () != NULL) + library_visitor (library, dynamic, triangle->Neighbor_ca ()); + } +} + +// Here we call the visitor for each library +void library_caller (Triangle *triangle) +{ + void *(lib)(Dot *, unsigned int); + + for (int current = 0; glagen.library[current].kind != none; current++) + { + library_visitor (glagen.library[current].run, + glagen.library[current].dynamic, + triangle); + glagen.step = glagen.step + 1; + } +} diff --git a/3d/library.hh b/3d/library.hh new file mode 100644 index 0000000..acb262f --- /dev/null +++ b/3d/library.hh @@ -0,0 +1,40 @@ +//============================================================================= +// +// Glagen : a planet sized landscape generator +// Copyright (C) 2002 Julien Guertault, Hugues Hiegel, Meng-Tih Lam +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// +//============================================================================= +// +// Glagen : GPL LAndscape GENerator +// +// library.cc for Glagen : made by Zavie (Julien Guertault) +// +// www.glagen.org +// +//============================================================================= + +#ifndef LIBRARY_VISITOR_HH_ +# define LIBRARY_VISITOR_HH_ + +#include "triangle.hh" + +void library_visitor (void *(library)(Dot*, unsigned int), + bool, + Triangle *); +void library_caller (Triangle *); + +#endif // LIBRARY_VISITOR_HH_ diff --git a/3d/main.cc b/3d/main.cc new file mode 100644 index 0000000..d2d3561 --- /dev/null +++ b/3d/main.cc @@ -0,0 +1,132 @@ +//============================================================================= +// +// Glagen : a planet sized landscape generator +// Copyright (C) 2002 Julien Guertault, Hugues Hiegel, Meng-Tih Lam +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// +//============================================================================= +// +// Glagen : GPL LAndscape GENerator +// +// main.cc for Glagen : made by Zavie (Julien Guertault) +// +// www.glagen.org +// +//============================================================================= + +#include +#include +#include +#include +#include "dot.hh" +#include "data_glagen.hh" +#include "display.hh" +#include "frame.hh" +#include "isosahedron.hh" +#include "library.hh" +#include "matrix3d.hh" +#include "perlin.hh" +#include "time.hh" +#include "triangle.hh" +#include "simul.hh" + +glagen_t glagen; + +void init_all () +{ + float origin[3]; + + Perlin_init (); + origin[0] = 0; + origin[1] = 0; + origin[2] = -3; + glagen.observer.frame.Set_origin (origin); + glagen.observer.altitude = sqrtf (glagen.observer.frame.Origin_X () * + glagen.observer.frame.Origin_X () + + glagen.observer.frame.Origin_Y () * + glagen.observer.frame.Origin_Y () + + glagen.observer.frame.Origin_Z () * + glagen.observer.frame.Origin_Z ()) - 1; + glagen.observer.speed = 0.1 + glagen.observer.altitude / 50; + glagen.triangles = 0; + + init_time (); + + //Limite : entre 50000 et 200000... + glagen.max_triangles = 100000; + glagen.step = 0; + glagen.size = 1; + glagen.square_size = glagen.size * glagen.size; + // + // Simulation + // + glagen.property = 200; + // 0.05 et 0.4 is quite good + glagen.split_dist_limit = 0.05; + glagen.split_norm_limit = 0.4; + // + glagen.ref = isosahedron (glagen.size); + glagen.step++; + + // Debug options + glagen.display_normal = false; + glagen.display_planet = true; + glagen.display_all = false; + glagen.third_view = false; + glagen.zoom = true; + glagen.depth_test = true; + glagen.light = false; +} + +int main (int narg, char **args) +{ +// printf("int : %d\n", sizeof (int)); + init_all(); + simule_lib_load(); + + if (glagen.zoom) + { + glagen.current = glagen.ref; + glagen.ref->Split_visitor (); + glagen.step = glagen.step + 1; + glagen.ref->Hide_visitor (); + } + else + { + split_all (glagen.ref); + glagen.step++; + split_all (glagen.ref->Child_center ()); + glagen.step++; + split_all (glagen.ref->Child_center ()->Child_center ()); + glagen.step++; + split_all (glagen.ref->Child_center ()->Child_center ()-> + Child_center ()); + glagen.step++; + split_all (glagen.ref->Child_center ()->Child_center ()-> + Child_center ()->Child_center ()); + glagen.step++; + glagen.current = glagen.ref-> + Child_center ()-> + Child_center ()-> + Child_center ()-> + Child_center ()-> + Child_center (); + } + library_caller (glagen.ref); + glagen.step++; + display (&narg, &args); + return 0; +} diff --git a/3d/matrix3d.cc b/3d/matrix3d.cc new file mode 100644 index 0000000..c02ac39 --- /dev/null +++ b/3d/matrix3d.cc @@ -0,0 +1,216 @@ +//============================================================================= +// +// Glagen : a planet sized landscape generator +// Copyright (C) 2002 Julien Guertault, Hugues Hiegel, Meng-Tih Lam +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// +//============================================================================= +// +// Glagen : GPL LAndscape GENerator +// +// matrix.cc for Glagen : made by Zavie (Julien Guertault) +// +// www.glagen.org +// +//============================================================================= + +#include +#include "data_glagen.hh" +#include "matrix3d.hh" +#include "vector.hh" + +// =============================================== Constructors and destructors + +Matrix33 :: Matrix33 () +{ + for (int y = 0; y < 3; y++) + for (int x = 0; x < 3; x++) + mat[x][y] = (x == y ? 1 : 0); +} + +Matrix33 :: Matrix33 (const class Matrix33 &source) +{ + for (int y = 0; y < 3; y++) + for (int x = 0; x < 3; x++) + mat[x][y] = source.A(x, y); +} + +Matrix33 :: Matrix33 (const float m[3][3]) +{ + for (int y = 0; y < 3; y++) + { + for (int x = 0; x < 3; x++) + mat[x][y] = m[x][y]; + mat[3][y] = 0; + } + mat[0][3] = 0; + mat[1][3] = 0; + mat[2][3] = 0; + mat[3][3] = 1; +} + +Matrix33 :: Matrix33 (const float angle, const Vector &v) +{ + float c = cosf (angle); + float s = sinf (angle); + float t = 1 - c; + float val[] = {t * v.X () * v.X () + c, + t * v.X () * v.Y () - s * v.Z (), + t * v.X () * v.Z () + s * v.Y (), + + t * v.X () * v.Y () + s * v.Z (), + t * v.Y () * v.Y () + c, + t * v.Y () * v.Z () - s * v.X (), + + t * v.X () * v.Z () - s * v.Y (), + t * v.Y () * v.Z () + s * v.X (), + t * v.Z () * v.Z () + c}; + for (int j = 0; j < 3; j++) + for (int i = 0; i < 3; i++) + mat[i][j] = val[3 * j + i]; +} + +Matrix33 :: ~Matrix33 () {} + +Matrix44 :: Matrix44 () +{ + for (int y = 0; y < 4; y++) + for (int x = 0; x < 4; x++) + mat[x][y] = (x == y ? 1 : 0); +} + +Matrix44 :: Matrix44 (const class Matrix44 &source) +{ + for (int y = 0; y < 4; y++) + for (int x = 0; x < 4; x++) + mat[x][y] = source.A(x, y); +} + +Matrix44 :: Matrix44 (const class Matrix33 &source) +{ + for (int y = 0; y < 3; y++) + for (int x = 0; x < 3; x++) + mat[x][y] = source.A(x, y); + mat[3][3] = 1; +} + +Matrix44 :: Matrix44 (const float m[4][4]) +{ + for (int y = 0; y < 4; y++) + for (int x = 0; x < 4; x++) + mat[x][y] = m[x][y]; +} + +Matrix44 :: Matrix44 (const float m[3][3]) +{ + for (int y = 0; y < 3; y++) + { + for (int x = 0; x < 3; x++) + mat[x][y] = m[x][y]; + mat[3][y] = 0; + } + mat[0][3] = 0; + mat[1][3] = 0; + mat[2][3] = 0; + mat[3][3] = 1; +} + +// Create a translation matrix from a vector +Matrix44 :: Matrix44(const float colon[3]) +{ + for (int y = 0; y < 4; y++) + for (int x = 0; x < 4; x++) + if (x == y) + mat[x][y] = 1; + else + mat[x][y] = 0; + mat[3][0] = colon[0]; + mat[3][1] = colon[1]; + mat[3][2] = colon[2]; +} + +Matrix44 :: ~Matrix44() {} + + +// ====================================================== The matrix's elements + +float Matrix33 :: A(const int x, const int y) const +{ + if (x >= 0 && x < 3 && + y >= 0 && y < 3) + return mat[x][y]; + else + return 0; +} + +float Matrix44 :: A(const int x, const int y) const +{ + if (x >= 0 && x < 4 && + y >= 0 && y < 4) + return mat[x][y]; + else + return 0; +} + +// Orthonormalize +void Matrix33 :: OrthonormalizeOrientation () +{ + Vector X (mat[0][0], mat[1][0], mat[2][0]); + Vector Y (mat[0][1], mat[1][1], mat[2][1]); + Vector Z; + + X.Normalize(); + Z = (X ^ Y); + Z.Normalize(); + Y = (Z ^ X); + Y.Normalize(); + + mat[0][0] = X.X (); mat[0][1] = Y.X (); mat[0][2] = Z.X (); + mat[1][0] = X.Y (); mat[1][1] = Y.Y (); mat[1][2] = Z.Y (); + mat[2][0] = X.Z (); mat[2][1] = Y.Z (); mat[2][2] = Z.Z (); +} + + +// ================================================================== Operators + +Vector Matrix33 :: operator * (const Vector &v) const +{ + float out[3]; + + out[0] = (A (0, 0) * v.X () + + A (1, 0) * v.Y () + + A (2, 0) * v.Z ()); + out[1] = (A (0, 1) * v.X () + + A (1, 1) * v.Y () + + A (2, 1) * v.Z ()); + out[2] = (A (0, 2) * v.X () + + A (1, 2) * v.Y () + + A (2, 2) * v.Z ()); + return Vector (out[0], out[1], out[2]); +} + +Matrix44 Matrix44 :: operator * (const Matrix44 &source) const +{ + float out[4][4]; + + for (int y = 0; y < 4; y++) + for (int x = 0; x < 4; x++) + out[x][y] = (A(0, y) * source.A(x, 0) + + A(1, y) * source.A(x, 1) + + A(2, y) * source.A(x, 2) + + A(3, y) * source.A(x, 3)); + return Matrix44(out); +} diff --git a/3d/matrix3d.hh b/3d/matrix3d.hh new file mode 100644 index 0000000..859f480 --- /dev/null +++ b/3d/matrix3d.hh @@ -0,0 +1,80 @@ +//============================================================================= +// +// Glagen : a planet sized landscape generator +// Copyright (C) 2002 Julien Guertault, Hugues Hiegel, Meng-Tih Lam +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// +//============================================================================= +// +// Glagen : GPL LAndscape GENerator +// +// matrix.hh for Glagen : made by Zavie (Julien Guertault) +// +// www.glagen.org +// +//============================================================================= + +#ifndef MATRIX3D_HH_ +# define MATRIX3D_HH_ + +class Matrix33 +{ +public : + + //Constructors and destructor + Matrix33 (); + Matrix33 (const class Matrix33 &); + Matrix33 (const float m[3][3]); + Matrix33 (const float, const class Vector &); + ~Matrix33 (); + + // Matrix itself + float A (const int, const int) const; + + // Orthonormalize + void OrthonormalizeOrientation (); + + // Operator + class Vector operator * (const class Vector &) const; + +protected : + float mat[3][3]; +}; + +class Matrix44 +{ +public : + + //Constructors and destructor + Matrix44 (); + Matrix44 (const class Matrix44 &); + Matrix44 (const class Matrix33 &); + Matrix44 (const float m[3][3]); + Matrix44 (const float m[4][4]); + Matrix44 (const float colon[3]); + ~Matrix44 (); + + //Matrix itself + float A (const int, const int) const; + + //Operator + Matrix44 operator * (const Matrix44 &) const; + +protected : + float mat[4][4]; +}; + +#endif // MATRIX3D diff --git a/3d/misc.cc b/3d/misc.cc new file mode 100644 index 0000000..caf7264 --- /dev/null +++ b/3d/misc.cc @@ -0,0 +1,43 @@ +//============================================================================= +// +// Glagen : a planet sized landscape generator +// Copyright (C) 2002 Julien Guertault, Hugues Hiegel, Meng-Tih Lam +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// +//============================================================================= +// +// Glagen : GPL LAndscape GENerator +// +// misc.cc for Glagen : made by Zavie (Julien Guertault) +// +// www.glagen.org +// +//============================================================================= + +#include +#include "data_glagen.hh" + +// +// This function is supposed to compute very fast a good approximation +// of the distance. +// The quality of this function is very important for the frame-rate +// +float Approx_dist (float x, float y, float z) +{ + // Well, I still have to fond an approximation ^_^ + // I suppose I will use Taylor Lagrange, or something like that. + return (sqrt (x * x + y * y + z * z)); +} diff --git a/3d/misc.hh b/3d/misc.hh new file mode 100644 index 0000000..696d5a4 --- /dev/null +++ b/3d/misc.hh @@ -0,0 +1,38 @@ +//============================================================================= +// +// Glagen : a planet sized landscape generator +// Copyright (C) 2002 Julien Guertault, Hugues Hiegel, Meng-Tih Lam +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// +//============================================================================= +// +// Glagen : GPL LAndscape GENerator +// +// misc.hh for Glagen : made by Zavie (Julien Guertault) +// +// www.glagen.org +// +//============================================================================= + + +#ifndef MISC_HH_ +# define MISC_HH_ + +#include "data_glagen.hh" + +float Approx_dist (float, float, float); + +#endif // MISC_HH_ diff --git a/3d/perlin.cc b/3d/perlin.cc new file mode 100644 index 0000000..5cb4aee --- /dev/null +++ b/3d/perlin.cc @@ -0,0 +1,347 @@ +//============================================================================= +// +// Glagen : a planet sized landscape generator +// Copyright (C) 2002 Julien Guertault, Hugues Hiegel, Meng-Tih Lam +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// +//============================================================================= +// +// Glagen : GPL LAndscape GENerator +// +// perlin.cc for Glagen : made by Zavie (Julien Guertault) +// +// www.glagen.org +// +//============================================================================= + +// Original implementation fo Perlin noice. +// It can be found on : +// http://mrl.nyu.edu/~perlin/doc/oscar.html#noise +// +// The 4th dimension noise has been added for our needs + +// coherent noise function over 1, 2 or 3 dimensions +// (copyright Ken Perlin) + +#include +#include +#include "data_glagen.hh" + +#define B 0x100 +#define BM 0xff + +#define N 0x1000 +#define NP 12 /* 2^N */ +#define NM 0xfff + +static int p[B + B + 2]; +static float g4[B + B + 2][4]; +static float g3[B + B + 2][3]; +static float g2[B + B + 2][2]; +static float g1[B + B + 2]; + +#define s_curve(t) ( t * t * (3. - 2. * t) ) + +#define lerp(t, a, b) ( a + t * (b - a) ) + +#define setup(i,b0,b1,r0,r1)\ + t = vec[i] + N;\ + b0 = ((int)t) & BM;\ + b1 = (b0+1) & BM;\ + r0 = t - (int)t;\ + r1 = r0 - 1.; + +float GLG_Perlin_noise_1D (float arg) +{ + int bx0, bx1; + float rx0, rx1; + float sx; + float t, u, v; + float vec[1]; + + vec[0] = arg; + + setup(0, bx0,bx1, rx0,rx1); + + sx = s_curve(rx0); + + u = rx0 * g1[ p[ bx0 ] ]; + v = rx1 * g1[ p[ bx1 ] ]; + + return lerp(sx, u, v); +} + +float GLG_Perlin_noise_2D (float vec[2]) +{ + int bx0, bx1; + int by0, by1; + int b00, b10, b01, b11; + float rx0, rx1; + float ry0, ry1; + float *q, sx, sy; + float a, b; + float t, u, v; + register int i, j; + + setup(0, bx0,bx1, rx0,rx1); + setup(1, by0,by1, ry0,ry1); + + i = p[ bx0 ]; + j = p[ bx1 ]; + + b00 = p[ i + by0 ]; + b10 = p[ j + by0 ]; + b01 = p[ i + by1 ]; + b11 = p[ j + by1 ]; + + sx = s_curve(rx0); + sy = s_curve(ry0); + +#define at2(rx,ry) ( rx * q[0] + ry * q[1] ) + + q = g2[ b00 ] ; u = at2(rx0,ry0); + q = g2[ b10 ] ; v = at2(rx1,ry0); + a = lerp(sx, u, v); + + q = g2[ b01 ] ; u = at2(rx0,ry1); + q = g2[ b11 ] ; v = at2(rx1,ry1); + b = lerp(sx, u, v); + + return lerp(sy, a, b); +} + +float GLG_Perlin_noise_3D (float vec[3]) +{ + int bx0, bx1; + int by0, by1; + int bz0, bz1; + int b00, b10, b01, b11; + float rx0, rx1; + float ry0, ry1; + float rz0, rz1; + float *q, sy, sz; + float a, b, c, d; + float t, u, v; + register int i, j; + + setup(0, bx0,bx1, rx0,rx1); + setup(1, by0,by1, ry0,ry1); + setup(2, bz0,bz1, rz0,rz1); + + i = p[ bx0 ]; + j = p[ bx1 ]; + + b00 = p[ i + by0 ]; + b10 = p[ j + by0 ]; + b01 = p[ i + by1 ]; + b11 = p[ j + by1 ]; + + t = s_curve(rx0); + sy = s_curve(ry0); + sz = s_curve(rz0); + +#define at3(rx,ry,rz) ( rx * q[0] + ry * q[1] + rz * q[2] ) + + q = g3[ b00 + bz0 ] ; u = at3(rx0,ry0,rz0); + q = g3[ b10 + bz0 ] ; v = at3(rx1,ry0,rz0); + a = lerp(t, u, v); + + q = g3[ b01 + bz0 ] ; u = at3(rx0,ry1,rz0); + q = g3[ b11 + bz0 ] ; v = at3(rx1,ry1,rz0); + b = lerp(t, u, v); + + c = lerp(sy, a, b); + + q = g3[ b00 + bz1 ] ; u = at3(rx0,ry0,rz1); + q = g3[ b10 + bz1 ] ; v = at3(rx1,ry0,rz1); + a = lerp(t, u, v); + + q = g3[ b01 + bz1 ] ; u = at3(rx0,ry1,rz1); + q = g3[ b11 + bz1 ] ; v = at3(rx1,ry1,rz1); + b = lerp(t, u, v); + + d = lerp(sy, a, b); + + return lerp(sz, c, d); +} + +float GLG_Perlin_noise_4D (float vec[4]) +{ + int bx0, bx1; + int by0, by1; + int bz0, bz1; + int bt0, bt1; + register int a0, a1; + int b00, b10, b01, b11; + int c000, c001, c010, c011, c100, c101, c110, c111; + float rx0, rx1; + float ry0, ry1; + float rz0, rz1; + float rt0, rt1; + float *q, sx, sy, sz, st; + float a, b, c, d, e, f; + float t, u, v; + + setup(0, bx0,bx1, rx0,rx1); + setup(1, by0,by1, ry0,ry1); + setup(2, bz0,bz1, rz0,rz1); + setup(3, bt0,bt1, rt0,rt1); + + a0 = p[ bx0 ]; + a1 = p[ bx1 ]; + + b00 = p[ a0 + by0 ]; + b10 = p[ a1 + by0 ]; + b01 = p[ a0 + by1 ]; + b11 = p[ a1 + by1 ]; + + c000 = p[ b00 + bz0 ]; + c100 = p[ b10 + bz0 ]; + c010 = p[ b01 + bz0 ]; + c110 = p[ b11 + bz0 ]; + c001 = p[ b00 + bz1 ]; + c101 = p[ b10 + bz1 ]; + c011 = p[ b01 + bz1 ]; + c111 = p[ b11 + bz1 ]; + + sx = s_curve(rx0); + sy = s_curve(ry0); + sz = s_curve(rz0); + st = s_curve(rt0); + +#define at4(rx, ry, rz, rt) ( rx * q[0] + ry * q[1] + rz * q[2] + rt * q[3]) + + q = g4[c000 + bt0]; u = at4(rx0, ry0, rz0, rt0); + q = g4[c100 + bt0]; v = at4(rx1, ry0, rz0, rt0); + a = lerp(sx, u, v); + + q = g4[c010 + bt0]; u = at4(rx0, ry1, rz0, rt0); + q = g4[c110 + bt0]; v = at4(rx1, ry1, rz0, rt0); + b = lerp(sx, u, v); + + c = lerp (sy, a, b); + + q = g4[c001 + bt0]; u = at4(rx0, ry0, rz1, rt0); + q = g4[c101 + bt0]; v = at4(rx1, ry0, rz1, rt0); + a = lerp(sx, u, v); + + q = g4[c011 + bt0]; u = at4(rx0, ry1, rz1, rt0); + q = g4[c111 + bt0]; v = at4(rx1, ry1, rz1, rt0); + b = lerp(sx, u, v); + + d = lerp (sy, a, b); + + + e = lerp (sz, c, d); + + + q = g4[c000 + bt1]; u = at4(rx0, ry0, rz0, rt1); + q = g4[c100 + bt1]; v = at4(rx1, ry0, rz0, rt1); + a = lerp(sx, u, v); + + q = g4[c010 + bt1]; u = at4(rx0, ry1, rz0, rt1); + q = g4[c110 + bt1]; v = at4(rx1, ry1, rz0, rt1); + b = lerp(sx, u, v); + + c = lerp (sy, a, b); + + q = g4[c001 + bt1]; u = at4(rx0, ry0, rz1, rt1); + q = g4[c101 + bt1]; v = at4(rx1, ry0, rz1, rt1); + a = lerp(sx, u, v); + + q = g4[c011 + bt1]; u = at4(rx0, ry1, rz1, rt1); + q = g4[c111 + bt1]; v = at4(rx1, ry1, rz1, rt1); + b = lerp(sx, u, v); + + d = lerp (sy, a, b); + + + f = lerp (sz, c, d); + + + return lerp (st, e, f); +} + +static void normalize2 (float v[2]) +{ + float s; + + s = sqrtf(v[0] * v[0] + v[1] * v[1]); + v[0] = v[0] / s; + v[1] = v[1] / s; +} + +static void normalize3 (float v[3]) +{ + float s; + + s = sqrtf(v[0] * v[0] + v[1] * v[1] + v[2] * v[2]); + v[0] = v[0] / s; + v[1] = v[1] / s; + v[2] = v[2] / s; +} + +static void normalize4 (float v[4]) +{ + float s; + + s = sqrtf(v[0] * v[0] + v[1] * v[1] + v[2] * v[2] + v[3] * v[3]); + v[0] = v[0] / s; + v[1] = v[1] / s; + v[2] = v[2] / s; + v[3] = v[3] / s; +} + +void Perlin_init () +{ + int i, j, k; + + for (i = 0 ; i < B ; i++) + { + p[i] = i; + + g1[i] = (float)((rand() % (B + B)) - B) / B; + + for (j = 0 ; j < 2 ; j++) + g2[i][j] = (float)((rand() % (B + B)) - B) / B; + normalize2(g2[i]); + + for (j = 0 ; j < 3 ; j++) + g3[i][j] = (float)((rand() % (B + B)) - B) / B; + normalize3(g3[i]); + + for (j = 0 ; j < 4 ; j++) + g4[i][j] = (float)((rand() % (B + B)) - B) / B; + normalize4(g4[i]); + } + + while (--i) + { + k = p[i]; + p[i] = p[j = rand() % B]; + p[j] = k; + } + + for (i = 0 ; i < B + 2 ; i++) + { + p[B + i] = p[i]; + g1[B + i] = g1[i]; + for (j = 0 ; j < 2 ; j++) + g2[B + i][j] = g2[i][j]; + for (j = 0 ; j < 3 ; j++) + g3[B + i][j] = g3[i][j]; + } +} diff --git a/3d/perlin.hh b/3d/perlin.hh new file mode 100644 index 0000000..3deb1c9 --- /dev/null +++ b/3d/perlin.hh @@ -0,0 +1,39 @@ +//============================================================================= +// +// Glagen : a planet sized landscape generator +// Copyright (C) 2002 Julien Guertault, Hugues Hiegel, Meng-Tih Lam +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// +//============================================================================= +// +// Glagen : GPL LAndscape GENerator +// +// perlin.hh for Glagen : made by Zavie (Julien Guertault) +// +// www.glagen.org +// +//============================================================================= + +#ifndef PERLIN_HH_ +# define PERLIN_HH_ + +float GLG_Perlin_noise_1D (float); +float GLG_Perlin_noise_2D (float vec[2]); +float GLG_Perlin_noise_3D (float vec[3]); +float GLG_Perlin_noise_4D (float vec[4]); +void Perlin_init (); + +#endif // PERLIN_HH_ diff --git a/3d/simul.cc b/3d/simul.cc new file mode 100644 index 0000000..d68daa5 --- /dev/null +++ b/3d/simul.cc @@ -0,0 +1,409 @@ +//============================================================================= +// +// Glagen : a planet sized landscape generator +// Copyright (C) 2002 Julien Guertault, Hugues Hiegel, Meng-Tih Lam +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// +//============================================================================= +// +// Glagen : GPL LAndscape GENerator +// +// simul.cc for Glagen : made by Zavie (Julien Guertault) +// +// www.glagen.org +// +//============================================================================= + +#include +#include "dot.hh" +#include "data_glagen.hh" +#include "perlin.hh" + +// +// A garder : une librairie de simulation du Soleil +// +void surface_solaire (Dot *m, unsigned int) +{ + property_t *property; + surface_t *data; + float param[4]; + float sum; + + if (m->Property (0) == NULL) + { + property = new property_t; // delete : dot.cc l59 + property->kind = surface; + property->size = sizeof (surface_t); + data = new surface_t; // delete : dot.cc l58 + property->data = data; + m->Set_property (0, property); + } + else + { + property = m->Property (0); + data = static_cast (property->data); + } + + param[0] = 10 * m->x () * 2; + param[1] = 10 * m->y () * 2; + param[2] = 10 * m->z () * 2; + param[3] = glagen.float_time; + sum = GLG_Perlin_noise_4D (param) / 40.0; + param[0] = 20 * m->x () * 2; + param[1] = 20 * m->y () * 2; + param[2] = 20 * m->z () * 2; + param[3] = glagen.float_time; + sum = sum + GLG_Perlin_noise_4D (param) / 80.0; + param[0] = 40 * m->x () * 2; + param[1] = 40 * m->y () * 2; + param[2] = 40 * m->z () * 2; + param[3] = glagen.float_time; + sum = sum + GLG_Perlin_noise_4D (param) / 160.0; + data->height = 1.5 * sum; + + data->red = 1; + data->green = (1 + 40 * data->height) / 2; + data->blue = (data->height * data->height * 1600); + data->alpha = (1 + 40 * data->height) / 2; +} + +void atmosphere_solaire (Dot *m, unsigned int) +{ + property_t *property; + surface_t *data; + float param[4]; + float sum; + + for (int layer = 0; layer < 100; layer++) + { + if (m->Property (layer + 1) == NULL) + { + property = new property_t; // delete : dot.cc l59 + property->kind = surface; + property->size = sizeof (surface_t); + data = new surface_t; // delete : dot.cc l58 + property->data = data; + m->Set_property (layer + 1, property); + } + else + { + property = static_cast (m->Property (layer + 1)); + data = static_cast (property->data); + } + param[0] = 3 * m->x () * 2; + param[1] = 3 * m->y () * 2; + param[2] = 3 * m->z () * 2; + param[3] = (-(layer)/3.0 + glagen.float_time + 20) / 20.0; + sum = GLG_Perlin_noise_4D (param); + sum = sum * sum; + sum = sum * sum; + data->height = 0.01 + 0.006 * layer; + data->red = 1; + data->green = 0.8 - 7 * sum; + data->blue = 0; + data->alpha = 0.005 + (120 * sum) / (sqrtf((layer + 1.0) / 71) * 71); + } +} + +// +// Un essai de simulation de sol +// +void essai_terrain (Dot *m, unsigned int level) +{ + property_t *property; + surface_t *data; + unsigned int alpha; + float param[3]; + float sum; + + if (m->Property (0) == NULL) + { + property = new property_t; // delete : dot.cc l59 + property->kind = surface; + property->size = sizeof (surface_t); + data = new surface_t; // delete : dot.cc l58 + property->data = data; + m->Set_property (0, property); + } + else + { + property = static_cast (m->Property (0)); + data = static_cast (property->data); + } + + sum = 0; + alpha = 1; + param[0] = alpha * m->x () * 3; + param[1] = alpha * m->y () * 3; + param[2] = alpha * m->z () * 3; + sum = sum + GLG_Perlin_noise_3D (param) / (10.0 * alpha); + for (unsigned int current = 0; current < 2 * level; current++) + { + alpha = 2 * alpha; + param[0] = alpha * m->x () * 3; + param[1] = alpha * m->y () * 3; + param[2] = alpha * m->z () * 3; + sum = sum + GLG_Perlin_noise_3D (param) / (10.0 * alpha); + } + + if (sum < 0) + data->height = 0; + else + data->height = sum; // 10; + + if (data->height <= 0) + { + data->red = 0.0; + data->green = 0.015 * (1 - sum); + data->blue = 0.40 * (1 - sum); + } + else + { + if (data->height < 0.005) + { + data->red = 0.52; + data->green = 0.46; + data->blue = 0.28; + } + else + if (data->height > 0.04) + { + if (data->height > 0.0055) + { + data->red = 0.9 + 4 * data->height; + data->green = 0.9 + 4 * data->height; + data->blue = 0.9 + 4 * data->height; + } + else + { + data->red = 0.55; + data->green = 0.41; + data->blue = 0.28; + } + } + else + { + data->red = 0.35; + data->green = 0.5; + data->blue = 0.21; + } + } + data->alpha = 1; +} + +// +// Un autre essai de simulation de sol +// +void essai_terrain_mono (Dot *m, unsigned int level) +{ + property_t *property; + surface_t *data; + unsigned int alpha; + float param[3]; + float sum; + + if (m->Property (0) == NULL) + { + property = new property_t; // delete : dot.cc l59 + property->kind = surface; + property->size = sizeof (surface_t); + data = new surface_t; // delete : dot.cc l58 + property->data = data; + m->Set_property (0, property); + } + else + { + property = static_cast (m->Property (0)); + data = static_cast (property->data); + } + + sum = 0; + alpha = 1; + param[0] = alpha * m->x () * 3; + param[1] = alpha * m->y () * 3; + param[2] = alpha * m->z () * 3; + sum = sum + GLG_Perlin_noise_3D (param) / (10.0 * alpha); + for (unsigned int current = 0; current < 2 * level; current++) + { + alpha = 2 * alpha; + param[0] = alpha * m->x () * 3; + param[1] = alpha * m->y () * 3; + param[2] = alpha * m->z () * 3; + sum = sum + GLG_Perlin_noise_3D (param) / (10.0 * alpha); + } + +// if (sum < 0) +// data->height = 0; +// else + data->height = sum * 2; + + data->red = 1; + data->green = 1; + data->blue = 1; + data->alpha = 1; +} + +// +// La planete rouge +// +void essai_mars (Dot *m, unsigned int level) +{ + property_t *property; + surface_t *data; + unsigned int alpha; + float param[3]; + float sum; + + if (m->Property (0) == NULL) + { + property = new property_t; // delete : dot.cc l59 + property->kind = surface; + property->size = sizeof (surface_t); + data = new surface_t; // delete : dot.cc l58 + property->data = data; + m->Set_property (0, property); + } + else + { + property = static_cast (m->Property (0)); + data = static_cast (property->data); + } + + sum = 0; + alpha = 1; + param[0] = m->x () * 3; + param[1] = m->y () * 3; + param[2] = m->z () * 3; + sum = sum + GLG_Perlin_noise_3D (param) / 10.0; + for (unsigned int current = 0; current < 2 * level; current++) + { + alpha = 2 * alpha; + param[0] = m->x () * 3 * alpha; + param[1] = m->y () * 3 * alpha; + param[2] = m->z () * 3 * alpha; + sum = sum + GLG_Perlin_noise_3D (param) / (10.0 * alpha); + } + + // + // - 0.2 < sum < 0.2 + // + + data->height = sum; + + if (data->height <= 0) + { +// data->red = 0.0; +// data->green = 1.0; +// data->blue = 1.0; + data->red = 0.07 + 0.70 / (-sum); + data->green = 0.07 + 0.20 / (-sum); + data->blue = 0.05; + } + else + { + data->red = 0.77 + (1.05 * sum); + data->green = 0.27 + (1.25 * sum); + data->blue = 0.05 + (0.17 * sum); + } + data->alpha = 1; +} + +// +// Un effet colore sympatique +// +void essai_sympa (Dot *m, unsigned int level) +{ + property_t *property; + surface_t *data; + unsigned int alpha; + float param[4]; + float sum; + int sum_int; + + if (m->Property (0) == NULL) + { + property = new property_t; // delete : dot.cc l59 + property->kind = surface; + property->size = sizeof (surface_t); + data = new surface_t; // delete : dot.cc l58 + property->data = data; + m->Set_property (0, property); + } + else + { + property = static_cast (m->Property (0)); + data = static_cast (property->data); + } + + sum = 0; + alpha = 1; + param[0] = alpha * m->x () * 3; + param[1] = alpha * m->y () * 3; + param[2] = alpha * m->z () * 3; + param[3] = glagen.float_time; + sum = sum + GLG_Perlin_noise_3D (param) / (10.0 * alpha); + for (unsigned int current = 0; current < 2 * level; current++) + { + alpha = 2 * alpha; + param[0] = alpha * m->x () * 3; + param[1] = alpha * m->y () * 3; + param[2] = alpha * m->z () * 3; + param[3] = alpha * glagen.float_time; + sum = sum + GLG_Perlin_noise_3D (param) / (10.0 * alpha); + } + data->height = 0; + sum_int = (int)(1200 * ((10 * sum) + 0.5)); +// data->red = ((sum_int % 200) * 6) / 1200.0; +// data->green = ((sum_int % 120) * 10) / 1200.0; +// data->blue = ((sum_int % 100) * 12) / 1200.0; + data->red = ((sum_int % 1200) * 1) / 1200.0; + data->green = ((sum_int % 1200) * 1) / 1200.0; + data->blue = ((sum_int % 600) * 2) / 1200.0; + data->alpha = 1; +} + +void simule_lib_load () +{ +// glagen.library[0].kind = none; + +// glagen.library[0].kind = surface; +// glagen.library[0].dynamic = false; +// glagen.library[0].run = essai_terrain; +// glagen.library[0].name = "Terrain"; + +// glagen.library[0].kind = surface; +// glagen.library[0].dynamic = false; +// glagen.library[0].run = essai_terrain_mono; +// glagen.library[0].name = "Relief"; + +// glagen.library[0].kind = surface; +// glagen.library[0].dynamic = false; +// glagen.library[0].run = essai_sympa; +// glagen.library[0].name = "Couleurs"; + + glagen.library[0].kind = surface; + glagen.library[0].dynamic = true; + glagen.library[0].run = surface_solaire; + glagen.library[0].name = "surface_solaire"; + +// glagen.library[1].kind = surface; +// glagen.library[1].dynamic = true; +// glagen.library[1].run = atmosphere_solaire; +// glagen.library[1].name = "atmosphere_solaire"; + + // Don't forget the end marker : + glagen.library[1].kind = none; +} diff --git a/3d/simul.hh b/3d/simul.hh new file mode 100644 index 0000000..cf2bd68 --- /dev/null +++ b/3d/simul.hh @@ -0,0 +1,41 @@ +//============================================================================= +// +// Glagen : a planet sized landscape generator +// Copyright (C) 2002 Julien Guertault, Hugues Hiegel, Meng-Tih Lam +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// +//============================================================================= +// +// Glagen : GPL LAndscape GENerator +// +// simul.hh for Glagen : made by Zavie (Julien Guertault) +// +// www.glagen.org +// +//============================================================================= + +#ifndef SIMUL_HH_ +# define SIMUL_HH_ + +#include "dot.hh" + +void surface_solaire (Dot *, unsigned int); +void atmosphere_solaire (Dot *, unsigned int); +void essai_terrain (Dot *, unsigned int); +void simule_lib_load (); + + +#endif // SIMUL_HH_ diff --git a/3d/time.hh b/3d/time.hh new file mode 100644 index 0000000..8afe7ed --- /dev/null +++ b/3d/time.hh @@ -0,0 +1,36 @@ +//============================================================================= +// +// Glagen : a planet sized landscape generator +// Copyright (C) 2002 Julien Guertault, Hugues Hiegel, Meng-Tih Lam +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// +//============================================================================= +// +// Glagen : GPL LAndscape GENerator +// +// time.hh for Glagen : made by Zavie (Julien Guertault) +// +// www.glagen.org +// +//============================================================================= + +#ifndef TIME_HH_ +# define TIME_HH_ + +void init_time (); +void update_time (); + +#endif // TIME_HH_ diff --git a/3d/time_unix.cc b/3d/time_unix.cc new file mode 100644 index 0000000..013e2a6 --- /dev/null +++ b/3d/time_unix.cc @@ -0,0 +1,51 @@ +//============================================================================= +// +// Glagen : a planet sized landscape generator +// Copyright (C) 2002 Julien Guertault, Hugues Hiegel, Meng-Tih Lam +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// +//============================================================================= +// +// Glagen : GPL LAndscape GENerator +// +// time_unix.cc for Glagen : made by Zavie (Julien Guertault) +// +// www.glagen.org +// +//============================================================================= + +#include +#include +#include "data_glagen.hh" + + +void init_time () +{ + if (gettimeofday (&(glagen.time), NULL) != 0) + exit (errno); + glagen.start_time = glagen.time.tv_sec; + glagen.time.tv_sec = 0; + glagen.float_time = (glagen.time.tv_usec / 1000) / 1000.0; +} + +void update_time () +{ + if (gettimeofday (&(glagen.time), NULL) != 0) + exit (errno); + glagen.time.tv_sec = glagen.time.tv_sec - glagen.start_time; + glagen.float_time = (glagen.time.tv_sec + + (glagen.time.tv_usec / 1000) / 1000.0); +} diff --git a/3d/time_windows.cc b/3d/time_windows.cc new file mode 100644 index 0000000..32a5d3d --- /dev/null +++ b/3d/time_windows.cc @@ -0,0 +1,53 @@ +//============================================================================= +// +// Glagen : a planet sized landscape generator +// Copyright (C) 2002 Julien Guertault, Hugues Hiegel, Meng-Tih Lam +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// +//============================================================================= +// +// Glagen : GPL LAndscape GENerator +// +// time_windows.cc for Glagen : made by Zavie (Julien Guertault) +// +// www.glagen.org +// +//============================================================================= + +#include +#include "data_glagen.hh" + +void init_time () +{ + int s = GetTickCount() / 1000; + int ms = GetTickCount() % 1000; + + glagen.start_time = s; + glagen.time.tv_sec = 0; + glagen.time.tv_usec = ms * 1000; + glagen.float_time = (glagen.time.tv_usec / 1000) / 1000.0; +} + +void update_time () +{ + int s = GetTickCount() / 1000; + int ms = GetTickCount() % 1000; + + glagen.time.tv_sec = s - glagen.start_time; + glagen.time.tv_usec = ms * 1000; + glagen.float_time = (glagen.time.tv_sec + + (glagen.time.tv_usec / 1000) / 1000.0); +} diff --git a/3d/triangle.cc b/3d/triangle.cc new file mode 100644 index 0000000..ee80216 --- /dev/null +++ b/3d/triangle.cc @@ -0,0 +1,729 @@ +//============================================================================= +// +// Glagen : a planet sized landscape generator +// Copyright (C) 2002 Julien Guertault, Hugues Hiegel, Meng-Tih Lam +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// +//============================================================================= +// +// Glagen : GPL LAndscape GENerator +// +// triangle.cc for Glagen : made by Zavie (Julien Guertault) +// +// www.glagen.org +// +//============================================================================= + +#include +#include +#include "data_glagen.hh" +#include "dot.hh" +#include "misc.hh" +#include "triangle.hh" +#include "vector.hh" + +// ================================================= Constructor and destructor + +Triangle :: Triangle (Dot *a, + Dot *b, + Dot *c, + Triangle *father): + _a(a), _b(b), _c(c), + _neighbor_ab(NULL), _neighbor_bc(NULL), _neighbor_ca(NULL), + _father(father), + _child_a(NULL), _child_b(NULL), _child_c(NULL), _child_center(NULL), + _visible(true) +{ + Vector v1; + Vector v2; + + glagen.triangles = glagen.triangles + 1; + if (glagen.triangles > glagen.max_triangles) + exit (1); + if (father == NULL) + _level = 0; + else + _level = father->Level () + 1; + + a->Use (father, this); + b->Use (father, this); + c->Use (father, this); + + _center = Vector ((a->x () + b->x () + c-> x()) / 3, + (a->y () + b->y () + c-> y()) / 3, + (a->z () + b->z () + c-> z()) / 3); + + v1 = Vector (a->x () - b->x (), a->y () - b->y (), a->z () - b->z ()); + v2 = Vector (a->x () - c->x (), a->y () - c->y (), a->z () - c->z ()); + _normal = Vector (v1 ^ v2); + _size = _normal.Norm (); + _normal = _normal / _size; + _normal_real = _normal; + _size = sqrtf (_size / 2); + + step = glagen.step - 1; +} + +Triangle :: ~Triangle () +{ + if (_child_center != NULL) + { + delete _child_center; + delete _child_a; + delete _child_b; + delete _child_c; + } + + // Del the old connexity + if (_neighbor_ab != NULL) + _neighbor_ab->Del_connexity (this); + if (_neighbor_bc != NULL) + _neighbor_bc->Del_connexity (this); + if (_neighbor_ca != NULL) + _neighbor_ca->Del_connexity (this); + + // Tell the vertices they aren't used by this triangle anymore + if (_a->Drop (this, _father)) + delete _a; + if (_b->Drop (this, _father)) + delete _b; + if (_c->Drop (this, _father)) + delete _c; + + if (_father != NULL) + _father->Child_dead (this); + + glagen.triangles = glagen.triangles - 1; +} + + +// ======================================================================= Read + +// The level +unsigned int Triangle :: Level () const { return _level; } + +// The vertices +Dot *Triangle :: A () const { return _a; } +Dot *Triangle :: B () const { return _b; } +Dot *Triangle :: C () const { return _c; } + +// The neighborhood +Triangle *Triangle :: Neighbor_ab () const { return _neighbor_ab; } +Triangle *Triangle :: Neighbor_bc () const { return _neighbor_bc; } +Triangle *Triangle :: Neighbor_ca () const { return _neighbor_ca; } + +// The father +Triangle *Triangle :: Father () const { return _father; } + +// The childs +Triangle *Triangle :: Child_a() const { return _child_a; } +Triangle *Triangle :: Child_b() const { return _child_b; } +Triangle *Triangle :: Child_c() const { return _child_c; } +Triangle *Triangle :: Child_center() const { return _child_center; } +Triangle *Triangle :: Child (Dot *match) const +{ + if (match == _a) + return _child_a; + if (match == _b) + return _child_b; + if (match == _c) + return _child_c; + return NULL; +} + +Vector &Triangle :: Normal () { return _normal; } +Vector &Triangle :: Normal_real () { return _normal_real; } + +float Triangle :: Size () const { return _size; } + +// Is this triangle split ? +bool Triangle :: Is_split () const +{ + return (_child_center != NULL); +} + +// In the current turn, has this triangle been checked ? +bool Triangle :: Is_checked () const +{ + return (step == glagen.step); +} + +// According to the position of the observer, does this triangle +// need to be split ? +float Triangle :: To_split () const +{ + float x = _center.X () - glagen.observer.frame.Origin_X (); + float y = _center.Y () - glagen.observer.frame.Origin_Y (); + float z = _center.Z () - glagen.observer.frame.Origin_Z (); +// float dist = x * x + y * y + z * z; + float dist = Approx_dist(x, y, z); +// float alpha = dist / (_size * _size); + float alpha = (dist * dist) / (_size * _size); + + // Special case : + // if over the horizon, the result is increased +// if (dist > 100 * glagen.observer.altitude * glagen.observer.altitude) + if (dist > 10 * glagen.observer.altitude) + alpha = alpha * alpha / 2; +// if (dist > 1000 * glagen.observer.altitude * glagen.observer.altitude) + if (dist > 32 * glagen.observer.altitude) + alpha = alpha * alpha / 2; + if (!_visible) + alpha = (alpha * alpha) / 2; + return (alpha); +} + +// According to the position of the observer, does this triangle +// need to be merged ? +bool Triangle :: Is_visible () const { return _visible; } + +// ====================================================================== Write + +// This triangle must set a reference to the given other one +void Triangle :: Make_connexity (Triangle *neighborhood) +{ + // Find on which side is the other triangle and then set the connexity + if ((neighborhood->A () == _a) + || (neighborhood->B () == _a) + || (neighborhood->C () == _a)) + { + if ((neighborhood->A () == _b) + || (neighborhood->B () == _b) + || (neighborhood->C () == _b)) + _neighbor_ab = neighborhood; + else + _neighbor_ca = neighborhood; + } + else + _neighbor_bc = neighborhood; +} + +// This triangle must forget its reference to the given other one +void Triangle :: Del_connexity (Triangle *related) +{ + // Find the connexity and delete it + if (_neighbor_ab == related) + _neighbor_ab = NULL; + if (_neighbor_bc == related) + _neighbor_bc = NULL; + if (_neighbor_ca == related) + _neighbor_ca = NULL; +} + +// The split function +void Triangle :: Split () +{ + Dot *d; + Dot *e; + Dot *f; + Triangle *neighbor_af; + Triangle *neighbor_ae; + Triangle *neighbor_bd; + Triangle *neighbor_bf; + Triangle *neighbor_ce; + Triangle *neighbor_cd; + + // Test if the triangle is already split + if (Is_split ()) + return; + + // Check the differences of iterations + if (_neighbor_ab == NULL || _neighbor_bc == NULL || _neighbor_ca == NULL) + _father->Split_neighbor(); + + // Find / create vertex + if (_neighbor_bc->Is_split ()) + { + // Identify and save the future connexity + neighbor_bd = _neighbor_bc->Child (_b); + neighbor_cd = _neighbor_bc->Child (_c); + + // Pop the vertex to use + if (neighbor_bd->B () == neighbor_cd->C ()) + d = neighbor_bd->B (); + else + d = neighbor_bd->C (); + } + else + { + // Create the vertex and set the connexity to NULL + d = _b->Middle (_c); // new ; delete : triangle.cc l99, 101, 103 + neighbor_bd = NULL; + neighbor_cd = NULL; + } + + // The same for each side + if (_neighbor_ca->Is_split ()) + { + neighbor_ce = _neighbor_ca->Child (_c); + neighbor_ae = _neighbor_ca->Child (_a); + if (neighbor_ce->B () == neighbor_ae->C ()) + e = neighbor_ce->B (); + else + e = neighbor_ce->C (); + } + else + { + e = _c->Middle (_a); // new ; delete : triangle.cc l99, 101, 103 + neighbor_ce = NULL; + neighbor_ae = NULL; + } + + if (_neighbor_ab->Is_split ()) + { + neighbor_af = _neighbor_ab->Child (_a); + neighbor_bf = _neighbor_ab->Child (_b); + if (neighbor_af->B () == neighbor_bf->C ()) + f = neighbor_af->B (); + else + f = neighbor_af->C (); + } + else + { + f = _a->Middle (_b); // new ; delete : triangle.cc l99, 101, 103 + neighbor_af = NULL; + neighbor_bf = NULL; + } + + // Create triangles + _child_center = new Triangle (d, e, f, this); // delete : triangle.cc l90 + _child_a = new Triangle (_a, f, e, this); // delete : triangle.cc l91 + _child_b = new Triangle (_b, d, f, this); // delete : triangle.cc l92 + _child_c = new Triangle (_c, e, d, this); // delete : triangle.cc l93 + + // Set the final connexity + if (neighbor_af != NULL) + { + _child_a->Make_connexity (neighbor_af); + neighbor_af->Make_connexity (_child_a); + } + if (neighbor_ae != NULL) + { + _child_a->Make_connexity (neighbor_ae); + neighbor_ae->Make_connexity (_child_a); + } + if (neighbor_bd != NULL) + { + _child_b->Make_connexity (neighbor_bd); + neighbor_bd->Make_connexity (_child_b); + } + if (neighbor_bf != NULL) + { + _child_b->Make_connexity (neighbor_bf); + neighbor_bf->Make_connexity (_child_b); + } + if (neighbor_ce != NULL) + { + _child_c->Make_connexity (neighbor_ce); + neighbor_ce->Make_connexity (_child_c); + } + if (neighbor_cd != NULL) + { + _child_c->Make_connexity (neighbor_cd); + neighbor_cd->Make_connexity (_child_c); + } + + _child_a->Make_connexity (_child_center); + _child_b->Make_connexity (_child_center); + _child_c->Make_connexity (_child_center); + _child_center->Make_connexity (_child_a); + _child_center->Make_connexity (_child_b); + _child_center->Make_connexity (_child_c); + + // Check for chained reactions + if (_neighbor_ab != NULL) + _neighbor_ab->Check_T (); + if (_neighbor_bc != NULL) + _neighbor_bc->Check_T (); + if (_neighbor_ca != NULL) + _neighbor_ca->Check_T (); +} + +// Check if a triangle needs to be split just because too many +// triangles in the neighborhood are split. +void Triangle :: Check_T () +{ + int warning; + + // The T problem only occurs if the triangle isn't Split + if (_child_center != NULL) + return; + warning = 0; + if (_neighbor_ab != NULL) + if (_neighbor_ab->Is_split ()) + warning = warning + 1; + if (_neighbor_bc != NULL) + if (_neighbor_bc->Is_split ()) + warning = warning + 1; + if (_neighbor_ca != NULL) + if (_neighbor_ca->Is_split ()) + warning = warning + 1; + if (warning > 1) + Split (); +} + +// The big merging function : we are not sure it will really merge +// the triangle, but at least, it will merge the children. +void Triangle :: Merge () +{ + unsigned char i; + + if (Is_split()) + { + // First we merge the children + _child_center->Merge_simple (); + _child_a->Merge_simple (); + _child_b->Merge_simple (); + _child_c->Merge_simple (); + + // Then we check the neighborhood + i = 0; + if (_neighbor_ab != NULL) + if (_neighbor_ab->Is_split ()) + { + _neighbor_ab->Front_attack (_a, _b); + i = i + 1; + } + if (_neighbor_bc != NULL) + if (_neighbor_bc->Is_split ()) + { + _neighbor_bc->Front_attack (_b, _c); + i = i + 1; + } + if (_neighbor_ca != NULL) + if (_neighbor_ca->Is_split ()) + { + _neighbor_ca->Front_attack (_c, _a); + i = i + 1; + } + + // If there's only one split neighbor triangle, then we can + // also destroy the children. Else we can't because it would + // have too much unexpected effects + if (i < 2) + { + // Destroy the child + delete _child_center; + delete _child_a; + delete _child_b; + delete _child_c; + + // Don't forget to change the pointers ! + _child_center = NULL; + _child_a = NULL; + _child_b = NULL; + _child_c = NULL; + } + } +} + +// Just a merge function without T case management +void Triangle :: Merge_simple () +{ + if (_child_center != NULL) + { + // Recursive merge + _child_center->Merge_simple (); + _child_a->Merge_simple (); + _child_b->Merge_simple (); + _child_c->Merge_simple (); + + // Destroy the child + delete _child_center; + delete _child_a; + delete _child_b; + delete _child_c; + + // Don't forget to change the pointers ! + _child_center = NULL; + _child_a = NULL; + _child_b = NULL; + _child_c = NULL; + } +} + +// Check the triangle for T cases when the neigbor triangle is merged +void Triangle :: Front_attack (Dot *quad_a, Dot *quad_d) +{ + Dot *quad_b; + Dot *quad_c; + Triangle *triangle_ab; + Triangle *triangle_cd; + Triangle *last_child; + + triangle_ab = Child (quad_a); + triangle_cd = Child (quad_d); + if (quad_a == _a) + { + if (quad_d == _b) + last_child = _child_c; + else + last_child = _child_b; + } + else + if (quad_a == _b) + { + if (quad_d == _c) + last_child = _child_a; + else + last_child = _child_c; + } + else + if (quad_d == _a) + last_child = _child_b; + else + last_child = _child_a; + + triangle_ab->Merge_simple (); + _child_center->Merge_simple (); + triangle_cd->Merge_simple (); + + if (triangle_ab->B () == triangle_cd->C ()) + { + quad_b = triangle_ab->C (); + quad_c = triangle_cd->B (); + if (triangle_ab->Neighbor_ca () != NULL) + if (triangle_ab->Neighbor_ca ()->Is_split ()) + triangle_ab->Neighbor_ca ()->Front_attack (quad_a, quad_b); + if (triangle_cd->Neighbor_ab () != NULL) + if (triangle_cd->Neighbor_ab ()->Is_split ()) + triangle_cd->Neighbor_ab ()->Front_attack (quad_c, quad_d); + } + else + { + quad_b = triangle_ab->B (); + quad_c = triangle_cd->C (); + if (triangle_ab->Neighbor_ab () != NULL) + if (triangle_ab->Neighbor_ab ()->Is_split ()) + triangle_ab->Neighbor_ab ()->Front_attack (quad_a, quad_b); + if (triangle_cd->Neighbor_ca () != NULL) + if (triangle_cd->Neighbor_ca ()->Is_split ()) + triangle_cd->Neighbor_ca ()->Front_attack (quad_c, quad_d); + } + if (last_child->Is_split ()) + last_child->Front_attack (quad_b, quad_c); +} + +// Check all the triangles to apply split or merge +void Triangle :: Split_visitor () +{ + if (step == glagen.step) + return; + step = glagen.step; + + float to_split = To_split (); + + if (to_split != 0) + { + if (to_split > 350) + Merge (); + else + { + if (glagen.triangles <= glagen.max_triangles) + if (to_split < 300) + if (false == Is_split ()) + Split (); + + if (Is_split ()) + { + // We check the childs + _child_center->Split_visitor (); + _child_a->Split_visitor (); + _child_b->Split_visitor (); + _child_c->Split_visitor (); + } + } + } + + // If there's no father, it means it's one of the root + // triangles and we can go to check the neighborhood + if (NULL == _father) + { + _neighbor_ab->Split_visitor (); + _neighbor_bc->Split_visitor (); + _neighbor_ca->Split_visitor (); + } +} + +// The visitor that computes if a triangle is visible or not. +bool Triangle :: Hide_visitor () +{ + if (step != glagen.step) + { + step = glagen.step; + if (Is_split ()) + { + _visible = _child_a->Hide_visitor (); + _visible = _child_b->Hide_visitor () || _visible; + _visible = _child_c->Hide_visitor () || _visible; + _visible = _child_center->Hide_visitor () || _visible; + } + else + { + // Let compute if it is visible... + + // We construct the vector from the center of to planet to + // the observer + Vector v = Vector (glagen.observer.frame.Origin_X () - _center.X (), + glagen.observer.frame.Origin_Y () - _center.Y (), + glagen.observer.frame.Origin_Z () - + _center.Z ()); + // We compute the scalar product to know how far it is + _visible = ((_normal * v) > 0); + + // Now, let compute if it is in the vision field + if (_visible == true) + { + v.Approx_normalize (); + _visible = (v * glagen.observer.frame.Basis_Z () < -0.70); + } + } + + // If there's no father, it means it's one of the root + // triangles and we can go to check the neighborhood + if (NULL == _father) + { + _neighbor_ab->Hide_visitor (); + _neighbor_bc->Hide_visitor (); + _neighbor_ca->Hide_visitor (); + } + } + return _visible; +} + +// Called by a child when deleted +void Triangle :: Child_dead (Triangle *child) +{ + if (_child_center == child) + _child_center = NULL; + if (_child_a == child) + _child_a = NULL; + if (_child_b == child) + _child_b = NULL; + if (_child_c == child) + _child_c = NULL; +} + +// This triangle is checked +void Triangle :: Checked () { step = glagen.step; } + + +// ====================================================================== Other + +// Split the neighborhood triangles +void Triangle :: Split_neighbor () +{ + if (_neighbor_ab != NULL) + _neighbor_ab->Split (); + if (_neighbor_bc != NULL) + _neighbor_bc->Split (); + if (_neighbor_ca != NULL) + _neighbor_ca->Split (); +} + +// Update the normal vector, if the triangle is moving. +void Triangle :: Update_normal () +{ + surface_t *surface; + float adjust = 0; + + // Get the position of the dot A + if (glagen.display_planet == true) + { + if (NULL == _a->Property (0)) + adjust = 0; + else + { + surface = static_cast (_a->Property (0)->data); + if (NULL == surface) + adjust = 0; + else + adjust = surface->height; + } + } + float ax = _a->x () * (glagen.size + adjust); + float ay = _a->y () * (glagen.size + adjust); + float az = _a->z () * (glagen.size + adjust); + + // Get the position of the dot B + if (glagen.display_planet) + { + if (NULL == _b->Property (0)) + adjust = 0; + else + { + surface = static_cast (_b->Property (0)->data); + if (NULL == surface) + adjust = 0; + else + adjust = surface->height; + } + } + float bx = _b->x () * (glagen.size + adjust); + float by = _b->y () * (glagen.size + adjust); + float bz = _b->z () * (glagen.size + adjust); + + // Get the position of the dot C + if (glagen.display_planet) + { + if (NULL == _c->Property (0)) + adjust = 0; + else + { + surface = static_cast (_c->Property (0)->data); + if (NULL == surface) + adjust = 0; + else + adjust = surface->height; + } + } + float cx = _c->x () * (glagen.size + adjust); + float cy = _c->y () * (glagen.size + adjust); + float cz = _c->z () * (glagen.size + adjust); + + Vector v1 = Vector (ax - bx, ay - by, az - bz); + Vector v2 = Vector (ax - cx, ay - cy, az - cz); + _normal_real = Vector (v1 ^ v2); + _normal_real.Normalize (); +} + +void Triangle :: Update_normal_visitor () +{ + if (step == glagen.step) + return; + step = glagen.step; + + Update_normal (); + + if (_child_center != NULL) + { + _child_center->Update_normal_visitor (); + _child_a->Update_normal_visitor (); + _child_b->Update_normal_visitor (); + _child_c->Update_normal_visitor (); + } + + if (NULL == _father) + { + _neighbor_ab->Update_normal_visitor (); + _neighbor_bc->Update_normal_visitor (); + _neighbor_ca->Update_normal_visitor (); + } + + _a->Update_normal (); + _b->Update_normal (); + _c->Update_normal (); +} diff --git a/3d/triangle.hh b/3d/triangle.hh new file mode 100644 index 0000000..3a3903f --- /dev/null +++ b/3d/triangle.hh @@ -0,0 +1,122 @@ +//============================================================================= +// +// Glagen : a planet sized landscape generator +// Copyright (C) 2002 Julien Guertault, Hugues Hiegel, Meng-Tih Lam +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// +//============================================================================= +// +// Glagen : GPL LAndscape GENerator +// +// triangle.hh for Glagen : made by Zavie (Julien Guertault) +// +// www.glagen.org +// +//============================================================================= + +#ifndef TRIANGLE_HH_ +# define TRIANGLE_HH_ + +#include +#include "data_glagen.hh" +#include "dot.hh" +#include "vector.hh" + +class Triangle +{ +public: + + //Constructor and destructor + Triangle (class Dot *, class Dot *, class Dot *, Triangle *); + ~Triangle (); + + // Read + unsigned int Level () const; + + Dot *A () const; + Dot *B () const; + Dot *C () const; + + Triangle *Neighbor_ab () const; + Triangle *Neighbor_bc () const; + Triangle *Neighbor_ca () const; + + Triangle *Father () const; + + Triangle *Child_a() const; + Triangle *Child_b() const; + Triangle *Child_c() const; + Triangle *Child_center() const; + Triangle *Child (Dot *match) const; + + Vector &Normal (); + Vector &Normal_real (); + + float Size () const; + bool Is_split () const; + bool Is_checked () const; + float To_split () const; + bool Is_visible () const; + + // Write + void Make_connexity (Triangle *); + void Del_connexity (Triangle *); + void Split (); + void Check_T (); + void Merge (); + void Merge_simple (); + void Front_attack (Dot *, Dot *); + void Split_visitor (); + bool Hide_visitor (); + void Child_dead (Triangle *); + void Checked (); + + // Other + void Split_neighbor (); + void Update_normal (); + void Update_normal_visitor (); + bool T_case (const unsigned int); + void Display (const unsigned int); + +protected: + unsigned int _level; + + Dot *_a; + Dot *_b; + Dot *_c; + + Triangle *_neighbor_ab; + Triangle *_neighbor_bc; + Triangle *_neighbor_ca; + + Triangle *_father; + + Triangle *_child_a; + Triangle *_child_b; + Triangle *_child_c; + Triangle *_child_center; + + bool _visible; + + Vector _center; + Vector _normal; + Vector _normal_real; + float _size; + + char step; +}; + +#endif // TRIANGLE_HH_ diff --git a/3d/triangle_gl.cc b/3d/triangle_gl.cc new file mode 100644 index 0000000..173db4f --- /dev/null +++ b/3d/triangle_gl.cc @@ -0,0 +1,180 @@ +//============================================================================= +// +// Glagen : a planet sized landscape generator +// Copyright (C) 2002 Julien Guertault, Hugues Hiegel, Meng-Tih Lam +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// +//============================================================================= +// +// Glagen : GPL LAndscape GENerator +// +// triangle.cc for Glagen : made by Zavie (Julien Guertault) +// +// www.glagen.org +// +//============================================================================= + +#ifndef DARWIN +# include +# include +#else +# include +# include +#endif + +#include "data_glagen.hh" +#include "dot.hh" +#include "triangle.hh" + +// +// Manage the T-case (when the has a 4th point) +// +bool Triangle :: T_case (const unsigned int id) +{ + Dot *middle; + Triangle *child1; + Triangle *child2; + + // Is there a triangle on this side ? + if (_neighbor_ab != NULL) + + // Then is it split ? + if (_neighbor_ab->Is_split ()) + { + // Find the dangling vertex + child1 = _neighbor_ab->Child (_a); + child2 = _neighbor_ab->Child (_b); + if (child1->B () == child2->C ()) + middle = child1->B (); + else + middle = child1->C (); + + // Display two triangles instead of just one + glBegin (GL_TRIANGLES); + _b->Display (id); + _c->Display (id); + middle->Display (id); + _c->Display (id); + _a->Display (id); + middle->Display (id); + glEnd (); + + // The T case is fixed + return true; + } + if (_neighbor_bc != NULL) + if (_neighbor_bc->Is_split ()) + { + child1 = _neighbor_bc->Child (_b); + child2 = _neighbor_bc->Child (_c); + if (child1->B () == child2->C ()) + middle = child1->B (); + else + middle = child1->C (); + glBegin (GL_TRIANGLES); + _a->Display (id); + _b->Display (id); + middle->Display (id); + _c->Display (id); + _a->Display (id); + middle->Display (id); + glEnd (); + return true; + } + if (_neighbor_ca != NULL) + if (_neighbor_ca->Is_split ()) + { + child1 = _neighbor_ca->Child (_c); + child2 = _neighbor_ca->Child (_a); + if (child1->B () == child2->C ()) + middle = child1->B (); + else + middle = child1->C (); + glBegin (GL_TRIANGLES); + _b->Display (id); + _c->Display (id); + middle->Display (id); + _a->Display (id); + _b->Display (id); + middle->Display (id); + glEnd (); + return true; + } + // In fact there's no T-case for this triangle + return false; +} + +// +// Display the faces included in the triangle (general case) +// +void Triangle :: Display (const unsigned int id) +{ + // Test if this triangle has been visited yet + if (step == glagen.step) + return; + step = glagen.step; + + if (glagen.display_all == true || _visible == true) + { + // If the triangle has childs, we visit them instead + if (_child_center != NULL) + { + _child_a->Display (id); + _child_b->Display (id); + _child_c->Display (id); + _child_center->Display (id); + } + else + { + // T-case managment + if (false == T_case (id)) + { + if (glagen.display_normal == true) + { + float x = (_a->x () + _b->x () + _c->x ()) / 3; + float y = (_a->y () + _b->y () + _c->y ()) / 3; + float z = (_a->z () + _b->z () + _c->z ()) / 3; + + // Display the normal vector + if (glagen.light) + glDisable(GL_LIGHTING); + glBegin (GL_LINES); + glColor3f(1.0, 0.2, 0.0); + glVertex3f(x, y, z); + glVertex3f(x + _normal_real.X () / 100, + y + _normal_real.Y () / 100, + z + _normal_real.Z () / 100); + glEnd (); + if (glagen.light) + glEnable(GL_LIGHTING); + } + // Could it be more simple ? + glBegin (GL_TRIANGLES); + _a->Display (id); + _b->Display (id); + _c->Display (id); + glEnd (); + } + } + } + // Recursive call at the top of the three + if (NULL == Father ()) + { + _neighbor_ab->Display (id); + _neighbor_bc->Display (id); + _neighbor_ca->Display (id); + } +} diff --git a/3d/vector.cc b/3d/vector.cc new file mode 100644 index 0000000..06e3085 --- /dev/null +++ b/3d/vector.cc @@ -0,0 +1,252 @@ +//============================================================================= +// +// Glagen : a planet sized landscape generator +// Copyright (C) 2002 Julien Guertault, Hugues Hiegel, Meng-Tih Lam +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// +//============================================================================= +// +// Glagen : GPL LAndscape GENerator +// +// vector.cc for Glagen : made by Zavie (Julien Guertault) +// +// www.glagen.org +// +//============================================================================= + +#include +#include "data_glagen.hh" +#include "misc.hh" +#include "vector.hh" + +// ================================================ Constructors and destructor + +Vector :: Vector () +{ + vect[0] = 0; + vect[1] = 0; + vect[2] = 0; +} + +Vector :: Vector (const Vector &source) +{ + vect[0] = source.X (); + vect[1] = source.Y (); + vect[2] = source.Z (); +} + +Vector :: Vector (const float x, const float y, const float z) +{ + vect[0] = x; + vect[1] = y; + vect[2] = z; +} + +Vector :: ~Vector () {} + + +// ======================================================================= Read + +float Vector :: X () const { return vect[0]; } +float Vector :: Y () const { return vect[1]; } +float Vector :: Z () const { return vect[2]; } + +float Vector :: Norm () const +{ + return (sqrtf(vect[0] * vect[0] + + vect[1] * vect[1] + + vect[2] * vect[2])); +} + +// Fast norm approximation computing +float Vector :: Approx_norm () const +{ + return (Approx_dist(vect[0], vect[1], vect[2])); +} + + +// ====================================================================== Write + +void Vector :: Set (const float x, const float y, const float z) +{ + vect[0] = x; + vect[1] = y; + vect[2] = z; +} + +void Vector :: Set_X (const float x){ vect[0] = x;} +void Vector :: Set_Y (const float y){ vect[1] = y;} +void Vector :: Set_Z (const float z){ vect[2] = z;} + +void Vector :: Normalize () +{ + float norm = Norm (); + vect[0] = vect[0] / norm; + vect[1] = vect[1] / norm; + vect[2] = vect[2] / norm; +} + +void Vector :: Approx_normalize () +{ + float norm = Approx_norm (); + vect[0] = vect[0] / norm; + vect[1] = vect[1] / norm; + vect[2] = vect[2] / norm; +} + +void Vector :: Rotate (const Vector &axis, const float angle) +{ + float cosinus = cosf (angle); + float sinus = sinf (angle); + float cos_bis = (1 - cosinus) * axis.X (); + float cos_third = (1 - cosinus) * axis.Y (); + + float x = (cosinus + cos_bis * axis.X ()) * vect[0]; + x = x + (cos_bis * axis.Y () - axis.Z () * sinus) * vect[1]; + x = x + (cos_bis * axis.Z () + axis.Y () * sinus) * vect[2]; + + float y = (cos_bis * axis.Y () + axis.Z () * sinus) * vect[0]; + y = y + (cosinus + cos_third * axis.Y ()) * vect[1]; + y = y + (cos_third * axis.Z () - axis.X () * sinus) * vect[2]; + + float z = (cos_bis * axis.Z () - axis.Y () * sinus) * vect[0]; + z = z + (cos_third * axis.Z () + axis.X () * sinus) * vect[1]; + z = z + (cosinus + (1 - cosinus) * axis.Z () * axis.Z ()) * vect[2]; + + vect[0] = x; + vect[1] = y; + vect[2] = z; +} + + +// ================================================================== Operators + +// @ +// @ +// @@@@@ +// @ +// @ +Vector Vector :: operator + (const class Vector &v) const +{ + return Vector(vect[0] + v.X (), + vect[1] + v.Y (), + vect[2] + v.Z ()); +} + +// +// +// @@@@@ +// +// +Vector Vector :: operator - (const class Vector &v) const +{ + return Vector(vect[0] - v.X (), + vect[1] - v.Y (), + vect[2] - v.Z ()); +} + +// +// @ +// @@@ +// @ +// +float Vector :: operator * (const class Vector &v) const +{ + return (vect[0] * v.X () + + vect[1] * v.Y () + + vect[2] * v.Z ()); +} + +// @ +// @ @ +// @ @ +// +// +Vector Vector :: operator ^ (const class Vector &v) const +{ + return Vector((vect[1] * v.Z ()) - (vect[2] * v.Y ()), + (vect[2] * v.X ()) - (vect[0] * v.Z ()), + (vect[0] * v.Y ()) - (vect[1] * v.X ())); +} + +// @ +// @ @@@@@ +// @@@@@ +// @ @@@@@ +// @ +Vector Vector :: operator += (const class Vector &v) +{ + *this = *this + v; + return *this; +} + +// +// @@@@@ +// @@@@@ +// @@@@@ +// +Vector Vector :: operator -= (const class Vector &v) +{ + *this = *this - v; + return *this; +} + + +// @@@ +// @ @ +// @@@ @@@@ +// @ @ @ +// @@@ @ +Vector Vector :: operator * (const float &a) const +{ + return Vector(X () * a, + Y () * a, + Z () * a); +} + +// @ @@@ +// @ @ +// @ @@@@ +// @ @ @ +// @ @@@ @ +Vector Vector :: operator / (const float &a) const +{ + return Vector(X () / a, + Y () / a, + Z () / a); +} + +// @@@ +// @ @@@@@ @ +// @@@ @@@@ +// @ @@@@@ @ @ +// @@@ @ +Vector Vector :: operator *= (const float &a) +{ + *this = *this * a; + return *this; +} + +// @ @@@ +// @ @@@@@ @ +// @ @@@@ +// @ @@@@@ @ @ +// @ @@@ @ +Vector Vector :: operator /= (const float &a) +{ + *this = *this / a; + return *this; +} diff --git a/3d/vector.hh b/3d/vector.hh new file mode 100644 index 0000000..2a7a47f --- /dev/null +++ b/3d/vector.hh @@ -0,0 +1,77 @@ +//============================================================================= +// +// Glagen : a planet sized landscape generator +// Copyright (C) 2002 Julien Guertault, Hugues Hiegel, Meng-Tih Lam +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// +//============================================================================= +// +// Glagen : GPL LAndscape GENerator +// +// vector.hh for Glagen : made by Zavie (Julien Guertault) +// +// www.glagen.org +// +//============================================================================= + +#ifndef VECTOR_HH_ +# define VECTOR_HH_ + +class Vector +{ +public : + + // Constructors and destructor + Vector (); + Vector (const Vector &); + Vector (const float, const float, const float); + ~Vector (); + + // Read + float X () const; + float Y () const; + float Z () const; + + float Norm () const; + float Approx_norm () const; + + // Write + void Set (const float, const float, const float); + void Set_X (const float); + void Set_Y (const float); + void Set_Z (const float); + void Normalize (); + void Approx_normalize (); + void Rotate (const Vector &, const float); + + // Operators + Vector operator + (const class Vector &) const; + Vector operator - (const class Vector &) const; + float operator * (const class Vector &) const; + Vector operator ^ (const class Vector &) const; + Vector operator += (const class Vector &); + Vector operator -= (const class Vector &); + + Vector operator * (const float &) const; + Vector operator / (const float &) const; + Vector operator *= (const float &); + Vector operator /= (const float &); + +protected : + float vect[3]; +}; + +#endif -- cgit v1.2.3