Maths - sfvec2f C++ files

related files

h file

   /*Title:      mjbWorld
Copyright (c) 1998-2007 Martin John BakerThis 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.For information about the GNU General public: License see http://www.gnu.org/To discuss this program http://sourceforge.net/forum/forum.php?forum_id=122133 also see website https://www.euclideanspace.com/ *//* for theory see: https://www.euclideanspace.com/maths/vectors/index.htm */__gc class sfvec2f : public property {//double x,y; static bool saveAsDouble = false ; public: double x; public: double y; // VRML only supports float but allow override if higher resolution required public: sfvec2f(); public: sfvec2f(float x1,float y1); public: sfvec2f(sfvec2f* p);// public: sfvec2f(Point2f p); public: String* vrmlType(); public: static String* vrmlType_s(){ return "SFVec2f"; } public: property* clone(); /** create an array of the appropriate type * with a size given by the parameter */ public: property* createArray(int size)[]; /** get a single value * inst = instance number * nb = nodeBean this property is contained in - only used in case this is * in a PROTO and parameter has an IS value */ public: property* get(int inst,nodeBean* nb); public: void set(property* in,int inst);/** output as a string * mode values * 0 - output modified values * 1 - output original values * 2 - output attribute * 3 - output attribute in brackets * 4 - output with f prefix */ public: String* outstring(int format); public: bool Equals(sfvec2f* v2); /** write to file * filter = information about output * mode values * 0 - output VRML97 modified values * 1 - output VRML97 original values * 2 - output xml (x3d) * 3 - output attribute in brackets * 4 - output with f prefix */ public: void write(filter* f,int mode,int indent); public: String* toStatic(); /** used by mfparam.vrml2par */ public: bool instring(filter* f,sfparam* sfp,nodeBean* n,int mode); public: bool instring(filter* f,String* s1); public: static Type* getEditClass(){ return __typeof(sfvec2fEditor); }};

CPP file

/*Title:      mjbWorld
Copyright (c) 1998-2002 Martin John BakerThis program is free software; you can redistribute it and/or modify it under the terms of the GNU General 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 License for more details.For information about the GNU General License see http://www.gnu.org/To discuss this program http://sourceforge.net/forum/forum.php?forum_id=122133 also see website https://www.euclideanspace.com/ *//* for theory see: https://www.euclideanspace.com/maths/vectors/index.htm */#include "mjbModel.h" /* x3d definition<!ENTITY % SFVec2f "CDATA"> <!-- ArrayList2Float --> */ // VRML only supports float but allow override if higher resolution requiredsfvec2f::sfvec2f() { saveAsDouble = false ; }sfvec2f::sfvec2f(float x1,float y1) { saveAsDouble = false ; x=x1; y=y1; }sfvec2f::sfvec2f(sfvec2f* p) { saveAsDouble = false ; x=p->x; y=p->y; }String* sfvec2f::vrmlType(){ return "SFVec2f"; }property* sfvec2f::clone() { //Console::WriteLine("sfvec2f->clone"); return new sfvec2f(this); }/** create an array of the appropriate type * with a size given by the parameter */ property* sfvec2f::createArray(int size)[]{ return new sfvec2f*[size]; }/** get a single value * inst = instance number * nb = nodeBean this property is contained in - only used in case this is * in a PROTO and parameter has an IS value */ property* sfvec2f::get(int inst,nodeBean* nb) { return this; }void sfvec2f::set(property* in,int inst) { x = (dynamic_cast<sfvec2f*>(in))->x; y = (dynamic_cast<sfvec2f*>(in))->y; }bool sfvec2f::Equals(sfvec2f* v2) { if (!v2) return false; if (x!= v2->x) return false; if (y!= v2->y) return false; return true; }/** output as a string * mode values * 0 - output modified values * 1 - output original values * 2 - output attribute * 3 - output attribute in brackets * 4 - output with f prefix */ String* sfvec2f::outstring(int format) { if (format == 3) { if (saveAsDouble) return String::Concat(S"(",__box(x)->ToString(), S" ",__box(y)->ToString(),S")"); else return String::Concat(S"(",__box((float)x)->ToString(), S" ",__box((float)y)->ToString(),S")"); } else if (format == 4) { return String::Concat(__box(x)->ToString(),S"f,", __box(y)->ToString(),S"f"); } else { if (saveAsDouble) return String::Concat(__box(x)->ToString(), S" ",__box(y)->ToString()); else return String::Concat(__box((float)x)->ToString(), S" ",__box((float)y)->ToString()); } }/** write to file * filter = information about output * mode values * 0 - output VRML97 modified values * 1 - output VRML97 original values * 2 - output xml (x3d) * 3 - output attribute in brackets * 4 - output with f prefix */ void sfvec2f::write(filter* f,int mode,int indent){ //Console::WriteLine("mfvec2f->write(f,"+mode+","+indent+")"); f->write(outstring(mode)); }String* sfvec2f::toStatic() { return String::Concat(__box(x)->ToString(),S"f,", __box(y)->ToString(),S"f"); }/** used by mfparam->vrml2par */ bool sfvec2f::instring(filter* f,sfparam* sfp,nodeBean* n,int mode) { String* s; try { s=f->nextToken(); if (s) if (s->Equals("IS")) { s=f->nextToken(); if (sfp) sfp->setIs(s); return true; } x = Single::Parse(s); s=f->nextToken(); y = Single::Parse(s); } catch (Exception* e) { Console::WriteLine("sfvec2f->instring error: {0}",e); } return true; }bool sfvec2f::instring(filter* f,String* s1) { String* s; try { x = Single::Parse(s1); s=f->nextToken(); y = Single::Parse(s); } catch (Exception* e) { Console::WriteLine("sfvec2f->instring error: {0}",e); } return true; }

metadata block
see also:

 

Correspondence about this page

Book Shop - Further reading.

Where I can, I have put links to Amazon for books that are relevant to the subject, click on the appropriate country flag to get more details of the book or to buy it from them.

cover Mathematics for 3D game Programming - Includes introduction to Vectors, Matrices, Transforms and Trigonometry. (But no euler angles or quaternions). Also includes ray tracing and some linear & rotational physics also collision detection (but not collision response).

Terminology and Notation

Specific to this page here:

 

This site may have errors. Don't use for critical systems.

Copyright (c) 1998-2023 Martin John Baker - All rights reserved - privacy policy.