Recovered from microbel

This commit is contained in:
rot
2025-03-05 08:35:31 +01:00
committed by h7x4
commit 88b92402a8
601 changed files with 82177 additions and 0 deletions

View File

@@ -0,0 +1,4 @@
INCLUDES = -I../../include
noinst_LIBRARIES = libpvvmudutils.a
libpvvmudutils_a_SOURCES = beam.C crossindex.C doublearray.C intarray.C matrix.C namedb.C objectarray.C plane.C time.C vector.C option.C getopt.c getopt1.c pingpong.C commandparser.C keyframe.C spline.C

View File

@@ -0,0 +1,337 @@
# Makefile.in generated automatically by automake 1.4 from Makefile.am
# Copyright (C) 1994, 1995-8, 1999 Free Software Foundation, Inc.
# This Makefile.in is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE.
SHELL = @SHELL@
srcdir = @srcdir@
top_srcdir = @top_srcdir@
VPATH = @srcdir@
prefix = @prefix@
exec_prefix = @exec_prefix@
bindir = @bindir@
sbindir = @sbindir@
libexecdir = @libexecdir@
datadir = @datadir@
sysconfdir = @sysconfdir@
sharedstatedir = @sharedstatedir@
localstatedir = @localstatedir@
libdir = @libdir@
infodir = @infodir@
mandir = @mandir@
includedir = @includedir@
oldincludedir = /usr/include
DESTDIR =
pkgdatadir = $(datadir)/@PACKAGE@
pkglibdir = $(libdir)/@PACKAGE@
pkgincludedir = $(includedir)/@PACKAGE@
top_builddir = ../../..
ACLOCAL = @ACLOCAL@
AUTOCONF = @AUTOCONF@
AUTOMAKE = @AUTOMAKE@
AUTOHEADER = @AUTOHEADER@
INSTALL = @INSTALL@
INSTALL_PROGRAM = @INSTALL_PROGRAM@ $(AM_INSTALL_PROGRAM_FLAGS)
INSTALL_DATA = @INSTALL_DATA@
INSTALL_SCRIPT = @INSTALL_SCRIPT@
transform = @program_transform_name@
NORMAL_INSTALL = :
PRE_INSTALL = :
POST_INSTALL = :
NORMAL_UNINSTALL = :
PRE_UNINSTALL = :
POST_UNINSTALL = :
CC = @CC@
CXX = @CXX@
GL_CFLAGS = @GL_CFLAGS@
GL_LIBS = @GL_LIBS@
LEX = @LEX@
MAKEINFO = @MAKEINFO@
NETLIBS = @NETLIBS@
PACKAGE = @PACKAGE@
RANLIB = @RANLIB@
TIFF_CFLAGS = @TIFF_CFLAGS@
TIFF_LIBS = @TIFF_LIBS@
VERSION = @VERSION@
YACC = @YACC@
INCLUDES = -I../../include
noinst_LIBRARIES = libpvvmudutils.a
libpvvmudutils_a_SOURCES = beam.C crossindex.C doublearray.C intarray.C matrix.C namedb.C objectarray.C plane.C time.C vector.C option.C getopt.c getopt1.c pingpong.C commandparser.C keyframe.C spline.C
mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs
CONFIG_CLEAN_FILES =
LIBRARIES = $(noinst_LIBRARIES)
DEFS = @DEFS@ -I. -I$(srcdir)
CPPFLAGS = @CPPFLAGS@
LDFLAGS = @LDFLAGS@
LIBS = @LIBS@
X_CFLAGS = @X_CFLAGS@
X_LIBS = @X_LIBS@
X_EXTRA_LIBS = @X_EXTRA_LIBS@
X_PRE_LIBS = @X_PRE_LIBS@
libpvvmudutils_a_LIBADD =
libpvvmudutils_a_OBJECTS = beam.o crossindex.o doublearray.o intarray.o \
matrix.o namedb.o objectarray.o plane.o time.o vector.o option.o \
getopt.o getopt1.o pingpong.o commandparser.o keyframe.o spline.o
AR = ar
CXXFLAGS = @CXXFLAGS@
CXXCOMPILE = $(CXX) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS)
CXXLD = $(CXX)
CXXLINK = $(CXXLD) $(AM_CXXFLAGS) $(CXXFLAGS) $(LDFLAGS) -o $@
CFLAGS = @CFLAGS@
COMPILE = $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
CCLD = $(CC)
LINK = $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(LDFLAGS) -o $@
DIST_COMMON = Makefile.am Makefile.in
DISTFILES = $(DIST_COMMON) $(SOURCES) $(HEADERS) $(TEXINFOS) $(EXTRA_DIST)
TAR = gtar
GZIP_ENV = --best
DEP_FILES = .deps/beam.P .deps/commandparser.P .deps/crossindex.P \
.deps/doublearray.P .deps/getopt.P .deps/getopt1.P .deps/intarray.P \
.deps/keyframe.P .deps/matrix.P .deps/namedb.P .deps/objectarray.P \
.deps/option.P .deps/pingpong.P .deps/plane.P .deps/spline.P \
.deps/time.P .deps/vector.P
SOURCES = $(libpvvmudutils_a_SOURCES)
OBJECTS = $(libpvvmudutils_a_OBJECTS)
all: all-redirect
.SUFFIXES:
.SUFFIXES: .C .S .c .o .s
$(srcdir)/Makefile.in: Makefile.am $(top_srcdir)/configure.in $(ACLOCAL_M4)
cd $(top_srcdir) && $(AUTOMAKE) --foreign common/lib/utils/Makefile
Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status $(BUILT_SOURCES)
cd $(top_builddir) \
&& CONFIG_FILES=$(subdir)/$@ CONFIG_HEADERS= $(SHELL) ./config.status
mostlyclean-noinstLIBRARIES:
clean-noinstLIBRARIES:
-test -z "$(noinst_LIBRARIES)" || rm -f $(noinst_LIBRARIES)
distclean-noinstLIBRARIES:
maintainer-clean-noinstLIBRARIES:
.s.o:
$(COMPILE) -c $<
.S.o:
$(COMPILE) -c $<
mostlyclean-compile:
-rm -f *.o core *.core
clean-compile:
distclean-compile:
-rm -f *.tab.c
maintainer-clean-compile:
libpvvmudutils.a: $(libpvvmudutils_a_OBJECTS) $(libpvvmudutils_a_DEPENDENCIES)
-rm -f libpvvmudutils.a
$(AR) cru libpvvmudutils.a $(libpvvmudutils_a_OBJECTS) $(libpvvmudutils_a_LIBADD)
$(RANLIB) libpvvmudutils.a
.C.o:
$(CXXCOMPILE) -c $<
tags: TAGS
ID: $(HEADERS) $(SOURCES) $(LISP)
list='$(SOURCES) $(HEADERS)'; \
unique=`for i in $$list; do echo $$i; done | \
awk ' { files[$$0] = 1; } \
END { for (i in files) print i; }'`; \
here=`pwd` && cd $(srcdir) \
&& mkid -f$$here/ID $$unique $(LISP)
TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) $(LISP)
tags=; \
here=`pwd`; \
list='$(SOURCES) $(HEADERS)'; \
unique=`for i in $$list; do echo $$i; done | \
awk ' { files[$$0] = 1; } \
END { for (i in files) print i; }'`; \
test -z "$(ETAGS_ARGS)$$unique$(LISP)$$tags" \
|| (cd $(srcdir) && etags $(ETAGS_ARGS) $$tags $$unique $(LISP) -o $$here/TAGS)
mostlyclean-tags:
clean-tags:
distclean-tags:
-rm -f TAGS ID
maintainer-clean-tags:
distdir = $(top_builddir)/$(PACKAGE)-$(VERSION)/$(subdir)
subdir = common/lib/utils
distdir: $(DISTFILES)
here=`cd $(top_builddir) && pwd`; \
top_distdir=`cd $(top_distdir) && pwd`; \
distdir=`cd $(distdir) && pwd`; \
cd $(top_srcdir) \
&& $(AUTOMAKE) --include-deps --build-dir=$$here --srcdir-name=$(top_srcdir) --output-dir=$$top_distdir --foreign common/lib/utils/Makefile
@for file in $(DISTFILES); do \
d=$(srcdir); \
if test -d $$d/$$file; then \
cp -pr $$/$$file $(distdir)/$$file; \
else \
test -f $(distdir)/$$file \
|| ln $$d/$$file $(distdir)/$$file 2> /dev/null \
|| cp -p $$d/$$file $(distdir)/$$file || :; \
fi; \
done
DEPS_MAGIC := $(shell mkdir .deps > /dev/null 2>&1 || :)
-include $(DEP_FILES)
mostlyclean-depend:
clean-depend:
distclean-depend:
-rm -rf .deps
maintainer-clean-depend:
%.o: %.c
@echo '$(COMPILE) -c $<'; \
$(COMPILE) -Wp,-MD,.deps/$(*F).pp -c $<
@-cp .deps/$(*F).pp .deps/$(*F).P; \
tr ' ' '\012' < .deps/$(*F).pp \
| sed -e 's/^\\$$//' -e '/^$$/ d' -e '/:$$/ d' -e 's/$$/ :/' \
>> .deps/$(*F).P; \
rm .deps/$(*F).pp
%.lo: %.c
@echo '$(LTCOMPILE) -c $<'; \
$(LTCOMPILE) -Wp,-MD,.deps/$(*F).pp -c $<
@-sed -e 's/^\([^:]*\)\.o[ ]*:/\1.lo \1.o :/' \
< .deps/$(*F).pp > .deps/$(*F).P; \
tr ' ' '\012' < .deps/$(*F).pp \
| sed -e 's/^\\$$//' -e '/^$$/ d' -e '/:$$/ d' -e 's/$$/ :/' \
>> .deps/$(*F).P; \
rm -f .deps/$(*F).pp
%.o: %.C
@echo '$(CXXCOMPILE) -c $<'; \
$(CXXCOMPILE) -Wp,-MD,.deps/$(*F).pp -c $<
@-cp .deps/$(*F).pp .deps/$(*F).P; \
tr ' ' '\012' < .deps/$(*F).pp \
| sed -e 's/^\\$$//' -e '/^$$/ d' -e '/:$$/ d' -e 's/$$/ :/' \
>> .deps/$(*F).P; \
rm .deps/$(*F).pp
%.lo: %.C
@echo '$(LTCXXCOMPILE) -c $<'; \
$(LTCXXCOMPILE) -Wp,-MD,.deps/$(*F).pp -c $<
@-sed -e 's/^\([^:]*\)\.o[ ]*:/\1.lo \1.o :/' \
< .deps/$(*F).pp > .deps/$(*F).P; \
tr ' ' '\012' < .deps/$(*F).pp \
| sed -e 's/^\\$$//' -e '/^$$/ d' -e '/:$$/ d' -e 's/$$/ :/' \
>> .deps/$(*F).P; \
rm -f .deps/$(*F).pp
info-am:
info: info-am
dvi-am:
dvi: dvi-am
check-am: all-am
check: check-am
installcheck-am:
installcheck: installcheck-am
install-exec-am:
install-exec: install-exec-am
install-data-am:
install-data: install-data-am
install-am: all-am
@$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
install: install-am
uninstall-am:
uninstall: uninstall-am
all-am: Makefile $(LIBRARIES)
all-redirect: all-am
install-strip:
$(MAKE) $(AM_MAKEFLAGS) AM_INSTALL_PROGRAM_FLAGS=-s install
installdirs:
mostlyclean-generic:
clean-generic:
distclean-generic:
-rm -f Makefile $(CONFIG_CLEAN_FILES)
-rm -f config.cache config.log stamp-h stamp-h[0-9]*
maintainer-clean-generic:
mostlyclean-am: mostlyclean-noinstLIBRARIES mostlyclean-compile \
mostlyclean-tags mostlyclean-depend mostlyclean-generic
mostlyclean: mostlyclean-am
clean-am: clean-noinstLIBRARIES clean-compile clean-tags clean-depend \
clean-generic mostlyclean-am
clean: clean-am
distclean-am: distclean-noinstLIBRARIES distclean-compile \
distclean-tags distclean-depend distclean-generic \
clean-am
distclean: distclean-am
maintainer-clean-am: maintainer-clean-noinstLIBRARIES \
maintainer-clean-compile maintainer-clean-tags \
maintainer-clean-depend maintainer-clean-generic \
distclean-am
@echo "This command is intended for maintainers to use;"
@echo "it deletes files that may require special tools to rebuild."
maintainer-clean: maintainer-clean-am
.PHONY: mostlyclean-noinstLIBRARIES distclean-noinstLIBRARIES \
clean-noinstLIBRARIES maintainer-clean-noinstLIBRARIES \
mostlyclean-compile distclean-compile clean-compile \
maintainer-clean-compile tags mostlyclean-tags distclean-tags \
clean-tags maintainer-clean-tags distdir mostlyclean-depend \
distclean-depend clean-depend maintainer-clean-depend info-am info \
dvi-am dvi check check-am installcheck-am installcheck install-exec-am \
install-exec install-data-am install-data install-am install \
uninstall-am uninstall all-redirect all-am all installdirs \
mostlyclean-generic distclean-generic clean-generic \
maintainer-clean-generic clean mostlyclean distclean maintainer-clean
# Tell versions [3.59,3.63) of GNU make to not export all variables.
# Otherwise a system limit (for SysV at least) may be exceeded.
.NOEXPORT:

80
common/lib/utils/beam.C Normal file
View File

@@ -0,0 +1,80 @@
/*
* PVVMUD a 3D MUD
* Copyright (C) 1998-1999 Programvareverkstedet (pvv@pvv.org)
*
* 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
*
*/
#include "pvvmud.H"
#include "beam.H"
CBeam::CBeam(){
}
CBeam::CBeam(const CVector & point,const CVector & direction){
m_point = point;
m_direction = direction;
}
CBeam::CBeam(const CVertex & point,const CVector & direction){
m_point = CVector(point.getX(),point.getY(),point.getZ());
m_direction = direction;
}
CBeam::CBeam(const CPosition & point,const CVector & direction){
m_point = CVector(point.getX(),point.getY(),point.getZ());
m_direction = direction;
}
const CVector & CBeam::getPoint() const{
return m_point;
}
const CVector & CBeam::getDirection() const{
return m_direction;
}
CBeam CBeam::operator+ (const CPosition& position) const{
CBeam result;
result = *this;
CVector pos(position.getX(),position.getY(),position.getZ());
result.m_point += pos;
return result;
}
void CBeam::transform(const CMatrix & transformation){
CVector p2 = m_point + m_direction;
m_point.transform(transformation);
p2.transform(transformation);
m_direction = p2 - m_point;
}
///////////////////////////////////////////////////////////////////////////////
// CBeam::intersect
// Info : Check intersection between beam and a bBox
// Return : Return true if beam intersect with bBox
// Implementation: HACK only check if point inside in XY plane
///////////////////////////////////////////////////////////////////////////////
int CBeam::intersect(const CBBox & bBox) const {
// cdebug << "CBeam::intersect : Hack impl.\n";
return bBox.insideXY(m_point);
}
ostream& operator<<(ostream&s,const CBeam& b){
return s << "( P: " << b.getPoint() << ", D: " << b.getDirection() << " )";
}

View File

@@ -0,0 +1,114 @@
/*
* PVVMUD a 3D MUD
* Copyright (C) 1998-1999 Programvareverkstedet (pvv@pvv.org)
*
* 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
*
*/
#include "commandparser.H"
CCommandParser::CCommand::CCommand(string & commandString,CommandFunc_t commandFunc){
m_commandString = commandString;
m_commandFunc = commandFunc;
}
string & CCommandParser::CCommand::getCommandString(){
return m_commandString;
}
void CCommandParser::CCommand::executeCommand(argv_t & argv,
CCommandParser * parser)
{
(parser->*m_commandFunc)(argv);
}
CCommandParser::CCommandParser(){
m_commandPrefix = '/';
}
///////////////////////////////////////////////////////////////////////////////
// parseCommand
// Parse commands on the form "/command", "/command arg...", "Message..."
// Side effects on commandString:
// Any command with arguments will be null terminated before arguments
///////////////////////////////////////////////////////////////////////////////
void CCommandParser::parseCommand(const string & commandString){
string command = commandString;
if (command[0] != m_commandPrefix){ // Is this a message?
commandChat(command);
} else { // No it is a command
command.erase(0,1); // Don't need leading '/'
argv_t argv;
createArgv(command,argv);
for (int index = 0; index < m_commandList.size(); index++){
if (m_commandList[index].getCommandString() == argv[0]){
m_commandList[index].executeCommand(argv,this);
return;
}
}
commandUnknown(commandString);
}
}
void CCommandParser::setCommandPrefix(char commandPrefix){
m_commandPrefix = commandPrefix;
}
///////////////////////////////////////////////////////////////////////////////
// createArgv
// Convert string to table of strings
///////////////////////////////////////////////////////////////////////////////
void CCommandParser::createArgv(string & argString, argv_t & argv){
string::size_type pos;
// Remove all double spaces
while ((pos = argString.find(" ")) != string::npos)
argString.replace(pos,2," ");
// Create argv
string::size_type last = 0;
string::size_type next;
while ((next = argString.find(" ",last)) != string::npos) {
argv.push_back(string(argString,last,next-last));
last = next + 1;
}
next = argString.size();
argv.push_back(string(argString,last,next));
}
///////////////////////////////////////////////////////////////////////////////
// addCommand
///////////////////////////////////////////////////////////////////////////////
void CCommandParser::addCommand(string commandString,
CommandFunc_t commandFunc)
{
m_commandList.push_back( CCommand(commandString,commandFunc));
}
void CCommandParser::commandChat(const string & chatMessage){
commandUnknown(chatMessage);
}
void CCommandParser::commandUnknown(const string & commandString){
}

View File

@@ -0,0 +1,64 @@
/*
* PVVMUD a 3D MUD
* Copyright (C) 1998-1999 Programvareverkstedet (pvv@pvv.org)
*
* 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
*
*/
#include <stdlib.h>
#include "mudtypes.h"
#include "crossindex.H"
CCrossIndexItem::CCrossIndexItem(int indexA,int indexB) {
next = NULL;
this->indexA = indexA;
this->indexB = indexB;
}
CCrossIndexItem * CCrossIndex::add(int indexA,int indexB){
CCrossIndexItem *newItem = new CCrossIndexItem(indexA,indexB);
newItem->setNext(first);
first=newItem;
return newItem;
}
int CCrossIndex::getA(int indexB){
CCrossIndexItem * currItem;
currItem = first;
while (currItem != NULL) {
if (currItem->getIndexB() == indexB) return currItem->getIndexA();
currItem = currItem->getNext();
}
return -1;
}
int CCrossIndex::getB(int indexA){
CCrossIndexItem * currItem;
currItem = first;
while (currItem != NULL) {
if (currItem->getIndexA() == indexA) return currItem->getIndexB();
currItem = currItem->getNext();
}
return -1;
}

View File

@@ -0,0 +1,82 @@
/*
* PVVMUD a 3D MUD
* Copyright (C) 1998-1999 Programvareverkstedet (pvv@pvv.org)
*
* 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
*
*/
#include "pvvmud.H"
#include <stdlib.h>
#include <iostream.h>
#include "doublearray.H"
CDoubleArray::CDoubleArray(){
m_size = 0;
m_num = 0;
m_array = NULL;
}
CDoubleArray::~CDoubleArray(){
if (m_array != NULL) free(m_array);
}
int CDoubleArray::add( double num ){
if (m_num >= m_size){
if (m_array == NULL){
m_array = (double*)malloc(sizeof(double)*4);
m_size = 4;
} else {
m_array = (double*)realloc(m_array,sizeof(double)*m_size*2);
m_size *=2;
}
}
m_array[m_num] = num;
return m_num++;
}
int CDoubleArray::add( CDoubleArray * doubleArray ){
int ii,tmp;
int num = doubleArray->getNumElements();
for (ii = 0; ii < num; ii ++){
tmp = add(doubleArray->get(ii));
}
return tmp;
}
int CDoubleArray::insert( double num ){
cdebug << "WARNING: CDoubleArray::insert NOT IMPLEMENTED!\n";
return 0;
}
double CDoubleArray::get( int index ) const{
return m_array[index];
}
int CDoubleArray::getNumElements() const{
return m_num;
}
void CDoubleArray::deleteAll(){
m_num = 0;
}
ostream& operator<<(ostream&s,const CDoubleArray& d) {
int index;
s << "[ ";
for (index = 0; index < d.getNumElements(); index ++)
s << d.get(index) << " ";
return s << "]";
}

1050
common/lib/utils/getopt.c Normal file

File diff suppressed because it is too large Load Diff

131
common/lib/utils/getopt.h Normal file
View File

@@ -0,0 +1,131 @@
/* Declarations for getopt.
Copyright (C) 1989,90,91,92,93,94,96,97 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The GNU C Library 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
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the GNU C Library; see the file COPYING.LIB. If not,
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
#ifndef _GETOPT_H
#define _GETOPT_H 1
#ifdef __cplusplus
extern "C" {
#endif
/* For communication from `getopt' to the caller.
When `getopt' finds an option that takes an argument,
the argument value is returned here.
Also, when `ordering' is RETURN_IN_ORDER,
each non-option ARGV-element is returned here. */
extern char *optarg;
/* Index in ARGV of the next element to be scanned.
This is used for communication to and from the caller
and for communication between successive calls to `getopt'.
On entry to `getopt', zero means this is the first call; initialize.
When `getopt' returns -1, this is the index of the first of the
non-option elements that the caller should itself scan.
Otherwise, `optind' communicates from one call to the next
how much of ARGV has been scanned so far. */
extern int optind;
/* Callers store zero here to inhibit the error message `getopt' prints
for unrecognized options. */
extern int opterr;
/* Set to an option character which was unrecognized. */
extern int optopt;
/* Describe the long-named options requested by the application.
The LONG_OPTIONS argument to getopt_long or getopt_long_only is a vector
of `struct option' terminated by an element containing a name which is
zero.
The field `has_arg' is:
no_argument (or 0) if the option does not take an argument,
required_argument (or 1) if the option requires an argument,
optional_argument (or 2) if the option takes an optional argument.
If the field `flag' is not NULL, it points to a variable that is set
to the value given in the field `val' when the option is found, but
left unchanged if the option is not found.
To have a long-named option do something other than set an `int' to
a compiled-in constant, such as set a value from `optarg', set the
option's `flag' field to zero and its `val' field to a nonzero
value (the equivalent single-letter option character, if there is
one). For long options that have a zero `flag' field, `getopt'
returns the contents of the `val' field. */
struct option
{
#if defined (__STDC__) && __STDC__
const char *name;
#else
char *name;
#endif
/* has_arg can't be an enum because some compilers complain about
type mismatches in all the code that assumes it is an int. */
int has_arg;
int *flag;
int val;
};
/* Names for the values of the `has_arg' field of `struct option'. */
#define no_argument 0
#define required_argument 1
#define optional_argument 2
#if defined (__STDC__) && __STDC__
#ifdef __GNU_LIBRARY__
/* Many other libraries have conflicting prototypes for getopt, with
differences in the consts, in stdlib.h. To avoid compilation
errors, only prototype getopt for the GNU C library. */
extern int getopt (int argc, char *const *argv, const char *shortopts);
#else /* not __GNU_LIBRARY__ */
extern int getopt ();
#endif /* __GNU_LIBRARY__ */
extern int getopt_long (int argc, char *const *argv, const char *shortopts,
const struct option *longopts, int *longind);
extern int getopt_long_only (int argc, char *const *argv,
const char *shortopts,
const struct option *longopts, int *longind);
/* Internal only. Users should not call this directly. */
extern int _getopt_internal (int argc, char *const *argv,
const char *shortopts,
const struct option *longopts, int *longind,
int long_only);
#else /* not __STDC__ */
extern int getopt ();
extern int getopt_long ();
extern int getopt_long_only ();
extern int _getopt_internal ();
#endif /* __STDC__ */
#ifdef __cplusplus
}
#endif
#endif /* _GETOPT_H */

187
common/lib/utils/getopt1.c Normal file
View File

@@ -0,0 +1,187 @@
/* getopt_long and getopt_long_only entry points for GNU getopt.
Copyright (C) 1987,88,89,90,91,92,93,94,96,97 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The GNU C Library 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
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the GNU C Library; see the file COPYING.LIB. If not,
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include "getopt.h"
#if !defined (__STDC__) || !__STDC__
/* This is a separate conditional since some stdc systems
reject `defined (const)'. */
#ifndef const
#define const
#endif
#endif
#include <stdio.h>
/* Comment out all this code if we are using the GNU C Library, and are not
actually compiling the library itself. This code is part of the GNU C
Library, but also included in many other GNU distributions. Compiling
and linking in this code is a waste when using the GNU C library
(especially if it is a shared library). Rather than having every GNU
program understand `configure --with-gnu-libc' and omit the object files,
it is simpler to just do this in the source for each such file. */
#define GETOPT_INTERFACE_VERSION 2
#if !defined (_LIBC) && defined (__GLIBC__) && __GLIBC__ >= 2
#include <gnu-versions.h>
#if _GNU_GETOPT_INTERFACE_VERSION == GETOPT_INTERFACE_VERSION
#define ELIDE_CODE
#endif
#endif
#ifndef ELIDE_CODE
/* This needs to come after some library #include
to get __GNU_LIBRARY__ defined. */
#ifdef __GNU_LIBRARY__
#include <stdlib.h>
#endif
#ifndef NULL
#define NULL 0
#endif
int
getopt_long (argc, argv, options, long_options, opt_index)
int argc;
char *const *argv;
const char *options;
const struct option *long_options;
int *opt_index;
{
return _getopt_internal (argc, argv, options, long_options, opt_index, 0);
}
/* Like getopt_long, but '-' as well as '--' can indicate a long option.
If an option that starts with '-' (not '--') doesn't match a long option,
but does match a short option, it is parsed as a short option
instead. */
int
getopt_long_only (argc, argv, options, long_options, opt_index)
int argc;
char *const *argv;
const char *options;
const struct option *long_options;
int *opt_index;
{
return _getopt_internal (argc, argv, options, long_options, opt_index, 1);
}
#endif /* Not ELIDE_CODE. */
#ifdef TEST
#include <stdio.h>
int
main (argc, argv)
int argc;
char **argv;
{
int c;
int digit_optind = 0;
while (1)
{
int this_option_optind = optind ? optind : 1;
int option_index = 0;
static struct option long_options[] =
{
{"add", 1, 0, 0},
{"append", 0, 0, 0},
{"delete", 1, 0, 0},
{"verbose", 0, 0, 0},
{"create", 0, 0, 0},
{"file", 1, 0, 0},
{0, 0, 0, 0}
};
c = getopt_long (argc, argv, "abc:d:0123456789",
long_options, &option_index);
if (c == -1)
break;
switch (c)
{
case 0:
printf ("option %s", long_options[option_index].name);
if (optarg)
printf (" with arg %s", optarg);
printf ("\n");
break;
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
if (digit_optind != 0 && digit_optind != this_option_optind)
printf ("digits occur in two different argv-elements.\n");
digit_optind = this_option_optind;
printf ("option %c\n", c);
break;
case 'a':
printf ("option a\n");
break;
case 'b':
printf ("option b\n");
break;
case 'c':
printf ("option c with value `%s'\n", optarg);
break;
case 'd':
printf ("option d with value `%s'\n", optarg);
break;
case '?':
break;
default:
printf ("?? getopt returned character code 0%o ??\n", c);
}
}
if (optind < argc)
{
printf ("non-option ARGV-elements: ");
while (optind < argc)
printf ("%s ", argv[optind++]);
printf ("\n");
}
exit (0);
}
#endif /* TEST */

113
common/lib/utils/intarray.C Normal file
View File

@@ -0,0 +1,113 @@
/*
* PVVMUD a 3D MUD
* Copyright (C) 1998-1999 Programvareverkstedet (pvv@pvv.org)
*
* 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
*
*/
#include "pvvmud.H"
#include <stdlib.h>
#include "intarray.H"
#include "exception.H"
CIntArray::CIntArray(){
m_size = 0;
m_num = 0;
m_array = NULL;
}
CIntArray::CIntArray(int size){
if (size > 0){
m_size = size;
m_num = 0;
m_array = (int*)malloc(m_size*sizeof(int));
} else {
m_size = 0;
m_num = 0;
m_array = NULL;
}
}
CIntArray::CIntArray(const CIntArray & array){
int ii;
m_size = array.m_num;
m_num = array.m_num;
m_array = (int*)malloc(m_size*sizeof(int));
for (ii = 0; ii < m_num; ii++) m_array[ii] = array.m_array[ii];
}
CIntArray::~CIntArray() {
if (m_array != NULL) free(m_array);
}
int CIntArray::add(int num){
if (m_num >= m_size || m_array == NULL) {
if (m_size <= 0) m_size = 16;
else m_size = m_size*2;
m_array = (int*)realloc(m_array,m_size*sizeof(int));
}
if (m_array != NULL) m_array[m_num] = num;
return m_num++;
}
int CIntArray::set(int index, int num){
if ((index < m_size) && (index >= 0)){
m_array[index] = num;
if (m_num <= index) m_num = index+1;
return true;
}
return false;
}
int CIntArray::get( int index ) const{
if (index < 0 || index >= m_num || m_array == NULL)
throw new CException("OutOfBound exception");
return m_array[index];
}
int CIntArray::getNumElements() const{
return m_num;
}
int CIntArray::find(int value) const{
int index,num = getNumElements();
for (index = 0; index < num; index++){
if (get(index) == value) return index;
}
return -1;
}
CIntArray CIntArray::substracSet( const CIntArray & array ) const {
CIntArray result;
int index,num = getNumElements();
for (index = 0; index < num; index++){
int value = get(index);
if (array.find(value) == -1) result.add(value);
}
return result;
}
CIntArray CIntArray::unionSet( const CIntArray & array ) const {
CIntArray result;
int index,num = getNumElements();
for (index = 0; index < num; index++){
int value = get(index);
if (array.find(value) != -1) result.add(value);
}
return result;
}

View File

@@ -0,0 +1,73 @@
/*
* PVVMUD a 3D MUD
* Copyright (C) 1998-1999 Programvareverkstedet (pvv@pvv.org)
*
* 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
*
*/
#include "pvvmud.H"
#include "keyframe.H"
CInterpolate::CInterpolate(){
}
void CInterpolate::addControlVector(CKeyFrame * keyFrame,
const ControlVector_t & controlVector)
{
for (int index = 0; index < controlVector.size(); index++){
keyFrame->addControlVector(controlVector[index]);
}
}
CVector CInterpolate::interpolate(double time, ControlVector_t * controlVector){
int size = (*controlVector).size();
if (size == 0) return CVector(0.0,0.0,0.0);
if (size == 1) return (*controlVector)[0];
int start = (int)floor((size-1) * time);
int stop = start + 1;
time = (size-1)*time-start;
return interpolate(start,time,controlVector);
}
CVector CInterpolate::interpolate(int start, double time,
ControlVector_t * controlVector)
{
return (*controlVector)[start]
+ ((*controlVector)[start+1]-(*controlVector)[start])*time;
}
CKeyFrame::CKeyFrame(CInterpolate * interpolate){
m_controlVector = new ControlVector_t();
m_interpolate = interpolate;
}
CKeyFrame::~CKeyFrame(){
delete m_controlVector;
delete m_interpolate;
}
void CKeyFrame::addControlVector(const CVector & vector){
m_controlVector->push_back(vector);
}
void CKeyFrame::addControlVector(const ControlVector_t & controlVector){
m_interpolate->addControlVector(this,controlVector);
}
CVector CKeyFrame::interpolate(double time){
return m_interpolate->interpolate(time, m_controlVector);
}

189
common/lib/utils/matrix.C Normal file
View File

@@ -0,0 +1,189 @@
/*
* PVVMUD a 3D MUD
* Copyright (C) 1998-1999 Programvareverkstedet (pvv@pvv.org)
*
* 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
*
*/
#include "pvvmud.H"
#include <math.h>
#include "matrix.H"
#include "vector.H"
////////////////////////////////////////////////////////////////////////////////
//
// Matrix vector format
//
// m = | m0 m4 m8 m12 |
// | m1 m5 m9 m13 |
// | m2 m6 m10 m14 |
// | m3 m7 m11 m15 |
//
//
////////////////////////////////////////////////////////////////////////////////
CMatrix::CMatrix(){
loadIdentity();
}
CMatrix::CMatrix(const CMatrix & matrix){
int ii;
for (ii = 0; ii < 16; ii++) m_matrix[ii] = matrix.m_matrix[ii];
}
CMatrix::CMatrix(double m0, double m4, double m8, double m12,
double m1, double m5, double m9, double m13,
double m2, double m6, double m10, double m14,
double m3, double m7, double m11, double m15)
{
m_matrix[0] = m0;
m_matrix[1] = m1;
m_matrix[2] = m2;
m_matrix[3] = m3;
m_matrix[4] = m4;
m_matrix[5] = m5;
m_matrix[6] = m6;
m_matrix[7] = m7;
m_matrix[8] = m8;
m_matrix[9] = m9;
m_matrix[10] = m10;
m_matrix[11] = m11;
m_matrix[12] = m12;
m_matrix[13] = m13;
m_matrix[14] = m14;
m_matrix[15] = m15;
}
CMatrix::CMatrix(CVector & v0, CVector & v1, CVector & v2, CVector & v3){
m_matrix[0] = v0.getX();
m_matrix[1] = v0.getY();
m_matrix[2] = v0.getZ();
m_matrix[3] = 0.0;
m_matrix[4] = v1.getX();
m_matrix[5] = v1.getY();
m_matrix[6] = v1.getZ();
m_matrix[7] = 0.0;
m_matrix[8] = v2.getX();
m_matrix[9] = v2.getY();
m_matrix[10] = v2.getZ();
m_matrix[11] = 0.0;
m_matrix[12] = v3.getX();
m_matrix[13] = v3.getY();
m_matrix[14] = v3.getZ();
m_matrix[15] = 1.0;
}
double * CMatrix::getVector(){
return m_matrix;
}
void CMatrix::multiply(const CMatrix & matrix){
CMatrix Temp(*this);
int ii,jj,kk;
for (ii = 0; ii < 4; ii++){
for (jj = 0; jj < 4; jj ++){
double sum = 0;
for (kk = 0; kk < 4; kk++){
sum += Temp.m_matrix[ii+kk*4]*matrix.m_matrix[jj*4+kk];
}
m_matrix[ii+jj*4] = sum;
}
}
}
void CMatrix::loadIdentity(){
int i;
for (i = 0; i < 16; i++){
if ((i % 5) == 0) m_matrix[i] = 1.0;
else m_matrix[i] = 0.0;
}
//m_matrix[0] = m_matrix[5] = m_matrix[10] = m_matrix[15] = 0;
}
void CMatrix::rotate(const CDirection & direction){
rotate(direction.getHeading(),0.0,0.0,1.0);
rotate(direction.getRoll(),0.0,1.0,0.0);
rotate(direction.getPitch(),1.0,0.0,0.0);
}
void CMatrix::rotate(double angle,double xx,double yy,double zz){
CMatrix r;
double rad_ang = angle*PI/180;
double sina = sin(rad_ang);
double cosa = cos(rad_ang);
r.m_matrix[0] = xx*xx + cosa*(1-xx*xx);
r.m_matrix[1] = xx*yy*(1-cosa) + zz*sina;
r.m_matrix[2] = zz*xx*(1-cosa) - yy*sina;
r.m_matrix[3] = 0.0f;
r.m_matrix[4] = xx*yy*(1-cosa) - zz*sina;
r.m_matrix[5] = yy*yy + cosa*(1-yy*yy);
r.m_matrix[6] = yy*zz*(1-cosa) + xx*sina;
r.m_matrix[7] = 0.0f;
r.m_matrix[8] = zz*xx*(1-cosa) + yy*sina;
r.m_matrix[9] = yy*zz*(1-cosa) - xx*sina;
r.m_matrix[10]= zz*zz + cosa*(1-zz*zz);
r.m_matrix[11]= 0.0f;
r.m_matrix[12]= 0.0f;
r.m_matrix[13]= 0.0f;
r.m_matrix[14]= 0.0f;
r.m_matrix[15]= 1.0f;
multiply(r);
}
void CMatrix::translate(const CPosition & position){
CMatrix trans;
trans.m_matrix[12] = position.getX();
trans.m_matrix[13] = position.getY();
trans.m_matrix[14] = position.getZ();
multiply(trans);
}
void CMatrix::transpose(){
int ii,jj;
for (ii = 1; ii < 4; ii++){
for (jj = 0; jj < ii; jj ++){
double tmp = m_matrix[ii+jj*4];
m_matrix[ii+jj*4] = m_matrix[ii*4+jj];
m_matrix[ii*4+jj] = tmp;
}
}
}
CMatrix operator*(const CMatrix & m1, const CMatrix & m2){
CMatrix result(m1);
result.multiply(m2);
return result;
}
ostream& operator<<(ostream&s,const CMatrix& matrix) {
int ii;
double * m = ((CMatrix)matrix).getVector();
s << "[" << m[0];
for (ii = 1; ii < 16; ii++){
s << "," << m[ii];
}
return s << "]";
}

158
common/lib/utils/namedb.C Normal file
View File

@@ -0,0 +1,158 @@
/*
* PVVMUD a 3D MUD
* Copyright (C) 1998-1999 Programvareverkstedet (pvv@pvv.org)
*
* 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
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "namedb.H"
#include "crossindex.H"
#include "exception.H"
CNameDBItem::CNameDBItem(int id,char *name) {
next=NULL;
this->id=id;
this->name=new char[strlen(name)+1];
strcpy(this->name,name);
}
int CNameDB::insert(char * name) {
CNameDBItem *newItem,*currItem,*nextItem;
if (first == NULL){
first = new CNameDBItem(++currentId,name);
return currentId;
}
currItem = NULL;
nextItem = first;
while ((nextItem != NULL) && (strcmp(nextItem->getName(),name)<=0)) {
currItem = nextItem;
nextItem = currItem->getNext();
}
if ((currItem != NULL) && (strcmp(currItem->getName(),name)==0))
return currItem->getId();
newItem = new CNameDBItem(++currentId,name);
newItem->setNext(nextItem);
if (currItem == NULL) first = newItem;
else currItem->setNext(newItem);
return currentId;
}
int CNameDB::add(int id, char * name) {
//NameDBItem_t *newItem,*currItem,*nextItem;
CNameDBItem *newItem;
newItem = new CNameDBItem(id,name);
if (currentId < id ) currentId = id;
newItem->setNext(first);
first = newItem;
return id;
}
char * CNameDB::findName(int id){
CNameDBItem * currItem;
currItem = first;
while (currItem != NULL){
if (currItem->getId() == id) return currItem->getName();
currItem = currItem->getNext();
}
return NULL;
}
int CNameDB::findId(char * name){
CNameDBItem * currItem;
currItem = first;
while (currItem != NULL){
if (strcmp(currItem->getName(),name) == 0) return currItem->getId();
currItem = currItem->getNext();
}
return -1;
}
void CNameDB::save(char *fileName){
FILE * ndbFile;
ndbFile = fopen(fileName,"w+");
if (ndbFile == NULL) throw new CException();
writeNDB(ndbFile);
fclose(ndbFile);
}
void CNameDB::load(char *fileName){
FILE * ndbFile;
ndbFile = fopen(fileName,"r");
if (ndbFile == NULL) throw new CException();
readNDB(ndbFile);
fclose(ndbFile);
}
void CNameDB::writeNDB(FILE * ndbfile){
CNameDBItem * currItem;
currItem = first;
while(currItem != NULL){
fprintf(ndbfile,"%i : %s\n",currItem->getId(),currItem->getName());
currItem = currItem->getNext();
}
}
void CNameDB::readNDB(FILE * ndbfile) {
char name[256];
int id;
while (fscanf(ndbfile,"%i : %255s\n",&id,name)==2 ){
add(id,name);
}
}
CCrossIndex * CNameDB::merge(CNameDB * mergeDB){
CCrossIndex * crossIndex;
CNameDBItem * mergeItem;
crossIndex = new CCrossIndex;
mergeItem = mergeDB->getFirst();
while (mergeItem != NULL){
crossIndex->add(insert(mergeItem->getName()),mergeItem->getId());
mergeItem = mergeItem->getNext();
}
return crossIndex;
}

View File

@@ -0,0 +1,99 @@
/*
* PVVMUD a 3D MUD
* Copyright (C) 1998-1999 Programvareverkstedet (pvv@pvv.org)
*
* 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
*
*/
#include "pvvmud.H"
#include <stdlib.h>
#include <iostream.h>
#include "objectarray.H"
CObjectArray::CObjectArray(){
m_grow = -1;
m_size = 0;
m_num = 0;
m_array = NULL;
cdebug<< "WARNING: CObjectArray::CObjectArray FUNCTIONALITY NOT IMPLEMENTED!\n";
}
CObjectArray::CObjectArray(int size){
m_grow = 0;
m_size = size;
m_num = 0;
m_array = (CObject**)malloc(sizeof(CObject*)*size);
for (int ii = 0; ii < m_size; ii++) m_array[ii] = NULL;
}
CObjectArray::CObjectArray(int size,int grow){
m_grow = grow;
m_size = size;
m_num = 0;
m_array = (CObject**)malloc(sizeof(CObject*)*size);
for (int ii = 0; ii < m_size; ii++) m_array[ii] = NULL;
cdebug<< "WARNING: CObjectArray::CObjectArray FUNCTIONALITY NOT IMPLEMENTED!\n";
}
CObjectArray::~CObjectArray(){
if (m_array != NULL) free(m_array);
}
void CObjectArray::deleteList(){
m_num = 0;
}
void CObjectArray::deleteAll(){
while (m_num > 0){
m_num--;
delete m_array[m_num];
}
}
int CObjectArray::add(CObject * obj){
if (m_num < m_size){
int index = m_num++;
m_array[index] = obj;
return index;
} else {
cdebug << "WARNING: CObjectArray::add NOT IMPLEMENTED!\n";
}
}
void CObjectArray::insert(int index,CObject * obj){
cdebug << "WARNING: CObjectArray::insert NOT IMPLEMENTED!\n";
}
void CObjectArray::set(int index,CObject * obj){
m_array[index] = obj;
if (m_num <= index) m_num = index+1;
}
CObject* CObjectArray::getItem(int index){
return m_array[index];
}
void CObjectArray::remove(CObject * obj){
cdebug << "WARNING: CObjectArray::remove NOT IMPLEMENTED!\n";
}
void CObjectArray::remove(int index){
cdebug << "WARNING: CObjectArray::remove NOT IMPLEMENTED!\n";
}
int CObjectArray::getNumElements(){
return m_num;
}

353
common/lib/utils/option.C Normal file
View File

@@ -0,0 +1,353 @@
/*
* PVVMUD a 3D MUD
* Copyright (C) 1998-1999 Programvareverkstedet (pvv@pvv.org)
*
* 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
*
*/
#include "pvvmud.H"
#include "option.H"
#ifdef _HAVE_GETOPT_LONG
#include <getopt.h>
#else
#include "getopt.h"
#endif // _HAVE_GETOPT_LONG
#include <iostream.h>
#include <string.h>
#include <stdlib.h>
char * COptionItem::m_typeString[] = {"string","integer","double"};
COptionItem::COptionItem(char * name, char abbreviation, char * strValue){
setName(name);
setAbbreviation(abbreviation);
setValue(strValue);
}
COptionItem::COptionItem(char * name, char abbreviation, int intValue){
setName(name);
setAbbreviation(abbreviation);
setValue(intValue);
}
COptionItem::COptionItem(char * name, char abbreviation, double doubleValue){
setName(name);
setAbbreviation(abbreviation);
setValue(doubleValue);
}
void COptionItem::setAbbreviation(char abbreviation){
m_abbreviation = abbreviation;
}
char COptionItem::getAbbreviation(){
return m_abbreviation;
}
void COptionItem::setValue(char * strValue){
m_type = STR_VALUE;
if (m_value.strValue != NULL) cdebug << "COptionItem::setValue(char * strValue) Posible memory leak!\n";
m_value.strValue = (char*)malloc(strlen(strValue)+1);
strcpy(m_value.strValue,strValue);
}
void COptionItem::setValue(int intValue){
m_type = INT_VALUE;
m_value.intValue = intValue;
}
void COptionItem::setValue(double doubleValue){
m_type = DOUBLE_VALUE;
m_value.doubleValue = doubleValue;
}
void COptionItem::updateValue(char * valueString){
switch (m_type){
case STR_VALUE: setValue(valueString); break;
case INT_VALUE: setValue(atoi(valueString)); break;
case DOUBLE_VALUE: setValue(atof(valueString)); break;
}
}
char * COptionItem::getString(){
if (m_type != STR_VALUE){
cdebug << "COptionItem " << getName() << " don't have string!\n";
return "Don't have string\n";
}
return m_value.strValue;
}
int COptionItem::getInt(){
if (m_type != INT_VALUE){
cdebug << "COptionItem " << getName() << " don't have int!\n";
return 0;
}
return m_value.intValue;
}
double COptionItem::getDouble(){
if (m_type != DOUBLE_VALUE){
cdebug << "COptionItem " << getName() << " don't have double!\n";
return 0.0;
}
return m_value.doubleValue;
}
void COptionItem::dump(){
cdebug << "Item: " << getName() << " Type: " << m_typeString[m_type]
<< " Abbreviation: " << getAbbreviation() << " Value: ";
switch (m_type){
case STR_VALUE:
cdebug << m_value.strValue;
break;
case INT_VALUE:
cdebug << m_value.intValue;
break;
case DOUBLE_VALUE:
cdebug << m_value.doubleValue;
break;
}
cdebug << "\n";
}
COption::COption(){
}
void COption::setValue(char * name, char abbreviation, char * strValue){
COptionItem * item = findOptionItem(name);
if (item == NULL){
item = new COptionItem(name,abbreviation,strValue);
addFirst(item);
} else {
item->setValue(strValue);
}
}
void COption::setValue(char * name, char abbreviation, int intValue){
COptionItem * item = findOptionItem(name);
if (item == NULL){
item = new COptionItem(name,abbreviation,intValue);
addFirst(item);
} else {
item->setValue(intValue);
}
}
void COption::setValue(char * name, char abbreviation, double doubleValue){
COptionItem * item = findOptionItem(name);
if (item == NULL){
item = new COptionItem(name,abbreviation,doubleValue);
addFirst(item);
} else {
item->setValue(doubleValue);
}
}
char * COption::getString(char * name){
COptionItem * item = findOptionItem(name);
if (item != NULL){
return item->getString();
} else {
cdebug << "COption::getString() : Unknown name " << name << "\n";
return "Unknown name\n";
}
}
int COption::getInt(char * name){
COptionItem * item = findOptionItem(name);
if (item != NULL){
return item->getInt();
} else {
cdebug << "COption::getInt() : Unknown name " << name << "\n";
return 0;
}
}
double COption::getDouble(char * name){
COptionItem * item = findOptionItem(name);
if (item != NULL){
return item->getDouble();
} else {
cdebug << "COption::getDouble() : Unknown name " << name << "\n";
return 0.0;
}
}
void COption::parseArguments(int argc, char * argv[]){
int maxNumItems = getNumItems();
// Alloc memory for optstring
int optStringMaxLength = maxNumItems*2+sizeof(char);
char * optString =(char*)malloc(sizeof(char)*optStringMaxLength);
memset(optString,0,sizeof(char)*optStringMaxLength);
char* optStringPtr = optString;
// Alloc memory for longopt structs
struct option * longOpts =
(struct option*)malloc(sizeof(struct option)*(maxNumItems+1));
memset(longOpts,0,sizeof(struct option)*(maxNumItems+1));
struct option * longOptsPtr = longOpts;
// Build longOpts array and optString
CObjectListItem * item = getFirst();
while (item != NULL){
COptionItem * optionItem = (COptionItem*)item->getObject();
if (optionItem->getName() != NULL){
longOptsPtr->name = optionItem->getName();
// TODO: Incoude test for required arguemnt, no argument
// or optional argument
longOptsPtr->has_arg = required_argument;
longOptsPtr->flag = NULL; // getopt_long return val
longOptsPtr->val = 0;
longOptsPtr++;
}
if (optionItem->getAbbreviation() != '\0'){
*optStringPtr++ = optionItem->getAbbreviation();
// TODO: Include test if option is needed or optional.
// Put ':' in optString if needed and '::' if optional.
*optStringPtr++ = ':';
}
item = item->getNext();
}
// Optionure getopt_long
// opterr = 0; // Turn off printing of error messages to stderr
int c,optionIndex;
while ((c = getopt_long(argc,argv,optString,
longOpts,&optionIndex)) != EOF){
switch (c){
case 0: // Long option
cdebug << "Long option " << longOpts[optionIndex].name;
if (optarg){
cdebug << " with arg " << optarg;
updateName(longOpts[optionIndex].name,optarg);
}
cdebug << "\n";
break;
case ':': // Missing parameter
// cdebug << "WARNING: Option '" << optarg << "' missing parameter!\n";
break;
case '?': // Unknown option
// cdebug << "WARNING: Unknown option '" << argv[optind] <<"'\n";
break;
default: // Option char
cdebug << "Option " << (char)c;
if (optarg){
cdebug << " with value " << optarg;
updateAbbreviation(c,optarg);
}
cdebug << "\n";
break;
}
}
// Free memory
free(optString);
free(longOpts);
}
void COption::loadOption(char * fileName){
FILE * file = fopen(fileName,"rt");
if (file != NULL){
loadOption(file);
fclose(file);
} else {
cdebug << "Failed to load optionuration file : " << fileName << "\n";
}
}
#define MAX_LINELENGTH 1024
int getLine(FILE * file, char * line, int length){
int index,ch;
do {
for (index = 0; (index < (length-1)) && ((ch = fgetc(file)) != EOF ) && (ch != '\n') && (ch != '#'); index++)
line[index] = ch;
line[index] = '\0';
if (ch == '#') while (((ch = fgetc(file)) != EOF) && (ch != '\n'));
} while ( (index == 0) && (ch != EOF) );
return index;
}
void COption::loadOption(FILE * file){
char line[MAX_LINELENGTH];
while (getLine(file,line,MAX_LINELENGTH) > 0){
char * chVal = strchr(line,'=');
if (chVal != NULL){
*chVal = '\0'; chVal++; // Cut string in two pices
updateName(line,chVal);
}
// cdebug << "Line: " << line << "\n";
}
}
void COption::updateName(const char * name, char * valueString){
COptionItem * optionItem = findOptionItem(name);
if (optionItem != NULL){
optionItem->updateValue(valueString);
}
}
void COption::updateAbbreviation(char abbreviation, char * valueString){
COptionItem * optionItem = findOptionItemByAbbreviation(abbreviation);
if (optionItem != NULL){
optionItem->updateValue(valueString);
}
}
void COption::dump(){
CObjectListItem * item = getFirst();
while (item != NULL){
COptionItem * optionItem = (COptionItem*)item->getObject();
optionItem->dump();
item = item->getNext();
}
}
COptionItem * COption::findOptionItem(const char * name){
CObjectListItem * item = getFirst();
while (item != NULL){
COptionItem * optionItem = (COptionItem*)item->getObject();
if ((optionItem->getName() != NULL) && (strcmp(name,optionItem->getName())) == 0){
return optionItem;
}
item = item->getNext();
}
return NULL;
}
COptionItem * COption::findOptionItemByAbbreviation(char abbreviation){
CObjectListItem * item = getFirst();
while (item != NULL){
COptionItem * optionItem = (COptionItem*)item->getObject();
if (abbreviation == optionItem->getAbbreviation()){
return optionItem;
}
item = item->getNext();
}
return NULL;
}

111
common/lib/utils/pingpong.C Normal file
View File

@@ -0,0 +1,111 @@
/*
* PVVMUD a 3D MUD
* Copyright (C) 1998-1999 Programvareverkstedet (pvv@pvv.org)
*
* 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
*
*/
#include <algorithm>
#include "pvvmud.H"
#include "pingpong.H"
CPingPong::CPingPong(BYTE maxPing){
m_currPing = 0;
m_numPing = 0;
m_maxPing = maxPing;
m_pingPong = (pingPong_t*)malloc(m_maxPing*sizeof(pingPong_t));
for (int index = 0; index < m_maxPing; index++)
m_pingPong[index].state = PS_NOTUSED;
m_firstPing = TRUE;
}
CPingPong::~CPingPong(){
free(m_pingPong);
}
delta_t CPingPong::getDeltaVector(DWORD * deltaTime){
delta_t delta(m_numPing);
for (int index = 0; index < m_numPing; index++){
delta[index] = m_pingPong[index].reciveTime
- m_pingPong[index].sendTime;
}
sort(delta.begin(),delta.end());
*deltaTime = delta[m_numPing/2];
return delta;
}
BYTE CPingPong::sendPing(DWORD sendTime){
BYTE currPing = m_currPing;
m_currPing++;
if (m_numPing < m_currPing) m_numPing = m_currPing;
if (m_currPing >= m_maxPing) m_currPing = 0;
m_pingPong[currPing].sendTime = sendTime;
m_pingPong[currPing].state = PS_WAIT;
return currPing;
}
long CPingPong::recivePong(DWORD reciveTime, BYTE sequenceNumber,
DWORD serverTime)
{
m_pingPong[sequenceNumber].reciveTime = reciveTime;
m_pingPong[sequenceNumber].serverTime = serverTime;
m_pingPong[sequenceNumber].state = PS_OK;
DWORD sendTime = m_pingPong[sequenceNumber].sendTime;
DWORD timeDelta = reciveTime - sendTime;
if (timeDelta > 10000){
m_pingPong[sequenceNumber].state = PS_BAD;
}
DWORD deltaTime;
delta_t delta = getDeltaVector(&deltaTime);
long timediff = sendTime - (serverTime + deltaTime/2);
if (m_firstPing){
m_firstPing = FALSE;
return timediff;
}
return timediff/2;
}
ostream& operator<<(ostream&s,CPingPong&p){
s << (int)p.m_numPing << "/" << (int)p.m_maxPing << " :";
DWORD deltaTime;
delta_t delta = p.getDeltaVector(&deltaTime);
for (int index = 0; index < p.m_numPing; index++){
s << " " << delta[index];
}
s << " : " << deltaTime/2;
return s;
}

74
common/lib/utils/plane.C Normal file
View File

@@ -0,0 +1,74 @@
/*
* PVVMUD a 3D MUD
* Copyright (C) 1998-1999 Programvareverkstedet (pvv@pvv.org)
*
* 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
*
*/
#include "pvvmud.H"
#include "plane.H"
CPlane::CPlane(){
m_a = m_b = m_c = m_d = 0.0;
}
CPlane::CPlane(const CVector & point,const CVector & normal){
m_a = normal.getX();
m_b = normal.getY();
m_c = normal.getZ();
m_d = -(m_a*point.getX()+m_b*point.getY()+m_c*point.getZ());
// Normalize plane
double k = 1/sqrt(m_a*m_a+m_b*m_b+m_c*m_c);
m_a *= k; m_b *= k; m_c *= k; m_d *= k;
}
CPlane::CPlane(const CVertex & point,const CVector & normal){
CVector vector(point);
*this = CPlane(vector,normal);
}
CPlane::CPlane(const CVertex & v1,const CVertex & v2,const CVertex & v3){
CVector edge = v2-v1;
*this = CPlane(v1,edge.cross(v3-v2));
}
double CPlane::distance(const CVector & position){
return (m_a*position.getX()+m_b*position.getY()+m_c*position.getZ()+m_d);
}
double CPlane::getA() const {
return m_a;
}
double CPlane::getB() const {
return m_b;
}
double CPlane::getC() const {
return m_c;
}
double CPlane::getD() const {
return m_d;
}
ostream& operator<<(ostream&s,const CPlane& p){
return s << "(" << p.getA() << "," << p.getB() << ","
<< p.getC() << "," << p.getD() << ")";
}

156
common/lib/utils/spline.C Normal file
View File

@@ -0,0 +1,156 @@
/*
* PVVMUD a 3D MUD
* Copyright (C) 1998-1999 Programvareverkstedet (pvv@pvv.org)
*
* 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
*
*/
#include "pvvmud.H"
#include "spline.H"
////////////////////////////////////////////////////////////////////////////////
//
// CSpline
//
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// Constructor
CSpline::CSpline(CMatrix * basis){
m_basis = basis;
m_basis->transpose();
}
////////////////////////////////////////////////////////////////////////////////
// interpolate
CVector CSpline::interpolate(double time, ControlVector_t * controlVector){
int size = (*controlVector).size();
if (size < 4) return CVector(0.0,0.0,0.0);
double numSeg = floor(size/4);
double seg = floor(numSeg*time) ;
if (seg == numSeg) seg--;
int start = (int)seg*4;
time = time*numSeg - seg;
CMatrix control((*controlVector)[start],(*controlVector)[start+1],
(*controlVector)[start+2],(*controlVector)[start+3]);
return interpolate(time,control);
}
////////////////////////////////////////////////////////////////////////////////
// interpolate
CVector CSpline::interpolate(double time, CMatrix & control){
CMatrix coefficients = control*(*m_basis);
CVector u(time*time*time,time*time,time,1);
return coefficients*u;
}
////////////////////////////////////////////////////////////////////////////////
//
// CCatmulRom
//
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// Constructor
CCatmullRom::CCatmullRom(double s)
:CSpline(new CMatrix( -s, 2.0-s, s-2.0, s,
2.0*s, s-3.0, 3.0-2.0*s, -s,
-s, 0.0, s, 0.0,
0.0, 1.0, 0.0, 0.0))
{
}
////////////////////////////////////////////////////////////////////////////////
// addControlVector
void CCatmullRom::addControlVector(CKeyFrame * keyFrame,
const ControlVector_t & controlVector)
{
for (int index = 0; index < (controlVector.size()-3); index++){
keyFrame->addControlVector(controlVector[index]);
keyFrame->addControlVector(controlVector[index+1]);
keyFrame->addControlVector(controlVector[index+2]);
keyFrame->addControlVector(controlVector[index+3]);
}
}
////////////////////////////////////////////////////////////////////////////////
//
// Bezier
//
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// Constructor
CBezier::CBezier():CSpline(&m_bezier){
}
////////////////////////////////////////////////////////////////////////////////
// addControlVector
void CBezier::addControlVector(CKeyFrame * keyFrame,
const ControlVector_t & controlVector)
{
for (int index = 0; index < ((controlVector.size()-4)/3 +1); index++){
keyFrame->addControlVector(controlVector[index*3]);
keyFrame->addControlVector(controlVector[index*3+1]);
keyFrame->addControlVector(controlVector[index*3+2]);
keyFrame->addControlVector(controlVector[index*3+3]);
}
}
////////////////////////////////////////////////////////////////////////////////
// static basis
CMatrix CBezier::m_bezier( -1.0, 3.0, -3.0, 1.0,
3.0, -6.0, 3.0, 0.0,
-3.0, 3.0, 0.0, 0.0,
1.0, 0.0, 0.0, 0.0);
////////////////////////////////////////////////////////////////////////////////
//
// Hermite
//
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// Constructor
CHermite::CHermite():CSpline(&m_hermite){
}
////////////////////////////////////////////////////////////////////////////////
// addControlVector
void CHermite::addControlVector(CKeyFrame * keyFrame,
const ControlVector_t & controlVector)
{
for (int index = 0; index < ((controlVector.size()-4)/2 +1); index++){
keyFrame->addControlVector(controlVector[index*2]);
keyFrame->addControlVector(controlVector[index*2+2]);
keyFrame->addControlVector(controlVector[index*2+1]);
keyFrame->addControlVector(controlVector[index*2+3]);
}
}
////////////////////////////////////////////////////////////////////////////////
// static basis
CMatrix CHermite::m_hermite( 2.0, -2.0, 1.0, 1.0,
-3.0, 3.0, -2.0, -1.0,
0.0, 0.0, 1.0, 0.0,
1.0, 0.0, 0.0, 0.0);

55
common/lib/utils/time.C Normal file
View File

@@ -0,0 +1,55 @@
/*
* PVVMUD a 3D MUD
* Copyright (C) 1998-1999 Programvareverkstedet (pvv@pvv.org)
*
* 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
*
*/
#include "pvvmud.H"
#include "time.H"
#include <sys/time.h>
CTime::CTime(){
sec = 0;
msec = 0;
}
void CTime::getTime(){
timeval curr;
gettimeofday(&curr,NULL);
sec = curr.tv_sec;
msec = curr.tv_usec/1000;
}
void CTime::add(long msec){
msec += msec;
while (msec > 1000){
msec -= 1000;
sec++;
}
}
long CTime::diff(const CTime & time){
return (sec-time.sec)*1000 + msec - time.msec;
}
CTime& CTime::operator=(const CTime& time){
msec = time.msec;
sec = time.sec;
return *this;
}

169
common/lib/utils/vector.C Normal file
View File

@@ -0,0 +1,169 @@
/*
* PVVMUD a 3D MUD
* Copyright (C) 1998-1999 Programvareverkstedet (pvv@pvv.org)
*
* 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
*
*/
#include "pvvmud.H"
#include <iostream.h>
#include "vector.H"
#include "vertex.H"
CVector::CVector(){
m_vector[0] = 0.0;
m_vector[1] = 0.0;
m_vector[2] = 0.0;
m_vector[3] = 1.0;
}
CVector::CVector(const CVector & vector){
m_vector[0] = vector.m_vector[0];
m_vector[1] = vector.m_vector[1];
m_vector[2] = vector.m_vector[2];
m_vector[3] = vector.m_vector[3];
}
CVector::CVector(double x, double y, double z){
m_vector[0] = x;
m_vector[1] = y;
m_vector[2] = z;
m_vector[3] = 1;
}
CVector::CVector(double x, double y, double z, double d){
m_vector[0] = x;
m_vector[1] = y;
m_vector[2] = z;
m_vector[3] = d;
}
CVector::CVector(const CVertex & vertex){
m_vector[0] = vertex.getX();
m_vector[1] = vertex.getY();
m_vector[2] = vertex.getZ();
m_vector[3] = 1;
}
double CVector::getX() const{
return m_vector[0];
}
double CVector::getY() const{
return m_vector[1];
}
double CVector::getZ() const{
return m_vector[2];
}
// Theory: The cross product is this determinant
//
// | i j k |
// det | m_vector[0] m_vector[1] m_vector[2] |
// | vector.m_vector[0] vector.m_vector[1] vector.m_vector[2] |
CVector CVector::cross( const CVector & vector ){
return CVector(
m_vector[1]*vector.m_vector[2] - m_vector[2]*vector.m_vector[1],
-m_vector[0]*vector.m_vector[2] + m_vector[2]*vector.m_vector[0],
m_vector[0]*vector.m_vector[1] - m_vector[1]*vector.m_vector[0]);
}
CVector& CVector::operator+=( const CVector & vector ){
int i;
for (i = 0; i < 3 ; i ++){
m_vector[i] += vector.m_vector[i];
}
return *this;
}
CVector CVector::operator+( const CVector & vector ) const{
CVector result;
int i;
for (i = 0; i < 3 ; i ++){
result.m_vector[i] = m_vector[i] + vector.m_vector[i];
}
result.m_vector[3] = 1;
return result;
}
CVector CVector::operator*( double scale ) const{
CVector result;
int i;
for (i = 0; i < 3 ; i ++){
result.m_vector[i] = m_vector[i]*scale;
}
result.m_vector[3] = 1;
return result;
}
CVector CVector::operator-( const CVector & vector ) const{
CVector result;
int i;
for (i = 0; i < 3 ; i ++){
result.m_vector[i] = m_vector[i] - vector.m_vector[i];
}
result.m_vector[3] = 1;
return result;
}
void CVector::transform(const CMatrix & transformation){
int ii,jj;
double sum;
//
// This create a compilation error with some compilers!
//
// double * m = ((CMatrix)transformation).getVector();
// CVector temp = *this;
// if (m == temp.m_vector)
// cdebug << "Error in compilation of CVector::transform !!!!\n";
//
CVector temp = *this;
CMatrix * ptrTransformation = (CMatrix*)&transformation;
double * m = ptrTransformation->getVector();
for (ii = 0; ii < 4; ii++){
sum = 0.0;
for (jj = 0; jj < 4; jj ++){
sum += m[ii+jj*4]*temp.m_vector[jj];
}
m_vector[ii] = sum;
}
}
CVector operator*(const CMatrix & m1, const CVector & v1){
CVector result;
double sum, *m = ((CMatrix)m1).getVector();
int ii,jj;
for (ii = 0; ii < 4; ii++){
sum = 0.0;
for (jj = 0; jj < 4; jj ++){
sum += m[ii+jj*4]*v1.m_vector[jj];
}
result.m_vector[ii] = sum;
}
return result;
}
ostream& operator<<(ostream&s,const CVector& v) {
return s << "[" << v.getX() << "," << v.getY() << "," << v.getZ() << "]";
}