From 3866f2b33313d891347f454537843befd295b78f Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Sat, 20 Oct 2007 10:02:51 +0000 Subject: Initial import. --- AUTHORS | 1 + COPYING | 340 +++++++++++++++++++++++++++++++++++++++++++++++ ChangeLog | 0 Doxyfile | 283 +++++++++++++++++++++++++++++++++++++++ INSTALL | 9 ++ Makefile.am | 5 + NEWS | 0 README | 17 +++ TODO | 0 configure.in | 90 +++++++++++++ osirion.kdevelop | 152 +++++++++++++++++++++ osirion.kdevelop.pcs | Bin 0 -> 92318 bytes osirion.kdevses | 32 +++++ src/Makefile.am | 6 + src/client/Makefile.am | 12 ++ src/client/camera.cc | 107 +++++++++++++++ src/client/camera.h | 44 ++++++ src/client/hud.cc | 0 src/client/hud.h | 0 src/client/input.cc | 86 ++++++++++++ src/client/input.h | 24 ++++ src/client/main.cc | 65 +++++++++ src/client/shipdrawer.cc | 108 +++++++++++++++ src/client/shipdrawer.h | 26 ++++ src/client/stardrawer | 0 src/client/stardrawer.cc | 22 +++ src/client/stardrawer.h | 26 ++++ src/client/video.cc | 109 +++++++++++++++ src/client/video.h | 30 +++++ src/client/view.cc | 153 +++++++++++++++++++++ src/client/view.h | 24 ++++ src/common/Makefile.am | 8 ++ src/common/color.cc | 84 ++++++++++++ src/common/color.h | 50 +++++++ src/common/functions.cc | 48 +++++++ src/common/functions.h | 42 ++++++ src/common/osirion.h | 11 ++ src/common/vector3f.cc | 151 +++++++++++++++++++++ src/common/vector3f.h | 138 +++++++++++++++++++ src/game/Makefile.am | 9 ++ src/game/game.cc | 31 +++++ src/game/game.h | 33 +++++ src/game/player.h | 20 +++ src/game/sector.h | 26 ++++ src/game/ship.cc | 85 ++++++++++++ src/game/ship.h | 54 ++++++++ src/game/star.cc | 17 +++ src/game/star.h | 29 ++++ src/game/world.h | 24 ++++ src/gl/Makefile.am | 10 ++ src/gl/box.cc | 96 +++++++++++++ src/gl/box.h | 41 ++++++ src/gl/osiriongl.cc | 214 +++++++++++++++++++++++++++++ src/gl/osiriongl.h | 158 ++++++++++++++++++++++ src/gl/sphere.cc | 89 +++++++++++++ src/gl/sphere.h | 50 +++++++ templates/cpp | 4 + templates/h | 4 + 58 files changed, 3297 insertions(+) create mode 100644 AUTHORS create mode 100644 COPYING create mode 100644 ChangeLog create mode 100644 Doxyfile create mode 100644 INSTALL create mode 100644 Makefile.am create mode 100644 NEWS create mode 100644 README create mode 100644 TODO create mode 100644 configure.in create mode 100644 osirion.kdevelop create mode 100644 osirion.kdevelop.pcs create mode 100644 osirion.kdevses create mode 100644 src/Makefile.am create mode 100644 src/client/Makefile.am create mode 100644 src/client/camera.cc create mode 100644 src/client/camera.h create mode 100644 src/client/hud.cc create mode 100644 src/client/hud.h create mode 100644 src/client/input.cc create mode 100644 src/client/input.h create mode 100644 src/client/main.cc create mode 100644 src/client/shipdrawer.cc create mode 100644 src/client/shipdrawer.h create mode 100644 src/client/stardrawer create mode 100644 src/client/stardrawer.cc create mode 100644 src/client/stardrawer.h create mode 100644 src/client/video.cc create mode 100644 src/client/video.h create mode 100644 src/client/view.cc create mode 100644 src/client/view.h create mode 100644 src/common/Makefile.am create mode 100644 src/common/color.cc create mode 100644 src/common/color.h create mode 100644 src/common/functions.cc create mode 100644 src/common/functions.h create mode 100644 src/common/osirion.h create mode 100644 src/common/vector3f.cc create mode 100644 src/common/vector3f.h create mode 100644 src/game/Makefile.am create mode 100644 src/game/game.cc create mode 100644 src/game/game.h create mode 100644 src/game/player.h create mode 100644 src/game/sector.h create mode 100644 src/game/ship.cc create mode 100644 src/game/ship.h create mode 100644 src/game/star.cc create mode 100644 src/game/star.h create mode 100644 src/game/world.h create mode 100644 src/gl/Makefile.am create mode 100644 src/gl/box.cc create mode 100644 src/gl/box.h create mode 100644 src/gl/osiriongl.cc create mode 100644 src/gl/osiriongl.h create mode 100644 src/gl/sphere.cc create mode 100644 src/gl/sphere.h create mode 100644 templates/cpp create mode 100644 templates/h diff --git a/AUTHORS b/AUTHORS new file mode 100644 index 0000000..f69a0a2 --- /dev/null +++ b/AUTHORS @@ -0,0 +1 @@ +Stijn Buys diff --git a/COPYING b/COPYING new file mode 100644 index 0000000..5b6e7c6 --- /dev/null +++ b/COPYING @@ -0,0 +1,340 @@ + GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1989, 1991 Free Software Foundation, Inc. + 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Library General Public License instead.) You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + + To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. You must make sure that they, too, receive or can get the +source code. And you must show them these terms so they know their +rights. + + We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + + Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + + The precise terms and conditions for copying, distribution and +modification follow. + + GNU GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + + 1. You may copy and distribute verbatim copies of the Program's +source code as you receive it, in any medium, provided that you +conspicuously and appropriately publish on each copy an appropriate +copyright notice and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + + 2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) You must cause the modified files to carry prominent notices + stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in + whole or in part contains or is derived from the Program or any + part thereof, to be licensed as a whole at no charge to all third + parties under the terms of this License. + + c) If the modified program normally reads commands interactively + when run, you must cause it, when started running for such + interactive use in the most ordinary way, to print or display an + announcement including an appropriate copyright notice and a + notice that there is no warranty (or else, saying that you provide + a warranty) and that users may redistribute the program under + these conditions, and telling the user how to view a copy of this + License. (Exception: if the Program itself is interactive but + does not normally print such an announcement, your work based on + the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + + a) Accompany it with the complete corresponding machine-readable + source code, which must be distributed under the terms of Sections + 1 and 2 above on a medium customarily used for software interchange; or, + + b) Accompany it with a written offer, valid for at least three + years, to give any third party, for a charge no more than your + cost of physically performing source distribution, a complete + machine-readable copy of the corresponding source code, to be + distributed under the terms of Sections 1 and 2 above on a medium + customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer + to distribute corresponding source code. (This alternative is + allowed only for noncommercial distribution and only if you + received the program in object code or executable form with such + an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + + 4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + + 5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + + 6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + + 7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + + 9. The Free Software Foundation may publish revised and/or new versions +of the General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + +Each version is given a distinguishing version number. If the Program +specifies a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + + 10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + + NO WARRANTY + + 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY +FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS +TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, +REPAIR OR CORRECTION. + + 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING +OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED +TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY +YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER +PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + 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 + + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + + Gnomovision version 69, Copyright (C) year name of author + Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, the commands you use may +be called something other than `show w' and `show c'; they could even be +mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the program + `Gnomovision' (which makes passes at compilers) written by James Hacker. + + , 1 April 1989 + Ty Coon, President of Vice + +This General Public License does not permit incorporating your program into +proprietary programs. If your program is a subroutine library, you may +consider it more useful to permit linking proprietary applications with the +library. If this is what you want to do, use the GNU Library General +Public License instead of this License. diff --git a/ChangeLog b/ChangeLog new file mode 100644 index 0000000..e69de29 diff --git a/Doxyfile b/Doxyfile new file mode 100644 index 0000000..38e6939 --- /dev/null +++ b/Doxyfile @@ -0,0 +1,283 @@ +# Doxyfile 1.5.1-KDevelop + +#--------------------------------------------------------------------------- +# Project related configuration options +#--------------------------------------------------------------------------- +PROJECT_NAME = osirion.kdevelop +PROJECT_NUMBER = 0.0.1 +OUTPUT_DIRECTORY = +CREATE_SUBDIRS = NO +OUTPUT_LANGUAGE = English +USE_WINDOWS_ENCODING = YES +BRIEF_MEMBER_DESC = YES +REPEAT_BRIEF = YES +ABBREVIATE_BRIEF = "The $name class" \ + "The $name widget" \ + "The $name file" \ + is \ + provides \ + specifies \ + contains \ + represents \ + a \ + an \ + the +ALWAYS_DETAILED_SEC = NO +INLINE_INHERITED_MEMB = NO +FULL_PATH_NAMES = NO +STRIP_FROM_PATH = /home/ingar/projects/radiant/gtkradiant-170-net/ +STRIP_FROM_INC_PATH = +SHORT_NAMES = NO +JAVADOC_AUTOBRIEF = NO +MULTILINE_CPP_IS_BRIEF = NO +DETAILS_AT_TOP = NO +INHERIT_DOCS = YES +SEPARATE_MEMBER_PAGES = NO +TAB_SIZE = 2 +ALIASES = +OPTIMIZE_OUTPUT_FOR_C = NO +OPTIMIZE_OUTPUT_JAVA = NO +BUILTIN_STL_SUPPORT = NO +DISTRIBUTE_GROUP_DOC = NO +SUBGROUPING = YES +#--------------------------------------------------------------------------- +# Build related configuration options +#--------------------------------------------------------------------------- +EXTRACT_ALL = NO +EXTRACT_PRIVATE = NO +EXTRACT_STATIC = YES +EXTRACT_LOCAL_CLASSES = YES +EXTRACT_LOCAL_METHODS = NO +HIDE_UNDOC_MEMBERS = NO +HIDE_UNDOC_CLASSES = NO +HIDE_FRIEND_COMPOUNDS = NO +HIDE_IN_BODY_DOCS = NO +INTERNAL_DOCS = NO +CASE_SENSE_NAMES = YES +HIDE_SCOPE_NAMES = NO +SHOW_INCLUDE_FILES = YES +INLINE_INFO = YES +SORT_MEMBER_DOCS = YES +SORT_BRIEF_DOCS = NO +SORT_BY_SCOPE_NAME = NO +GENERATE_TODOLIST = YES +GENERATE_TESTLIST = YES +GENERATE_BUGLIST = YES +GENERATE_DEPRECATEDLIST= YES +ENABLED_SECTIONS = +MAX_INITIALIZER_LINES = 30 +SHOW_USED_FILES = YES +SHOW_DIRECTORIES = NO +FILE_VERSION_FILTER = +#--------------------------------------------------------------------------- +# configuration options related to warning and progress messages +#--------------------------------------------------------------------------- +QUIET = NO +WARNINGS = YES +WARN_IF_UNDOCUMENTED = NO +WARN_IF_DOC_ERROR = YES +WARN_NO_PARAMDOC = NO +WARN_FORMAT = "$file:$line: $text" +WARN_LOGFILE = +#--------------------------------------------------------------------------- +# configuration options related to the input files +#--------------------------------------------------------------------------- +INPUT = /home/ingar/projects/osirion +FILE_PATTERNS = *.c \ + *.cc \ + *.cxx \ + *.cpp \ + *.c++ \ + *.d \ + *.java \ + *.ii \ + *.ixx \ + *.ipp \ + *.i++ \ + *.inl \ + *.h \ + *.hh \ + *.hxx \ + *.hpp \ + *.h++ \ + *.idl \ + *.odl \ + *.cs \ + *.php \ + *.php3 \ + *.inc \ + *.m \ + *.mm \ + *.dox \ + *.py \ + *.C \ + *.CC \ + *.C++ \ + *.II \ + *.I++ \ + *.H \ + *.HH \ + *.H++ \ + *.CS \ + *.PHP \ + *.PHP3 \ + *.M \ + *.MM \ + *.PY \ + *.C \ + *.H \ + *.tlh \ + *.diff \ + *.patch \ + *.moc \ + *.xpm \ + *.dox +RECURSIVE = yes +EXCLUDE = +EXCLUDE_SYMLINKS = NO +EXCLUDE_PATTERNS = +EXAMPLE_PATH = +EXAMPLE_PATTERNS = * +EXAMPLE_RECURSIVE = NO +IMAGE_PATH = +INPUT_FILTER = +FILTER_PATTERNS = +FILTER_SOURCE_FILES = NO +#--------------------------------------------------------------------------- +# configuration options related to source browsing +#--------------------------------------------------------------------------- +SOURCE_BROWSER = NO +INLINE_SOURCES = NO +STRIP_CODE_COMMENTS = YES +REFERENCED_BY_RELATION = YES +REFERENCES_RELATION = YES +REFERENCES_LINK_SOURCE = YES +USE_HTAGS = NO +VERBATIM_HEADERS = YES +#--------------------------------------------------------------------------- +# configuration options related to the alphabetical class index +#--------------------------------------------------------------------------- +ALPHABETICAL_INDEX = NO +COLS_IN_ALPHA_INDEX = 5 +IGNORE_PREFIX = +#--------------------------------------------------------------------------- +# configuration options related to the HTML output +#--------------------------------------------------------------------------- +GENERATE_HTML = YES +HTML_OUTPUT = html +HTML_FILE_EXTENSION = .html +HTML_HEADER = +HTML_FOOTER = +HTML_STYLESHEET = +HTML_ALIGN_MEMBERS = YES +GENERATE_HTMLHELP = NO +CHM_FILE = +HHC_LOCATION = +GENERATE_CHI = NO +BINARY_TOC = NO +TOC_EXPAND = NO +DISABLE_INDEX = NO +ENUM_VALUES_PER_LINE = 4 +GENERATE_TREEVIEW = NO +TREEVIEW_WIDTH = 250 +#--------------------------------------------------------------------------- +# configuration options related to the LaTeX output +#--------------------------------------------------------------------------- +GENERATE_LATEX = YES +LATEX_OUTPUT = latex +LATEX_CMD_NAME = latex +MAKEINDEX_CMD_NAME = makeindex +COMPACT_LATEX = NO +PAPER_TYPE = a4wide +EXTRA_PACKAGES = +LATEX_HEADER = +PDF_HYPERLINKS = NO +USE_PDFLATEX = NO +LATEX_BATCHMODE = NO +LATEX_HIDE_INDICES = NO +#--------------------------------------------------------------------------- +# configuration options related to the RTF output +#--------------------------------------------------------------------------- +GENERATE_RTF = NO +RTF_OUTPUT = rtf +COMPACT_RTF = NO +RTF_HYPERLINKS = NO +RTF_STYLESHEET_FILE = +RTF_EXTENSIONS_FILE = +#--------------------------------------------------------------------------- +# configuration options related to the man page output +#--------------------------------------------------------------------------- +GENERATE_MAN = NO +MAN_OUTPUT = man +MAN_EXTENSION = .3 +MAN_LINKS = NO +#--------------------------------------------------------------------------- +# configuration options related to the XML output +#--------------------------------------------------------------------------- +GENERATE_XML = yes +XML_OUTPUT = xml +XML_SCHEMA = +XML_DTD = +XML_PROGRAMLISTING = NO +#--------------------------------------------------------------------------- +# configuration options for the AutoGen Definitions output +#--------------------------------------------------------------------------- +GENERATE_AUTOGEN_DEF = NO +#--------------------------------------------------------------------------- +# configuration options related to the Perl module output +#--------------------------------------------------------------------------- +GENERATE_PERLMOD = NO +PERLMOD_LATEX = NO +PERLMOD_PRETTY = YES +PERLMOD_MAKEVAR_PREFIX = +#--------------------------------------------------------------------------- +# Configuration options related to the preprocessor +#--------------------------------------------------------------------------- +ENABLE_PREPROCESSING = YES +MACRO_EXPANSION = NO +EXPAND_ONLY_PREDEF = NO +SEARCH_INCLUDES = YES +INCLUDE_PATH = +INCLUDE_FILE_PATTERNS = +PREDEFINED = +EXPAND_AS_DEFINED = +SKIP_FUNCTION_MACROS = YES +#--------------------------------------------------------------------------- +# Configuration::additions related to external references +#--------------------------------------------------------------------------- +TAGFILES = +GENERATE_TAGFILE = osirion.tag +ALLEXTERNALS = NO +EXTERNAL_GROUPS = YES +PERL_PATH = /usr/bin/perl +#--------------------------------------------------------------------------- +# Configuration options related to the dot tool +#--------------------------------------------------------------------------- +CLASS_DIAGRAMS = YES +HIDE_UNDOC_RELATIONS = YES +HAVE_DOT = YES +CLASS_GRAPH = YES +COLLABORATION_GRAPH = YES +GROUP_GRAPHS = YES +UML_LOOK = NO +TEMPLATE_RELATIONS = YES +INCLUDE_GRAPH = YES +INCLUDED_BY_GRAPH = YES +CALL_GRAPH = NO +CALLER_GRAPH = NO +GRAPHICAL_HIERARCHY = YES +DIRECTORY_GRAPH = YES +DOT_IMAGE_FORMAT = png +DOT_PATH = +DOTFILE_DIRS = +MAX_DOT_GRAPH_WIDTH = 1024 +MAX_DOT_GRAPH_HEIGHT = 1024 +MAX_DOT_GRAPH_DEPTH = 0 +DOT_TRANSPARENT = NO +DOT_MULTI_TARGETS = NO +GENERATE_LEGEND = YES +DOT_CLEANUP = YES +#--------------------------------------------------------------------------- +# Configuration::additions related to the search engine +#--------------------------------------------------------------------------- +SEARCHENGINE = NO diff --git a/INSTALL b/INSTALL new file mode 100644 index 0000000..3288f2f --- /dev/null +++ b/INSTALL @@ -0,0 +1,9 @@ +Basic Installation +================== + +To build the source you will need the SDL and OpenGL library and header files. + +./configure +make +src/client/osirion + diff --git a/Makefile.am b/Makefile.am new file mode 100644 index 0000000..02520f2 --- /dev/null +++ b/Makefile.am @@ -0,0 +1,5 @@ +# not a GNU package. You can remove this line, if +# have all needed files, that a GNU package needs +AUTOMAKE_OPTIONS = foreign 1.4 + +SUBDIRS = src diff --git a/NEWS b/NEWS new file mode 100644 index 0000000..e69de29 diff --git a/README b/README new file mode 100644 index 0000000..db98823 --- /dev/null +++ b/README @@ -0,0 +1,17 @@ +The Osirion Project + +This is the Osirion project. I wrote it to get a better grasp on OpenGL +and to get some C++ practice. Maybe someday, it will be a real game. + +Controls: + space bar: switch camera between free mode and tracking mode + left/right/up/down arrow keys: rotate camera in free mode + keypad left/right: turn the ship left/right + keypad +/-: increase/decrease thrust + +The program is distributed under the terms and conditions of the +GNU General Public License version 2. + + +Stijn Buys + diff --git a/TODO b/TODO new file mode 100644 index 0000000..e69de29 diff --git a/configure.in b/configure.in new file mode 100644 index 0000000..ea9eb07 --- /dev/null +++ b/configure.in @@ -0,0 +1,90 @@ +AC_INIT(configure.in) + +AM_CONFIG_HEADER(config.h) +AM_INIT_AUTOMAKE(osirion, 0.0.1) + +AC_LANG_CPLUSPLUS +AC_PROG_CXX +AM_PROG_LIBTOOL + +dnl KDE_FIND_PATH(programm-name, variable-name, list of directories, +dnl if-not-found, test-parameter) +AC_DEFUN(KDE_FIND_PATH, +[ + AC_MSG_CHECKING([for $1]) + if test -n "$$2"; then + kde_cv_path="$$2"; + else + kde_cache=`echo $1 | sed 'y%./+-%__p_%'` + + AC_CACHE_VAL(kde_cv_path_$kde_cache, + [ + kde_cv_path="NONE" + dirs="$3" + kde_save_IFS=$IFS + IFS=':' + for dir in $PATH; do + dirs="$dirs $dir" + done + IFS=$kde_save_IFS + + for dir in $dirs; do + if test -x "$dir/$1"; then + if test -n "$5" + then + evalstr="$dir/$1 $5 2>&1 " + if eval $evalstr; then + kde_cv_path="$dir/$1" + break + fi + else + kde_cv_path="$dir/$1" + break + fi + fi + done + + eval "kde_cv_path_$kde_cache=$kde_cv_path" + + ]) + + eval "kde_cv_path=\"`echo '$kde_cv_path_'$kde_cache`\"" + + fi + + if test -z "$kde_cv_path" || test "$kde_cv_path" = NONE; then + AC_MSG_RESULT(not found) + $4 + else + AC_MSG_RESULT($kde_cv_path) + $2=$kde_cv_path + + fi +]) + +KDE_FIND_PATH(sdl-config, LIBSDL_CONFIG, [${prefix}/bin ${exec_prefix}/bin /usr/local/bin /opt/local/bin], [ + AC_MSG_WARN([Could not find libsdl anywhere, check http://www.sdl.org]) +]) + +if test -n "$LIBSDL_CONFIG"; then + LIBSDL_LIBS="`$LIBSDL_CONFIG --libs`" + LIBSDL_RPATH= + for args in $LIBSDL_LIBS; do + case $args in + -L*) + LIBSDL_RPATH="$LIBSDL_RPATH $args" + ;; + esac + done + LIBSDL_RPATH=`echo $LIBSDL_RPATH | sed -e "s/-L/-R/g"` + LIBSDL_CFLAGS="`$LIBSDL_CONFIG --cflags`" + + AC_DEFINE_UNQUOTED(HAVE_LIBSDL, 1, [Defines if your system has the LIBSDL library]) +fi + + +AC_SUBST(LIBSDL_LIBS) +AC_SUBST(LIBSDL_CFLAGS) +AC_SUBST(LIBSDL_RPATH) + +AC_OUTPUT(Makefile src/Makefile src/game/Makefile src/gl/Makefile src/client/Makefile src/common/Makefile) diff --git a/osirion.kdevelop b/osirion.kdevelop new file mode 100644 index 0000000..915757e --- /dev/null +++ b/osirion.kdevelop @@ -0,0 +1,152 @@ + + + + Stijn Buys + stijn.buys@telenet.be + 0.0.1 + KDevAutoProject + C++ + + C++ + Code + SDL + + + + + + src/client/osirion + debug + + + src/osirion + true + executable + + + + + + + optimized + kdevgccoptions + kdevgppoptions + kdevg77options + -O2 -g0 + + + --enable-debug=full + debug + kdevgccoptions + kdevgppoptions + kdevg77options + -O0 -g3 + + + + + -lSDL + + + + + + + + + + + + ada + ada_bugs_gcc + bash + bash_bugs + w3c-dom-level2-html + fortran_bugs_gcc + gnome1 + gnustep + gtk + gtk_bugs + haskell + haskell_bugs_ghc + java_bugs_gcc + java_bugs_sun + kde2book + opengl + pascal_bugs_fp + php + php_bugs + perl + perl_bugs + python + python_bugs + qt-kdev3 + ruby + ruby_bugs + w3c-svg + sw + w3c-uaag10 + wxwidgets_bugs + + + Guide to the Qt Translation Tools + Qt Assistant Manual + Qt Designer Manual + Qt Reference Documentation + qmake User Guide + + + KDE Libraries (Doxygen) + + + + + + + + + + + Doxygen Documentation Collection + osirion.tag + + + + osirion + osirion + Osirion + OSIRION + Stijn Buys + stijn.buys@telenet.be + GPL + COPYING + 0.0.1 + 2007 + /home/ingar/projects/osirion + + + + + true + true + true + false + true + true + true + 250 + 400 + 250 + + + + + false + false + + + *.o,*.lo,CVS + false + + + diff --git a/osirion.kdevelop.pcs b/osirion.kdevelop.pcs new file mode 100644 index 0000000..818f139 Binary files /dev/null and b/osirion.kdevelop.pcs differ diff --git a/osirion.kdevses b/osirion.kdevses new file mode 100644 index 0000000..c6fee45 --- /dev/null +++ b/osirion.kdevses @@ -0,0 +1,32 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Makefile.am b/src/Makefile.am new file mode 100644 index 0000000..b30324a --- /dev/null +++ b/src/Makefile.am @@ -0,0 +1,6 @@ + +# set the include path found by configure +AM_CPPFLAGS = $(LIBSDL_CFLAGS) $(all_includes) + +# the library search path. +SUBDIRS = common game gl client diff --git a/src/client/Makefile.am b/src/client/Makefile.am new file mode 100644 index 0000000..f234f49 --- /dev/null +++ b/src/client/Makefile.am @@ -0,0 +1,12 @@ + +METASOURCES = AUTO +bin_PROGRAMS = osirion +osirion_LDADD = $(top_builddir)/src/common/libcommon.la \ + $(top_builddir)/src/game/libgame.la $(top_builddir)/src/gl/libosiriongl.la -lSDL +osirion_SOURCES = camera.cc camera.h input.cc input.h main.cc video.cc video.h \ + view.cc view.h shipdrawer.cc shipdrawer.h stardrawer.cc stardrawer.h + + + +INCLUDES = -I$(top_srcdir)/src +osirion_LDFLAGS = -L/usr/X11/lib64 diff --git a/src/client/camera.cc b/src/client/camera.cc new file mode 100644 index 0000000..ca60d18 --- /dev/null +++ b/src/client/camera.cc @@ -0,0 +1,107 @@ +/* camera.cc + This file is part of the Osirion project and is distributed under + the terms and conditions of the GNU General Public License version 2 +*/ + +#include "common/functions.h" +#include "common/osirion.h" + +#include "game/game.h" +#include "gl/osiriongl.h" + +namespace camera +{ +enum Mode {Free, Track}; +Mode mode = Track; + +const float track_pitch = 15.0f; // default tracking pitch +const float offset_inc = 5.0f; // default offset increment + +float yaw = 90; // current yaw, angle in XZ plane +float yaw_offset = 0; // target offset, relative to target yaw + +float pitch = -90; // current pitch, angle in XY +float pitch_offset = track_pitch; // target offset, relative to target pitch + +float distance = 2.0f; // distance from the eye to the target + + +void draw(float elapsed) +{ + // adjust yaw target + float yaw_target = game::ship.yaw - yaw_offset; + float d = degreesf(yaw - yaw_target); + yaw = degreesf( yaw - d * elapsed); + + // adjust pitch target + float pitch_target = 0.0f - pitch_offset; + d= degreesf(pitch - pitch_target); + pitch = degreesf( pitch - d *elapsed); + + /* + gl::translate(distance, 0.0, 0.0); + gl::rotate(-pitch,0, 0, 1.0 ); + gl::rotate(-yaw, 0, 1.0f, 0); + */ + switch (mode) { + case Free: + gl::translate(1+distance * GAMESCALE, 0.0f, 0.0f); + gl::rotate(-pitch, 0, 0, 1.0f); + gl::rotate(-yaw, 0, 1.0f, 0); + break; + case Track: + gl::translate(1+distance* GAMESCALE, -0.5f* GAMESCALE, 0.0f); + gl::rotate(-pitch, 0, 0, 1.0f); + gl::rotate(-yaw, 0, 1.0f, 0); + break; + default: + break; + } +} + +void rotate_right() +{ + if (mode == Free ) { + yaw_offset = degreesf( yaw_offset - offset_inc); + } +} + +void rotate_left() +{ + if (mode == Free ) { + yaw_offset = degreesf( yaw_offset + offset_inc); + } +} + +void rotate_up() +{ + if (mode == Free ) { + pitch_offset = degreesf( pitch_offset + offset_inc); + } +} + +void rotate_down() +{ + if (mode == Free ) { + pitch_offset = degreesf( pitch_offset - offset_inc); + } +} + +void nextmode() { + switch(mode) { + case Free: + mode = Track; + yaw_offset = 0; + yaw = game::ship.yaw; + pitch_offset = track_pitch; + break; + case Track: + mode = Free; + yaw_offset = 0; + break; + default: + break; + } +} + +} //namespace camera diff --git a/src/client/camera.h b/src/client/camera.h new file mode 100644 index 0000000..63c7aa5 --- /dev/null +++ b/src/client/camera.h @@ -0,0 +1,44 @@ +/* camera.h + This file is part of the Osirion project +*/ + +#ifndef __INCLUDED_CAMERA_H__ +#define __INCLUDED_CAMERA_H__ + +#include "common/vector3f.h" + +/// camera functions +/** The functions in this namespace performs the transformations +for the camera eye location. The camera always looks at (0,0,0) +*/ +namespace camera +{ + /// draw the OpenGL camera transformation + void draw(float elapsed); + + /// rotate the camera left + void rotate_left(); + /// rotate the camera right + void rotate_right(); + /// rotate the camera up + void rotate_up(); + /// rotate the camera down + void rotate_down(); + + /// switch to next camera mode + void nextmode(); + + /// camera target + /** The location the camera is looking at */ + extern Vector3f target; + + /// horizontal viewing angle x/z plane + extern float horiz_angle; + /// vertical viewing angle z/y plane + extern float vert_angle; + /// distance from the camera to the target + /** The distance in game units from the eye of the camera to the target */ + extern float distance; +}; + +#endif // __INCLUDED_CAMERA_H__ diff --git a/src/client/hud.cc b/src/client/hud.cc new file mode 100644 index 0000000..e69de29 diff --git a/src/client/hud.h b/src/client/hud.h new file mode 100644 index 0000000..e69de29 diff --git a/src/client/input.cc b/src/client/input.cc new file mode 100644 index 0000000..8af7414 --- /dev/null +++ b/src/client/input.cc @@ -0,0 +1,86 @@ +/* input.cc + This file is part of the Osirion project and is distributed under + the terms and conditions of the GNU General Public License version 2 +*/ + +// SDL headers +#include + +//project headers +#include "common/functions.h" +#include "game/game.h" + +#include "view.h" +#include "camera.h" + +namespace input +{ + +void init() +{ + SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL); +} + +void shutdown() +{ +} + +void handle_keydown(SDL_keysym* keysym) +{ + switch( keysym->sym ) { + case SDLK_ESCAPE: + game::shutdown(); + break; + case SDLK_SPACE: + camera::nextmode(); + break; + case SDLK_LEFT: + camera::rotate_left(); + break; + case SDLK_RIGHT: + camera::rotate_right(); + break; + case SDLK_UP: + camera::rotate_up(); + break; + case SDLK_DOWN: + camera::rotate_down(); + break; + case SDLK_KP_PLUS: + game::ship.thrust_increase(); + break; + case SDLK_KP_MINUS: + game::ship.thrust_decrease(); + break; + case SDLK_KP4: + game::ship.turn_left(); + break; + case SDLK_KP6: + game::ship.turn_right(); + break; + default: + break; + } + +} + +void process() +{ + SDL_Event event; + + while( SDL_PollEvent( &event ) ) { + switch( event.type ) { +// case SDL_MOUSEBUTTONUP: + case SDL_KEYDOWN: + handle_keydown( &event.key.keysym ); + break; + case SDL_QUIT: + game::shutdown(); + break; + } + + } + +} + +} // namespace input diff --git a/src/client/input.h b/src/client/input.h new file mode 100644 index 0000000..f1e94d9 --- /dev/null +++ b/src/client/input.h @@ -0,0 +1,24 @@ +/* input.h + This file is part of the Osirion project and is distributed under + the terms and conditions of the GNU General Public License version 2 +*/ + +#ifndef __INCLUDED_INPUT_H__ +#define __INCLUDED_INPUT_H__ + + +namespace input +{ + /// initialize the input subsystem + void init(); + /// shutdown the input subsystem + void shutdown(); + + /// exit the application + void quit(int exit_code); + + /// process input events + void process(); +}; + +#endif // __INCLUDED_INPUT_H__ diff --git a/src/client/main.cc b/src/client/main.cc new file mode 100644 index 0000000..66e0fa3 --- /dev/null +++ b/src/client/main.cc @@ -0,0 +1,65 @@ +/* main.cc + This file is part of the Osirion project and is distributed under + the terms and conditions of the GNU General Public License version 2 +*/ + +// SDL headers +#include + +// C++ headers +#include + +// project headers +#include "common/osirion.h" +#include "game/game.h" + +#include "input.h" +#include "video.h" + +void quit(int exit_code) +{ + SDL_Quit(); + exit(exit_code); +} + +int main( int argc, char *argv[] ) +{ + std::cout << "The Osirion project " << OSIRION_VERSION << std::endl; + + // Initialize the video subsystem + video::init(); + if (!video::initialized) { + quit(1); + } + + // initialize input + input::init(); + + // initialize game + game::init(); + + Uint32 startup = SDL_GetTicks(); + while(game::initialized) { + Uint32 chrono = SDL_GetTicks(); + + // overflow protection ~49 days + if (chrono < startup) { + startup = chrono; + } + + // update the game chronometers + float elapsed = (float) ( chrono - startup) / 1000.0f; + game::update(elapsed); + + // update the video chronometers and draw + video::draw(elapsed); + startup = chrono; + + // process input + input::process(); + } + + video::shutdown(); + + quit(0); +} diff --git a/src/client/shipdrawer.cc b/src/client/shipdrawer.cc new file mode 100644 index 0000000..d889178 --- /dev/null +++ b/src/client/shipdrawer.cc @@ -0,0 +1,108 @@ +/* shipdrawer.cc + This file is part of the Osirion project and is distributed under + the terms and conditions of the GNU General Public License version 2 +*/ + +#include + +// project headers +#include "gl/osiriongl.h" +#include "gl/box.h" + +#include "shipdrawer.h" + +Vector3f v0(1.0f, -1.0f, -1.0f); +Vector3f v1(1.0f, 1.0f, -1.0f); +Vector3f v2(1.0f, 1.0f, 1.0f); +Vector3f v3(1.0f, -1.0f, 1.0f); + +Vector3f v4(-1.0f, -1.0f, -1.0f); +Vector3f v5(-1.0f, 1.0f, -1.0f); +Vector3f v6(-1.0f, 1.0f, 1.0f); +Vector3f v7(-1.0f, -1.0f, 1.0f); + +ShipDrawer::ShipDrawer(Ship *s) +{ + angle = 0; + ship = s; +} + +ShipDrawer::~ShipDrawer() +{ +} + +void ShipDrawer::draw(float elapsed) +{ + using namespace gl; + + gl::push(); + + rotate(ship->yaw, 0.0f, 1.0f, 0.0f ); + + + Vector3f tl(0.25, 0.125, 0.125); + Vector3f br(-0.25, -0.125, -0.125); + + Box box(tl, br); + box.draw(); + + tl = Vector3f(0, 0.07, 0.25); + br = Vector3f(-0.5, -0.07, 0.125); + Box engine1(tl, br); + engine1.topcolor = Color(0.7, 0.7, 0.7); + engine1.bottomcolor = engine1.topcolor * 0.5; + engine1.draw(); + + tl = Vector3f(0, 0.07, -0.125); + br = Vector3f(-0.5, -0.07, -0.25); + Box engine2(tl, br); + engine2.topcolor = engine1.topcolor; + engine2.bottomcolor = engine1.bottomcolor; + engine2.draw(); + + tl = Vector3f(0.4, 0.07, 0.07); + br = Vector3f(0.25, -0.07, -0.07); + Box cockpit(tl, br); + cockpit.topcolor = engine1.topcolor; + cockpit.bottomcolor = engine1.bottomcolor; + cockpit.draw(); + + if(ship->thrust > 0 ) { + color(1.0f,0 ,0 ); + begin(Lines); + vertex(-0.5f, 0, 0.185); + vertex(-0.5f-0.25f*ship->thrust, 0, 0.185); + + vertex(-0.5f, 0, -0.185f); + vertex(-0.5f-0.25f*ship->thrust, 0, -0.185f); + end(); + } + + // shield rotation + rotate(angle, 0.0f, 1.0f, 0.0f ); + angle += 180.0f * elapsed; + if( angle > 360.0f ) { + angle -= 360.0f; + } + + // draw the shield + color(Color(0.0f, 1.0f ,0.0f , 0.5f)); + + begin(LineStrip); + vertex(v0); + vertex(v1); + vertex(v2); + vertex(v3); + vertex(v0); + end(); + + begin(LineStrip); + vertex(v4); + vertex(v5); + vertex(v6); + vertex(v7); + vertex(v4); + end(); + + gl::pop(); +} diff --git a/src/client/shipdrawer.h b/src/client/shipdrawer.h new file mode 100644 index 0000000..8860585 --- /dev/null +++ b/src/client/shipdrawer.h @@ -0,0 +1,26 @@ +/* shipdrawer.h + This file is part of the Osirion project and is distributed under + the terms and conditions of the GNU General Public License version 2 +*/ + +#ifndef __INCLUDED_SHIPDRAWER_H__ +#define __INCLUDED_SHIPDRAWER_H__ + +// project headers +#include "game/ship.h" + +class ShipDrawer +{ +public: + ShipDrawer(Ship *s); + ~ShipDrawer(); + + /// update the model state + void draw(float elapsed); + +private: + Ship *ship; + float angle; +}; + +#endif // __INCLUDED_SHIPDRAWER_H__ diff --git a/src/client/stardrawer b/src/client/stardrawer new file mode 100644 index 0000000..e69de29 diff --git a/src/client/stardrawer.cc b/src/client/stardrawer.cc new file mode 100644 index 0000000..6bdf34c --- /dev/null +++ b/src/client/stardrawer.cc @@ -0,0 +1,22 @@ +/* stardrawer.cc + This file is part of the Osirion project and is distributed under + the terms and conditions of the GNU General Public License version 2 +*/ + +#include "gl/osiriongl.h" +#include "stardrawer.h" + +StarDrawer::StarDrawer(Star *s) { + star = s; + sphere.radius = s->radius; + +} +StarDrawer::~StarDrawer() { + star = 0; +} + +void StarDrawer::draw(float elapsed) +{ + gl::color(star->color); + sphere.draw(); +} diff --git a/src/client/stardrawer.h b/src/client/stardrawer.h new file mode 100644 index 0000000..7656414 --- /dev/null +++ b/src/client/stardrawer.h @@ -0,0 +1,26 @@ +/* stardrawer.h + This file is part of the Osirion project and is distributed under + the terms and conditions of the GNU General Public License version 2 +*/ + +#ifndef __INCLUDED_STARDRAWER_H__ +#define __INCLUDED_STARDRAWER_H__ + +#include "gl/sphere.h" +#include "game/star.h" + +/// Class to draw stars +class StarDrawer +{ +public: + StarDrawer(Star *s); + ~StarDrawer(); + + void draw(float elapsed); + +private: + Star *star; + gl::Sphere sphere; +}; + +#endif // __INCLUDED_STARDRAWER_H__ diff --git a/src/client/video.cc b/src/client/video.cc new file mode 100644 index 0000000..eb4297e --- /dev/null +++ b/src/client/video.cc @@ -0,0 +1,109 @@ +/* video.cc + This file is part of the Osirion project and is distributed under + the terms and conditions of the GNU General Public License version 2 +*/ + +// SDL headers +#include + +// C++ headers +#include + +// project headers +#include "gl/osiriongl.h" +#include "view.h" + + +namespace video +{ +int width = 0; +int height = 0; +bool initialized = false; +float ratio = 1; + +void reset() +{ + ratio = (float) width / (float) height; + + // Our shading model--Gouraud (smooth). + gl::shademodel(GL_SMOOTH); + + // Culling + gl::cullface( GL_BACK ); + gl::frontface(GL_CCW ); + gl::enable( GL_CULL_FACE ); + + gl::depthmask(GL_TRUE); // Depth buffer writing + gl::enable(GL_DEPTH_TEST); + + // Set the clear color + gl::clearcolor( 0, 0, 0, 0 ); + + // Setup our viewport. + gl::viewport(0, 0, width, height ); + + view::reset(); +} + +void init() +{ + if (initialized) { + return; + } + + int bpp = 0; + int flags = 0; + + if( SDL_Init(SDL_INIT_VIDEO) < 0 ) { + std::cerr << "SDL_Init() failed: " << SDL_GetError() << std::endl; + return; + } + + const SDL_VideoInfo* sdl_videoinfo = SDL_GetVideoInfo(); + if( !sdl_videoinfo) { + std::cerr << "SDL_GetVideoInfo() failed: " << SDL_GetError() << std::endl; + return; + } + + width = 800; + height = 600; + bpp = sdl_videoinfo->vfmt->BitsPerPixel; + + SDL_GL_SetAttribute( SDL_GL_RED_SIZE, 5 ); + SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE, 5 ); + SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE, 5 ); + SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, 16 ); + SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 ); + + flags = SDL_OPENGL | SDL_FULLSCREEN; + + if(!SDL_SetVideoMode(width, height, bpp, flags )) { + std::cerr << "SDL_SetVideoMode() failed: " << SDL_GetError() << std::endl; + return; + } + + gl::init(); + + initialized = true; + view::init(); + + reset(); + return; +} + +void draw(float elapsed) +{ + view::draw(elapsed); +} + +void shutdown() +{ + view::shutdown(); + gl::shutdown(); + + initialized = false; + width = 0; + height = 0; +} + +} // namespace video diff --git a/src/client/video.h b/src/client/video.h new file mode 100644 index 0000000..3b126f1 --- /dev/null +++ b/src/client/video.h @@ -0,0 +1,30 @@ +/* video.h + This file is part of the Osirion project +*/ + +#ifndef __INCLUDED_VIDEO_H__ +#define __INCLUDED_VIDEO_H__ + + +namespace video +{ + /// initialize the video subsystem + void init(); + /// shutdown the video subsystem + void shutdown(); + /// Update the screen state and redraw + void draw(float elapsed); + /// reset and clear the viewport + void reset(); + + /// Width of the SDL window in pixels + extern int width; + /// Height of the SDL window in pixels + extern int height; + /// True if the video subsystem is initialized + extern bool initialized; + /// width/height ratio + extern float ratio; +}; + +#endif // __INCLUDED_VIDEO_H__ diff --git a/src/client/view.cc b/src/client/view.cc new file mode 100644 index 0000000..3641261 --- /dev/null +++ b/src/client/view.cc @@ -0,0 +1,153 @@ +/* view.cc + This file is part of the Osirion project and is distributed under + the terms and conditions of the GNU General Public License version 2 +*/ + +// C++ headers +#include + +// SDL headers +#include + +// project headers +#include "common/functions.h" +#include "common/osirion.h" + +#include "game/game.h" +#include "gl/osiriongl.h" + +#include "video.h" +#include "camera.h" + +#include "shipdrawer.h" +#include "stardrawer.h" + +namespace view +{ + +ShipDrawer *shipdrawer = 0; +StarDrawer *stardrawer = 0; + +Ship *target =0; // the view's target + +void init() { + // draw scene + if (!shipdrawer) { + stardrawer = new StarDrawer(&game::star); + shipdrawer = new ShipDrawer(&game::ship); + target = &game::ship; + } + +} + +void shutdown() +{ + delete stardrawer; + stardrawer = 0; + delete shipdrawer; + shipdrawer = 0; +} + +void reset() { + // Change to the projection matrix and set our viewing volume. + gl::matrixmode( GL_PROJECTION ); + gl::loadidentity(); + + //glu::perspective( 64.0, video::ratio, 1.0, 1024.0 ); + const float frustumsize=0.5f; + gl::frustum( -frustumsize * video::ratio, frustumsize * video::ratio, -frustumsize, frustumsize, 1.0, 1024.0); + /* + map world coordinates to GL coordinates + + The world coordinates are identical to GL coordinates, + but the default viewing pitch (0 degrees) + is the positive X-axis + */ + gl::rotate(90.0f, 0, 1.0, 0); +} + +void draw_background() +{ + using namespace gl; + + begin(Lines); + color(0.9f, 0.5f, 0.0f); + vertex(-2,1,0); + color(1.0f, 1.0f, 0.0f); + vertex(2,1,0); + + vertex(0,1,-0.5); + vertex(0,1,0.5); + + vertex(0,2.0f,0); + vertex(0,-1, 0); + end(); + + int gridsize = 32; + float s = 1.0f / gridsize; + float y = -4.0f; + + float dx = target->location.x - floorf(target->location.x); + float dz = target->location.z - floorf(target->location.z); + + color(0,0, 1.0f); + begin(Lines); + for (int i=-gridsize; i <= gridsize; i++) { + color(0,0, 0); + vertex(i-dx, y, -gridsize-dz); + color(0,0, (gridsize-abs(i))*s); + vertex(i-dx, y, -dz); + vertex(i-dx, y, -dz); + color(0,0, 0); + vertex(i-dx, y, gridsize-dz); + + vertex(-gridsize-dx, y, i-dz); + color(0,0, (gridsize-abs(i))*s); + vertex(-dx, y, i-dz); + vertex(-dx, y, i-dz); + color(0,0, 0); + vertex(gridsize-dx, y, i-dz); + } + end(); +} + +void draw_world(float elapsed) +{ + // draw the world + gl::push(); + + //std::cerr << "ship at " << game::ship.location << " translate " << game::ship.location - target->location << std::endl; + gl::translate(game::ship.location - target->location); + gl::scale(GAMESCALE, GAMESCALE, GAMESCALE); + shipdrawer->draw(elapsed); + gl::pop(); + + //std::cerr << "star at " << game::star.location << " translate " << game::star.location - game::ship.location << std::endl; + gl::translate(game::star.location - target->location); + stardrawer->draw(elapsed); + +} + +void draw(float elapsed) +{ + // Clear the color and depth buffers. + gl::clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); + + // We don't want to modify the projection matrix. + gl::matrixmode( GL_MODELVIEW ); + gl::loadidentity(); + + // Camera transformation + camera::draw(elapsed); + + // draw the semi-static background + draw_background(); + + // draw the world + draw_world(elapsed); + + SDL_GL_SwapBuffers( ); +} + +} // namespace view + diff --git a/src/client/view.h b/src/client/view.h new file mode 100644 index 0000000..de73ab9 --- /dev/null +++ b/src/client/view.h @@ -0,0 +1,24 @@ +/* view.h + This file is part of the Osirion project and is distributed under + the terms and conditions of the GNU General Public License version 2 +*/ + +#ifndef __INCLUDED_VIEW_H__ +#define __INCLUDED_VIEW_H__ + +#include "common/vector3f.h" + +/// Draws the view of the map +namespace view +{ + void init(); + void shutdown(); + + /// Update the chronometer and draw the game view + void draw(float elapsed); + + /// Reset the projection matrix + void reset(); +}; + +#endif // __INCLUDED_VIEW_H__ diff --git a/src/common/Makefile.am b/src/common/Makefile.am new file mode 100644 index 0000000..4f556bf --- /dev/null +++ b/src/common/Makefile.am @@ -0,0 +1,8 @@ + +METASOURCES = AUTO +libcommon_la_LDFLAGS = -avoid-version -no-undefined +noinst_LTLIBRARIES = libcommon.la +libcommon_la_SOURCES = color.cc color.h functions.cc functions.h osirion.h\ + vector3f.cc vector3f.h + + diff --git a/src/common/color.cc b/src/common/color.cc new file mode 100644 index 0000000..85892c8 --- /dev/null +++ b/src/common/color.cc @@ -0,0 +1,84 @@ +/* + *************************************************************************** + * Copyright (C) 2002-2004 by Stijn Buys * + * stijn.buys@pandora.be * + * * + * This software is redistributed under the terms of the * + * GNU General Public License. Please read LICENSE.txt. * + *************************************************************************** +*/ + +#include "color.h" + +Color::Color() { + _r = _g = _b = 0.0f; + _a = 1.0f; +} + +Color::Color(const float red, const float green , const float blue , const float alpha) { + _r = red; + _g = green; + _b = blue; + _a = alpha; +} + +Color::Color(const float grey, const float alpha) { + _r = _g = _b = grey; + _a = alpha; +} + +Color::Color(const Color &other) { + this->operator=(other); +} + +const Color & Color::operator=(const Color &other) { + this->_r = other._r; + this->_g = other._g; + this->_b = other._b; + this->_a = other._a; + return (*this); +} + +void Color::normalize() { + float tmp = _r; + + if (_g > tmp) + tmp = _g; + if ( _b > tmp) + tmp = _b; + + if (tmp > 1) { + _r /= tmp; + _g /= tmp; + _b /= tmp; + } +} + +float Color::red() const { + return _r; +} + +float Color::green() const { + return _g; +} + +float Color::blue() const { + return _b; +} + +float Color::alpha() const { + return _a; +} + +Color Color::operator*(float scalar) const { + return Color(red()*scalar, green()*scalar, blue()*scalar, alpha()); +} + +Color operator*(float scalar, const Color& color) { + return color * scalar; +} +std::ostream &operator<<(std::ostream &os, const Color &c) { + os << c.red() << " " << c.green() << " " << c.blue() << " " << c.alpha(); + return os; +} + diff --git a/src/common/color.h b/src/common/color.h new file mode 100644 index 0000000..d84d1a3 --- /dev/null +++ b/src/common/color.h @@ -0,0 +1,50 @@ +/* + *************************************************************************** + * Copyright (C) 2004 by Stijn Buys * + * stijn.buys@pandora.be * + * * + * This software is redistributed under the terms of the * + * GNU General Public License. Please read LICENSE.txt. * + *************************************************************************** +*/ + +#ifndef __COLOR_HEADER__ +#define __COLOR_HEADER__ + +#include + +/// a class representing an RGBA color value +class Color { + public: + Color(); + Color(const float, float const, const float, const float=1.0f); + Color(const float, const float=1.0f); + Color(const Color &); + + float red() const; + float green() const; + float blue() const; + float alpha() const; + + const Color &operator=(const Color &); + + Color operator*(const float scalar) const; + + // Some default colors + static const Color Black() { return Color(0.0f); }; + static const Color White() { return Color(1.0f); }; + static const Color Red() { return Color(1.0f,0.0f,0.0f); }; + static const Color Green() { return Color(0.0f,1.0f,0.0f); }; + static const Color Blue() { return Color(0.0f, 0.0f, 1.0f); }; + static const Color Yellow() { return Color(1.0f, 1.0f, 0.0f); }; + + private: + void normalize(); + float _r, _g, _b, _a; +}; + +std::ostream &operator<<(std::ostream &os, const Color &c); + +Color operator*(const float scalar, const Color& color); + +#endif // ___HEADER__ diff --git a/src/common/functions.cc b/src/common/functions.cc new file mode 100644 index 0000000..7152c91 --- /dev/null +++ b/src/common/functions.cc @@ -0,0 +1,48 @@ +/* functions.cc + * This file is part of the Osirion project + */ + +#include "functions.h" + +float min(float a, float b) { + return (a < b ? a : b); +} + +float max(float a, float b) { + return (a > b ? a : b); +} + +int min(int a, int b) { + return (a < b ? a : b); +} + +int max(int a, int b) { + return (a > b ? a : b); +} + +float randomf(const float max) { + return ((float) rand() / (float) RAND_MAX) * max; +} + +unsigned randomi(const unsigned int max) { + return ((unsigned int)(rand() % max)); +} + +float degreesf(float angle) { + float r = angle; + while (r <= -180.0f) + r += 360.0f; + while (r >= 180.0f) + r -= 360.0f; + return r; +} + +float sgnf(float value) +{ + if (value < 0 ) + return -1; + else if (value == 0 ) + return 0; + + return 1; +} diff --git a/src/common/functions.h b/src/common/functions.h new file mode 100644 index 0000000..02f25da --- /dev/null +++ b/src/common/functions.h @@ -0,0 +1,42 @@ +/* functions.h + This file is part of the Osirion project +*/ + +#ifndef __INCLUDED_FUNCTIONS_H__ +#define __INCLUDED_FUNCTIONS_H__ + +#include +#include + +/// return the smallest of two float values +float min(float a, float b); + +/// return the smallest of two integers +int min(int a, int b); + +/// return the largest of two float values +float max(float a, float b); + +/// return the largest of two integers +int max(int a, int b); + +/// returns a random float +/*! The value returned will be in the interval [0-max] + * @param max the maximum value returned +**/ +float randomf(const float max = 1); + +/// returns a random integer +/*! The value returned will be in the interval [0-(max-1)] + * @param max the maximum value returned +**/ +unsigned int randomi(const unsigned int max); + +/// return the sign of a float value +float sgnf(float value); + +/// return an angle in the ]-180,180] range +float degreesf(float angle); + +#endif // __INCLUDED_FUNCTIONS_H__ + diff --git a/src/common/osirion.h b/src/common/osirion.h new file mode 100644 index 0000000..56d8b4e --- /dev/null +++ b/src/common/osirion.h @@ -0,0 +1,11 @@ +/* osirion.h + This file is part of the Osirion project +*/ + +#ifndef __INCLUDED_OSIRION_H__ +#define __INCLUDED_OSIRION_H__ + +#define OSIRION_VERSION "0.0.1" +#define GAMESCALE 0.2f + +#endif // __INCLUDED_OSIRION_H__ diff --git a/src/common/vector3f.cc b/src/common/vector3f.cc new file mode 100644 index 0000000..3e469b6 --- /dev/null +++ b/src/common/vector3f.cc @@ -0,0 +1,151 @@ +/* vector3f.h + This file is part of the Osirion project +*/ +#include "vector3f.h" +#include + +Vector3f::Vector3f() : + x(coord[0]), y(coord[1]), z(coord[2]) +{ + for (int i=0; i < 3; i++) + coord[i] = 0; +} + + +Vector3f::Vector3f(const Vector3f &other) : + x(coord[0]), y(coord[1]), z(coord[2]) +{ + for (int i=0; i < 3; i++) + coord[i] = other.coord[i]; +} + +Vector3f::Vector3f(const float xv, const float yv, const float zv) : + x(coord[0]), y(coord[1]), z(coord[2]) +{ + coord[0] = xv; + coord[1] = yv; + coord[2] = zv; +} + +Vector3f::~Vector3f() +{ +} + + +Vector3f & Vector3f::operator=(const Vector3f & other) +{ + for (int i=0; i < 3; i++) + coord[i] = other.coord[i]; + return (*this); +} + + +Vector3f & Vector3f::operator*=(const float scalar) +{ + for (int i=0; i < 3; i++) + coord[i] *= scalar; + return (*this); +} + + +Vector3f & Vector3f::operator/=(const float scalar) { + for (int i=0; i < 3; i++) + coord[i] /= scalar; + return (*this); +} + + +Vector3f &Vector3f::operator-=(const Vector3f & other) { + for (int i=0; i < 3; i++) + coord[i] -= other[i]; + return (*this); +} + + +Vector3f &Vector3f::operator+=(const Vector3f &other) { + for (int i=0; i < 3; i++) + coord[i] += other[i]; + return (*this); +} + + +Vector3f Vector3f::operator*(const float scalar) const { + Vector3f r(*this); + for (int i=0; i < 3; i++) + r.coord[i] *= scalar; + return (r); + } + + +Vector3f Vector3f::operator/(const float scalar) const { + Vector3f r(*this); + for (int i=0; i < 3; i++) + r.coord[i] /= scalar; + return (r); +} + + +Vector3f Vector3f::operator-(const Vector3f& other) const { + Vector3f r(*this); + for (int i=0; i < 3; i++) + r.coord[i] -= other.coord[i]; + return (r); +} + + +Vector3f Vector3f::operator+(const Vector3f& other) const { + Vector3f r(*this); + for (int i=0; i < 3; i++) + r.coord[i] += other.coord[i]; + return (r); +} + + +float Vector3f::operator*(const Vector3f& other) const { + float r = 0; + for (int i=0; i < 3; i++) + r += coord[i] * other.coord[i]; + return (r); +} + + +bool Vector3f::operator==(const Vector3f& other) const { + for (int i=0; i < 3; i++) + if (coord[i] != other.coord[i]) + return (false); + return (true); +} + +float Vector3f::lengthsquared() const { + double r = 0; + for (int i=0; i < 3; i++) + r += coord[i]*coord[i]; + return ((float) r); +} + +float Vector3f::length() const { + double r = 0; + for (int i=0; i < 3; i++) + r += coord[i]*coord[i]; + + return ((float) sqrt(r)); +} + +void Vector3f::normalize() { + (*this) /= this->length(); +} + +std::ostream &operator<<(std::ostream & os, const Vector3f & vector) { + os << vector[0] << " " << vector[1] << " " << vector[2]; + return os; +} + +std::istream &operator>>(std::istream & is, Vector3f & vector) { + for (int i=0; i < 3; i++) + is >> vector[i]; + return is; +} + +Vector3f operator*(float scalar, const Vector3f& vector) { + return vector * scalar; +} diff --git a/src/common/vector3f.h b/src/common/vector3f.h new file mode 100644 index 0000000..53b2ce7 --- /dev/null +++ b/src/common/vector3f.h @@ -0,0 +1,138 @@ +/* vector3f.h + This file is part of the Osirion project +*/ + + #ifndef __INCLUDED_VECTOR3F_H__ + #define __INCLUDED_VECTOR3F_H__ + + #include +/// A point or vector in 3D-space +/*! + An instance of this class represents a point in 3D-space or a 3D-vector + and forms the basic building block for all spatial calculations. + */ +class Vector3f { + +public: + /// Default constructor, creates a Vector3f (0,0,0) + Vector3f(); + + /// Copy constructor + /*! Create a new Vector3f that is a copy from an other + * @param other the vector to copy values from + */ + Vector3f(const Vector3f &other); + + /// Create a Vector3f with given coordinates + /*! Create a new vector at a given position in a 3D-space + * @param xv the x-coordinate of the location + * @param yv the y-coordinate of the location + * @param zv the z-coordinate of the location + */ + Vector3f(const float xv, const float yv, const float zv); + + /// Destructor + ~Vector3f(); + + /* -- Assignment operators -- */ + /// assignment operator + Vector3f& operator=(const Vector3f &other); + + /// multiplicate each element of the vector with a given value + /// @param scalar multiplication factor + Vector3f& operator*=(const float scalar); + + /// divide each element of the vector by a given value + /// @param scalar divider + Vector3f& operator/=(const float scalar); + + /// perform an element-wise subtraction + Vector3f& operator-=(const Vector3f &other); + + /// perform ann element-wise addition + Vector3f& operator+=(const Vector3f &other); + + /* -- Mathematical operators -- */ + + /// return this Vector multiplied with scalar + Vector3f operator*(const float scalar) const; + + /// return this vector divided by a scalar + Vector3f operator/(const float scalar) const; + + /// return the element-wise difference between two vectors + Vector3f operator-(const Vector3f &other) const; + + /// return the element-wise sumn of two vectors + Vector3f operator+(const Vector3f &other) const; + + /// return the vector cross-product + float operator*(const Vector3f &other) const; + + /// comparison operator + bool operator==(const Vector3f &other) const; + + /// assign a value to an element of this vector + /*! WARNING: range is not checked + * @param index the index of the element to assign to ( 0 <= index < 3 ) + */ + inline float& operator[](const unsigned int index) { + return coord[index]; + } + + /// returns the value of an element of this vector + /*! WARNING: range is not checked + * @param index the index of the element to return ( 0 <= index < 3 ) + */ + inline float operator[](const unsigned int index) const { + return coord[index]; + } + + + float &x; + float &y; + float &z; + + /// Return the cartesian length of this vector + float length() const; + + /// Return the cartesian length squared (to speed up calculations) + float lengthsquared() const; + + /// Divide this Vector by it's length + /// @see normalized() + /// WARNING: vector must not be (0, 0, 0) + void normalize(); + + /* static functions */ + + /// Returns the unity vector on the X-axis + static inline Vector3f Xaxis() { return Vector3f(1.0f, 0.0f, 0.0f); } + + /// Returns the unity vector on the Y-axis + static inline Vector3f Yaxis() { return Vector3f(0.0f, 1.0f, 0.0f); } + + /// Returns the unity vector on the Z-axis + static inline Vector3f Zaxis() { return Vector3f(0.0f, 0.0f, 1.0f); } + + /// Return the cartesian length of a vector + static inline float length(const Vector3f& vector) { return vector.length(); } + + /// Return a vector divided by it's length + /// @see normalize() + /// WARNING: vector must not be (0, 0, 0) + static inline Vector3f normalized(const Vector3f& vector) { return (vector / vector.length()); } + + float coord[3]; +}; + +/// Write a Vector3f to a std::ostream +std::ostream &operator<<(std::ostream & os, const Vector3f & vector); + +/// Read a Vector3d from a std::istream +std::istream &operator>>(std::istream & is, Vector3f& vector); + +/// scalar*Vector3f operators +Vector3f operator*(float scalar, const Vector3f& vector); + +#endif // __INCLUDED_VECTOR3F_H__ diff --git a/src/game/Makefile.am b/src/game/Makefile.am new file mode 100644 index 0000000..754c168 --- /dev/null +++ b/src/game/Makefile.am @@ -0,0 +1,9 @@ + +METASOURCES = AUTO +libgame_la_LDFLAGS = -avoid-version +noinst_LTLIBRARIES = libgame.la + +libgame_la_SOURCES = game.cc game.h ship.cc ship.h player.h world.h star.cc \ + star.h sector.h +INCLUDES = -I$(top_srcdir)/src +noinst_HEADERS = world.h sector.h diff --git a/src/game/game.cc b/src/game/game.cc new file mode 100644 index 0000000..dfa5fe5 --- /dev/null +++ b/src/game/game.cc @@ -0,0 +1,31 @@ +/* game.cc + This file is part of the Osirion project +*/ + +// project headers +#include "ship.h" +#include "star.h" + +namespace game { + +Ship ship; +Star star; +bool initialized = false; + +void init() +{ + star.location = Vector3f(256.0f, 0.0f, 256.0f); + initialized = true; +} + +void shutdown() +{ + initialized = false; +} + +void update(float elapsed) +{ + ship.update(elapsed); +} + +}; // namespace game diff --git a/src/game/game.h b/src/game/game.h new file mode 100644 index 0000000..7c1cc0c --- /dev/null +++ b/src/game/game.h @@ -0,0 +1,33 @@ +/* game.h + This file is part of the Osirion project +*/ + +#ifndef __INCLUDED_GAME_H__ +#define __INCLUDED_GAME_H__ + +// project headers +#include "ship.h" +#include "star.h" + +namespace game +{ + /// initialize the game + void init(); + + /// shutdown the game + void shutdown(); + + /// update the game state + void update(float elapsed); + + /// the only ship in the game + extern Ship ship; + + /// the only star in the game + extern Star star; + + /// true while the game is running + extern bool initialized; +}; + +#endif // __INCLUDED_GAME_H__ diff --git a/src/game/player.h b/src/game/player.h new file mode 100644 index 0000000..4c75206 --- /dev/null +++ b/src/game/player.h @@ -0,0 +1,20 @@ +/* player.h + This file is part of the Osirion project and is distributed under + the terms and conditions of the GNU General Public License version 2 +*/ + +#ifndef __INCLUDED_PLAyER_H__ +#define __INCLUDED_PLAyER_H__ + +#include + +/// A player in the game +class Player { +public: + Player(); + ~Player(); + + std::string name; +}; + +#endif // __INCLUDED_PLAyER_H__ diff --git a/src/game/sector.h b/src/game/sector.h new file mode 100644 index 0000000..10f548c --- /dev/null +++ b/src/game/sector.h @@ -0,0 +1,26 @@ +/* sector.h + This file is part of the Osirion project and is distributed under + the terms and conditions of the GNU General Public License version 2 +*/ + +#ifndef __INCLUDED_SECTOR_H__ +#define __INCLUDED_SECTOR_H__ + +#include + +namespace game +{ +class Sector { +public: + Sector(); + ~Sector(); + + /// tag used in configuration files, e.g. "terran" + std::string tag; + /// name to display, e.g. "Terran System" + std::string name; +}; + +} // namespace game + +#endif // __INCLUDED_SECTOR_H__ diff --git a/src/game/ship.cc b/src/game/ship.cc new file mode 100644 index 0000000..a24be0d --- /dev/null +++ b/src/game/ship.cc @@ -0,0 +1,85 @@ +/* ship.cc + This file is part of the Osirion project +*/ + +// C++ headers +#include + +// project headers +#include "common/functions.h" +#include "common/osirion.h" + +#include "ship.h" + +Ship::Ship() +{ + speed = 0; + yaw = 0; + yaw_offset = 0; + + thrust = 0; + + // ship specs + acceleration = 6 * GAMESCALE; + max_speed = 16.0f * GAMESCALE; + + max_yaw_offset = 45; + yaw_speed = 4; +} + +Ship::~Ship() +{ +} + +void Ship::update(float elapsed) +{ + // update yaw + float d = yaw_speed * elapsed * yaw_offset; + yaw_offset -= d; + yaw +=d; + + // update thrust + if (speed < thrust * max_speed) { + speed += acceleration * elapsed; + if (speed > thrust * max_speed) { + speed = thrust * max_speed; + } + } else if(speed > thrust * max_speed) { + speed -= acceleration * elapsed; + if (speed < 0) speed = 0; + } + + // location TODO avoid sin/cos calculations + location.x += cosf(yaw * M_PI / 180) * speed * elapsed; + location.z -= sinf(yaw * M_PI / 180) * speed * elapsed; +} + + +void Ship::thrust_increase() +{ + thrust += 0.05; + if (thrust > 1) thrust = 1; +} + +void Ship::thrust_decrease() +{ + thrust -= 0.08; + if (thrust < 0) thrust = 0; +} + +void Ship::turn_left() +{ + //yaw = degreesf(yaw + 2); + yaw_offset += 2; + if (yaw_offset > max_yaw_offset) + yaw_offset = max_yaw_offset; +} + +void Ship::turn_right() +{ + //yaw = degreesf(yaw - 2); + yaw_offset -= 2; + if (yaw_offset < -max_yaw_offset) + yaw_offset = - max_yaw_offset; +} + diff --git a/src/game/ship.h b/src/game/ship.h new file mode 100644 index 0000000..d6a00ba --- /dev/null +++ b/src/game/ship.h @@ -0,0 +1,54 @@ +/* ship.h + This file is part of the Osirion project +*/ + +#ifndef __INCLUDED_SHIP_H__ +#define __INCLUDED_SHIP_H__ + +// project headers +#include "common/vector3f.h" + +class Ship +{ +public: + Ship(); + ~Ship(); + + /// update the ship state + void update(float elapsed); + + /// location of the ship in space + Vector3f location; + /// speed vector in units/second + float speed; + + /// turn left, increase yaw_offset + void turn_left(); + /// turn right, decrease yaw_offset + void turn_right(); + /// yaw, angle in the x/z plane + float yaw; + + /// increase thrust + void thrust_increase(); + /// decrease thrust + void thrust_decrease(); + /// forward thruster in % [0-1] + float thrust; + + /* -- Ship SPECS --*/ + /// acceleration + float acceleration; + /// maximum speed + float max_speed; + /// maximum yaw_offset + float max_yaw_offset; + /// yaw turn speed + float yaw_speed; + +private: + float yaw_offset; +}; + +#endif // __INCLUDED_SHIP_H__ + diff --git a/src/game/star.cc b/src/game/star.cc new file mode 100644 index 0000000..6aa82ac --- /dev/null +++ b/src/game/star.cc @@ -0,0 +1,17 @@ +/* star.h + This file is part of the Osirion project and is distributed under + the terms and conditions of the GNU General Public License version 2 +*/ + +#include "star.h" + +Star::Star() : + location(0,0,0), + color(1,1,1,1) +{ + radius = 48; +} + +Star::~Star() +{ +} diff --git a/src/game/star.h b/src/game/star.h new file mode 100644 index 0000000..ef33ad5 --- /dev/null +++ b/src/game/star.h @@ -0,0 +1,29 @@ +/* star.h + This file is part of the Osirion project and is distributed under + the terms and conditions of the GNU General Public License version 2 +*/ + +#ifndef __INCLUDED_STAR_H__ +#define __INCLUDED_STAR_H__ + +// C++ headers +#include + +// project headers +#include "common/vector3f.h" +#include "common/color.h" + +/// A star, that shines so bright +class Star { +public: + Star(); + ~Star(); + + Vector3f location; + Color color; + float radius; + + std::string name; +}; + +#endif // __INCLUDED_STAR_H__ diff --git a/src/game/world.h b/src/game/world.h new file mode 100644 index 0000000..8cbc232 --- /dev/null +++ b/src/game/world.h @@ -0,0 +1,24 @@ +/* world.h + This file is part of the Osirion project and is distributed under + the terms and conditions of the GNU General Public License version 2 +*/ + +#ifndef __INCLUDED_WORLD_H__ +#define __INCLUDED_WORLD_H__ + +#include + +namespace game +{ + +/// The game world +namespace World { + /// load the intial game world into memory + void init(); + /// unload the game world + void shutdown(); +}; + +} // namespace game + +#endif // __INCLUDED_WORLD_H__ diff --git a/src/gl/Makefile.am b/src/gl/Makefile.am new file mode 100644 index 0000000..e7f6663 --- /dev/null +++ b/src/gl/Makefile.am @@ -0,0 +1,10 @@ + +METASOURCES = AUTO + +libosiriongl_la_LDFLAGS = -avoid-version +noinst_LTLIBRARIES = libosiriongl.la + +INCLUDES = -I$(top_srcdir)/src +libosiriongl_la_SOURCES = box.h box.cc sphere.cc sphere.h osiriongl.cc \ + osiriongl.h +noinst_HEADERS = box.h box.h diff --git a/src/gl/box.cc b/src/gl/box.cc new file mode 100644 index 0000000..67a8ed0 --- /dev/null +++ b/src/gl/box.cc @@ -0,0 +1,96 @@ +/* box.cc + This file is part of the Osirion project +*/ + +// project headers +#include "box.h" +#include "osiriongl.h" + +namespace gl { + +Box::Box(Vector3f const & tl, Vector3f const &br) : + topleft(tl), bottomright(br) +{ + topcolor = Color::White(); + bottomcolor= Color::White() * 0.7f; +} + +Box::Box(const Box & other) +{ + (*this) = other; +} + +Box& Box::operator=(const Box &other) +{ + bottomcolor = other.bottomcolor; + topcolor = other.topcolor; + + topleft = other.topleft; + bottomright = other.bottomright; + return (*this); +} + +void Box::draw() +{ + Vector3f v0(topleft.x, bottomright.y, bottomright.z); + Vector3f v1(topleft.x, topleft.y, bottomright.z); + Vector3f v2(topleft.x, topleft.y, topleft.z); + Vector3f v3(topleft.x, bottomright.y, topleft.z); + + Vector3f v4(bottomright.x, bottomright.y, bottomright.z); + Vector3f v5(bottomright.x, topleft.y, bottomright.z); + Vector3f v6(bottomright.x, topleft.y, topleft.z); + Vector3f v7(bottomright.x, bottomright.y, topleft.z); + + begin(Quads); + + // top + color(topcolor); + vertex(v2); + vertex(v1); + vertex(v5); + vertex(v6); + + // sides + color(bottomcolor); + vertex(v0); + color(topcolor); + vertex(v1); + vertex(v2); + color(bottomcolor); + vertex(v3); + + vertex(v3); + color(topcolor); + vertex(v2); + vertex(v6); + color(bottomcolor); + vertex(v7); + + vertex(v4); + color(topcolor); + vertex(v5); + vertex(v1); + color(bottomcolor); + vertex(v0); + + vertex(v7); + color(topcolor); + vertex(v6); + vertex(v5); + color(bottomcolor); + vertex(v4); + + // bottom + color(bottomcolor); + vertex(v4); + vertex(v0); + vertex(v3); + vertex(v7); + + end(); + +} + +} // namespace gl + diff --git a/src/gl/box.h b/src/gl/box.h new file mode 100644 index 0000000..f612243 --- /dev/null +++ b/src/gl/box.h @@ -0,0 +1,41 @@ +/* box.h + This file is part of the Osirion project +*/ + +#ifndef __INCLUDED_BOX_H__ +#define __INCLUDED_BOX_H__ + +#include "common/vector3f.h" +#include "common/color.h" + +namespace gl { + +/// a drawable OpenGL block shape +class Box +{ +public: + /// create a new standard cube with edge length 1 + Box(Vector3f const & tl, Vector3f const &br); + /// copy constructor + Box(const Box &other); + + /// assignment operator + Box& operator=(const Box &other); + + /// top left vertex (1,1,1) + Vector3f topleft; + /// bottom right vertex (-1,-1,-1) + Vector3f bottomright; + + /// draw the block + void draw(); + + /// Top color + Color topcolor; + /// bottom color + Color bottomcolor; +}; + +} // namespace gl + +#endif // __INCLUDED_BOX_H__ diff --git a/src/gl/osiriongl.cc b/src/gl/osiriongl.cc new file mode 100644 index 0000000..0917eec --- /dev/null +++ b/src/gl/osiriongl.cc @@ -0,0 +1,214 @@ +/* gl.cc + * This file is part of the Osirion project + */ + +// SDL headers +#include + +#include "osiriongl.h" + +namespace gl +{ + +typedef void (APIENTRY *glBegin_func)(GLenum); +typedef void (APIENTRY *glEnd_func)(); +typedef void (APIENTRY *glViewport_func)(GLint, GLint, GLsizei, GLsizei); +typedef void (APIENTRY *glDepthMask_func)(GLenum); +typedef void (APIENTRY *glFrontFace_func)(GLenum); +typedef void (APIENTRY *glCullFace_func)(GLenum); +typedef void (APIENTRY *glShadeModel_func)(GLenum); +typedef void (APIENTRY *glEnable_func)(GLenum); +typedef void (APIENTRY *glClear_func)(GLbitfield); +typedef void (APIENTRY *glClearColor_func)(GLclampf, GLclampf, GLclampf,GLclampf); +typedef void (APIENTRY *glRotatef_func)(GLfloat, GLfloat, GLfloat, GLfloat); +typedef void (APIENTRY *glTranslatef_func)(GLfloat, GLfloat, GLfloat); +typedef void (APIENTRY *glScalef_func)(GLfloat, GLfloat, GLfloat); +typedef void (APIENTRY *glVertex3f_func)(GLfloat, GLfloat, GLfloat); +typedef void (APIENTRY *glPushMatrix_func)(); +typedef void (APIENTRY *glPopMatrix_func)(); +typedef void (APIENTRY *glColor4f_func)(GLfloat, GLfloat, GLfloat, GLfloat); +typedef void (APIENTRY *glMatrixMode_func)(GLenum); +typedef void (APIENTRY *glLoadIdentity_func)(); +typedef void (APIENTRY *glFrustum_func)(GLdouble, GLdouble, GLdouble, GLdouble, GLdouble, GLdouble); + +glBegin_func osglBegin = 0; +glEnd_func osglEnd = 0; +glViewport_func osglViewport = 0; +glDepthMask_func osglDepthMask = 0; +glFrontFace_func osglFrontFace = 0; +glCullFace_func osglCullFace = 0; +glShadeModel_func osglShadeModel = 0; +glEnable_func osglEnable = 0; +glClear_func osglClear = 0; +glClearColor_func osglClearColor = 0; +glRotatef_func osglRotatef = 0; +glTranslatef_func osglTranslatef = 0; +glScalef_func osglScalef = 0; +glVertex3f_func osglVertex3f = 0; +glPushMatrix_func osglPushMatrix = 0; +glPopMatrix_func osglPopMatrix = 0; +glColor4f_func osglColor4f = 0; +glMatrixMode_func osglMatrixMode = 0; +glLoadIdentity_func osglLoadIdentity = 0; +glFrustum_func osglFrustum = 0; + +// ------------- INITIALIZE FUNCTION POINTERS --------------// +void init() +{ + osglBegin = (glBegin_func) SDL_GL_GetProcAddress("glBegin"); + osglEnd = (glEnd_func) SDL_GL_GetProcAddress("glEnd"); + osglViewport = (glViewport_func) SDL_GL_GetProcAddress("glViewport"); + osglDepthMask = (glDepthMask_func) SDL_GL_GetProcAddress("glDepthMask"); + osglFrontFace = (glFrontFace_func) SDL_GL_GetProcAddress("glFrontFace"); + osglCullFace = (glCullFace_func) SDL_GL_GetProcAddress("glCullFace"); + osglShadeModel = (glShadeModel_func) SDL_GL_GetProcAddress("glShadeModel"); + osglEnable = (glEnable_func) SDL_GL_GetProcAddress("glEnable"); + osglClear = (glClear_func) SDL_GL_GetProcAddress("glClear"); + osglClearColor = (glClearColor_func) SDL_GL_GetProcAddress("glClearColor"); + osglRotatef = (glRotatef_func) SDL_GL_GetProcAddress("glRotatef"); + osglTranslatef = (glTranslatef_func) SDL_GL_GetProcAddress("glTranslatef"); + osglScalef = (glScalef_func) SDL_GL_GetProcAddress("glScalef"); + osglVertex3f = (glVertex3f_func) SDL_GL_GetProcAddress("glVertex3f"); + osglPushMatrix = (glPushMatrix_func) SDL_GL_GetProcAddress("glPushMatrix"); + osglPopMatrix = (glPopMatrix_func) SDL_GL_GetProcAddress("glPopMatrix"); + osglColor4f = (glColor4f_func) SDL_GL_GetProcAddress("glColor4f"); + osglMatrixMode = (glMatrixMode_func) SDL_GL_GetProcAddress("glMatrixMode"); + osglLoadIdentity = (glLoadIdentity_func) SDL_GL_GetProcAddress("glLoadIdentity"); + osglFrustum = (glFrustum_func) SDL_GL_GetProcAddress("glFrustum"); +} + + +void shutdown() +{ + osglBegin = 0; + osglEnd = 0; + osglViewport = 0; + osglDepthMask = 0; + osglFrontFace = 0; + osglCullFace = 0; + osglShadeModel = 0; + osglEnable = 0; + osglClear = 0; + osglClearColor = 0; + osglRotatef = 0; + osglTranslatef = 0; + osglScalef = 0; + osglVertex3f = 0; + osglPushMatrix = 0; + osglPopMatrix = 0; + osglColor4f = 0; + osglMatrixMode = 0; + osglLoadIdentity = 0; +} + +void begin(Primitive primitive) { + osglBegin(primitive); +} + +void end() { + osglEnd(); +} + +void viewport(GLint x, GLint y, GLsizei width, GLsizei height) +{ + osglViewport(x, y, width, height); +} + +void depthmask(GLenum mode) +{ + osglDepthMask(mode); +} + + +void frontface(GLenum mode) +{ + osglFrontFace(mode); +} + +void cullface(GLenum mode) +{ + osglCullFace(mode); +} + +void shademodel(GLenum mode) +{ + osglShadeModel(mode); +} + +void enable(GLenum cap) +{ + osglEnable(cap); +} + +void clear (GLbitfield mask) { + osglClear(mask); +} + +void clearcolor(Color const & color) { + osglClearColor(color.red(), color.green(), color.blue(), color.alpha()); +} + +void clearcolor(const float r, const float g, const float b, const float a) { + osglClearColor(r,g,b, a); +} + +void rotate(const float angle, const Vector3f& vector) { + osglRotatef(angle, vector[0], vector[1], vector[2]); +} + +void rotate(const float angle, const float x, const float y, const float z) { + osglRotatef(angle, x, y, z); +} + +void translate(const Vector3f& vector) { + osglTranslatef(vector[0], vector[1], vector[2]); +} + +void translate(const float x, const float y, const float z) { + osglTranslatef(x, y, z); +} +void scale(const Vector3f& vector) { + osglScalef(vector[0], vector[1], vector[2]); +} + +void scale(const float x, const float y, const float z) { + osglScalef(x, y, z); +} + +void vertex(const Vector3f& vector) { + osglVertex3f(vector[0], vector[1], vector[2]); +} + +void vertex(const float x, const float y, const float z) { + osglVertex3f(x, y, z); +} + +void push() { + osglPushMatrix(); +} + +void pop() { + osglPopMatrix(); +} + +void color(const float r, const float g, const float b, const float a) { + osglColor4f(r,g,b,a); +} +void color(Color const & color) { + osglColor4f(color.red(), color.green(), color.blue(), color.alpha()); +} + +void matrixmode(GLenum mode) { + osglMatrixMode(mode); +} + +void loadidentity() { + osglLoadIdentity(); +} + +void frustum(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble znear, GLdouble zfar) +{ + osglFrustum(left, right, bottom, top, znear, zfar); +} + +} // namespace gl diff --git a/src/gl/osiriongl.h b/src/gl/osiriongl.h new file mode 100644 index 0000000..92c0db3 --- /dev/null +++ b/src/gl/osiriongl.h @@ -0,0 +1,158 @@ +/* gl.h + This file is part of the Osirion project +*/ + +#ifndef __INCLUDED_OSIRIONGL_H__ +#define __INCLUDED_OSIRIONGL_H__ + +// OpenGL headers +#include + +// project headers +#include "common/vector3f.h" +#include "common/color.h" + +/// wrapper namespace for OpenGL operations +/*! The GL namespace provides a wrapper to the OpenGL library functions. + * All methods take floats or Vector3f and Color as parameters. + */ +namespace gl +{ + /// initialize the OpenGL subsystem + void init(); + + /// shutdown the OpenGL subsystem + void shutdown(); + + /// enum to denote Vertex drawing modes + enum Primitive { + Points=GL_POINTS, + Lines=GL_LINES, + LineStrip=GL_LINE_STRIP, + LineLoop=GL_LINE_LOOP, + Triangles=GL_TRIANGLES, + TriangleStrip=GL_TRIANGLE_STRIP, + TriangleFan=GL_TRIANGLE_FAN, + Quads=GL_QUADS, + QuadStrip=GL_QUAD_STRIP, + Polygon=GL_POLYGON + }; + + + /// glViewPort + void viewport(GLint x, GLint y, GLsizei width, GLsizei height ); + + /// set the color used to clear to buffer + void clearcolor(Color const &color); + /// set the color used to clear to buffer + void clearcolor(const float r, const float g, const float b, const float a); + + /// clear buffers to preset values + void clear (GLbitfield mask); + + /// glMatrixMode + void matrixmode(GLenum mode); + + /// glEnable + void enable(GLenum cap); + + /// glShadeModel + void shademodel(GLenum mode); + + /// glCullFace + void cullface(GLenum mode); + + /// glFrontFace + void frontface(GLenum mode); + + + /// glDepthMask + void depthmask(GLenum mode); + + /// Delimite the start of a sequence of verteces describing a primitive or group of primitives + /*! @param primitive The type of drawing primitive + * @see end() + */ + void begin(Primitive primitive); + + /// Delimit the end of a sequence of verteces describing a primitive or group of primitives + /*! @see begin() + */ + void end(); + + /// Add the next vertex the the current drawing operation + /*! From the glVertex() description: + * vertex() commands are used within begin()/end() pairs to specify point, + * line, and polygon vertices. The current color, normal, and texture + * coordinates are associated with the vertex when vertex() is called. + */ + void vertex(const Vector3f& vector); + + void vertex(const float x, const float y, const float z); + + /// Multiply the current matrix by a general rotation matrix + /*! @param angle The angle of the rotation, in degrees [0-360] + * @param vector The rotation axes, relative to the origin (0,0,0) + */ + void rotate(const float angle, const Vector3f& vector); + + /// Multiply the current matrix by a general rotation matrix + /*! @param angle The angle of the rotation, in degrees + * @param x The x-coordinate of the rotation vector + * @param y The y-coordinate of the rotation vector + * @param z The z-coordinate of the rotation vector + */ + void rotate(const float angle, const float x, const float y, const float z); + + /// Multiply the current matrix by a general translation matrix + /*! @param vector The translation vector, relative to the origin (0,0,0) + */ + void translate(const Vector3f& vector); + + /// Multiply the current matrix by a general translation matrix + /*! + * @param x The x-coordinate of the translation vector + * @param y The y-coordinate of the translation vector + * @param z The z-coordinate of the translation vector + */ + void translate(const float x, const float y, const float z); + + /// Multiply the current matrix by a general scaling matrix + /*! @param vector The scale factor for all 3 axes + */ + void scale(const Vector3f& vector); + + /// Multiply the current matrix by a general scaling matrix + /*! + * @param x x-scaling factor + * @param y y-scaling factor + * @param z z-scaling factor + */ + void scale(const float x, const float y, const float z); + + /// Specify the drawing color for the next GL functions + /*! @param color the new drawing color + */ + void color(Color const & color); + + /*! @param r red value of the new drawing color + * @param g green value of the new drawing color + * @param b blue value of the new drawing color + * @param a alpha value of the new drawing color + */ + void color(const float r, const float g, const float b, const float a=1.0f); + + /// Push the current transformation matrix to the stack + void push(); + + /// Replace the transformation matrix with the top from the stack + void pop(); + + /// Replace the transformation matrix with the identity matrtix + void loadidentity(); + + /// Perspective matrix + void frustum(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble znear, GLdouble zfar); +}; + +#endif // __INCLUDED_OSIRIONGL_H__ diff --git a/src/gl/sphere.cc b/src/gl/sphere.cc new file mode 100644 index 0000000..5e4e931 --- /dev/null +++ b/src/gl/sphere.cc @@ -0,0 +1,89 @@ +/* sphere.cc + This file is part of the Osirion project +*/ + +#include "common/functions.h" + +#include "osiriongl.h" +#include "sphere.h" + +namespace gl { + +const int segments = 33; + +Sphere::Sphere(Vector3f p , float r) +{ + position = p; + radius = r; + + // TODO make global sine-cosine lists + sintable = new float[segments]; + costable = new float[segments]; + float d = 2 * M_PI / segments; + + for (int i=0; i < segments; i++) { + sintable[i] = sin( d * (float) i ); + costable[i] = cos ( d * (float) i ); + } +} + +Sphere::~Sphere() +{ + delete sintable; + delete costable; +} + +Sphere::Sphere(const Sphere &other) +{ + (*this) = other; +} + +Sphere& Sphere::operator=(const Sphere &other) +{ + position = other.position; + radius = other.radius; +} + +void Sphere::draw() +{ + // draw top + // TODO upside-down + float r = radius*sintable[1]; + float h = radius*costable[1]; + + begin(LineLoop); + //begin(Polygon); + for (int i = segments-1; i >= 0; i--) + vertex(r*costable[i], h, r*sintable[i]); + end(); + + // draw bottom + // TODO upside-down + begin(LineLoop); + for (int i = 0; i< segments; i++) + vertex(r*costable[i], -h, r*sintable[i]); + end(); + + // draw body + for (int j=1; j < segments-1; j++) { + r = radius*sintable[j]; + float r1 = radius*sintable[j+1]; + + begin(QuadStrip); + vertex(r1, radius*costable[j+1], 0); + vertex(r, radius*costable[j], 0); + + for (int i = segments-1; i >= 0; i--) { + vertex(r1*costable[i], radius*costable[j+1], r1*sintable[i]); + vertex(r*costable[i], radius*costable[j], r*sintable[i]); + //vertex(r*costable[i-1], radius*costable[j], r*sintable[i-1]); + //vertex(r1*costable[i-1], radius*costable[j+1], r1*sintable[i-1]); + } + end(); + + } +} + + +} // namespace gl + diff --git a/src/gl/sphere.h b/src/gl/sphere.h new file mode 100644 index 0000000..f2bbf0a --- /dev/null +++ b/src/gl/sphere.h @@ -0,0 +1,50 @@ +/* sphere.h + This file is part of the Osirion project +*/ + +#ifndef __INCLUDED_SPHERE_H__ +#define __INCLUDED_SPHERE_H__ + +#include "common/vector3f.h" +#include "common/color.h" + +namespace gl { + +/// a drawable OpenGL block shape +class Sphere +{ +public: + /// create a new sphere + Sphere(Vector3f p = Vector3f(), float r = 1.0f); + + /// copy constructor + Sphere(const Sphere &other); + + /// destructor + ~Sphere(); + + /// assignment operator + Sphere& operator=(const Sphere &other); + + /// radius of the sphere + float radius; + + /// position of the sphere + Vector3f position; + + /// draw the sphere + void draw(); + + /// Top color + Color topcolor; + /// bottom color + Color bottomcolor; + +private: + float *sintable; + float *costable; +}; + +} // namespace gl + +#endif // __INCLUDED_SPHERE_H__ diff --git a/templates/cpp b/templates/cpp new file mode 100644 index 0000000..99b52be --- /dev/null +++ b/templates/cpp @@ -0,0 +1,4 @@ +/* $FILE$ + This file is part of the Osirion project and is distributed under + the terms of the GNU General Public License version 2 +*/ diff --git a/templates/h b/templates/h new file mode 100644 index 0000000..99b52be --- /dev/null +++ b/templates/h @@ -0,0 +1,4 @@ +/* $FILE$ + This file is part of the Osirion project and is distributed under + the terms of the GNU General Public License version 2 +*/ -- cgit v1.2.3