Jump to content
  • Advertisement

Chisser98

Member
  • Content Count

    30
  • Joined

  • Last visited

Community Reputation

136 Neutral

About Chisser98

  • Rank
    Member

Personal Information

  • Interests
    Programming
  1. Chisser98

    Auto handles with the ref add-on

    Hello, I am trying to implement a member function that will return a `ref@`object. I got the basic function working, but I did not want to deal with reference counting in my code, so I added the auto handle to the object to make it: `ref@+` However, when I try to register this method I get an error from Angelscript: (0, 0) : ERR : Failed in call to function 'RegisterObjectMethod' with 'ScriptObjectHandle' and 'ref@+ get()' (Code: -10) If I remove the auto handle it works fine. If I use a different type (i.e. a type that I have added), it also works fine. Does anyone know what I'm doing wrong? Cheers Jarrett
  2. Chisser98

    implementing partial templates

    Oh awesome, I didn't know that, thanks WitchLord!
  3. Chisser98

    implementing partial templates

    hmm..what I was trying to get at is to allow the use of the angle brackets when defining a type in Angelscript. so I could register the type `vector<int>` Which would be implemented with a `std::vector<int> `. so in angel script I could write something like: vector<int> myInts; myInts.push_back(1); and it would work, but if I used: vector<float> myFloats; myFloats.push_back(1.0f); it would fail to compile since the type `vector<float>` is not a defined type. does that make sense?
  4. Chisser98

    implementing partial templates

    Hi, I'm curious if anyone else would think that the use of a 'partial template' system in Angelscript would be useful. Specifically, if I want to bind a std::vector, I need to give it a unique name for each type (i.e. vectorInt, vectorFloat, etc). What if Angelscript could allow the use of the angle bracket syntax to name a type (i.e. Bind `std::vector<int>` to `vector<int>`). A user would not be able to instantiate a `vector<float>` unless this type was registered. does anyone think this might be useful? I haven't looked at the code yet, so I'm not sure how complicated this might be.
  5. Chisser98

    passing class/function to asMETHOD

    Ah, right.  Thanks saejox, AngelBinder was a big help.   Well, I guess it's pretty clear by now that I have no idea what I'm doing:     So, after more researching, and asking around a little on stackoverflow, I have something compiling.   However, now I seem to be unable to create a asSMethodPtr object...   I define the following struct:     struct S {     int f()     {         return 5;     }     int x = 10; };     and use it thusly:         asSMethodPtr pt = asSMethodPtr<sizeof( void (S::*)() )>::Convert( AS_METHOD_AMBIGUITY_CAST( int (S::*)()) (&S::f) );     However, I get the following compile time exception:     template_tests.cpp: In function ‘int main()’: template_tests.cpp:64:15: error: missing template arguments before ‘pt’ template_tests.cpp:64:15: error: expected ‘;’ before ‘pt’     Any idea why in the world I get that?     If I try to add an integer in there as a template, like so:   asSMethodPtr<16> pt = asSMethodPtr<sizeof( void (S::*)() )>::Convert( AS_METHOD_AMBIGUITY_CAST( int (S::*)()) (&S::f) );       I get this error instead: template_tests.cpp: In function ‘int main()’: template_tests.cpp:66:120: error: conversion from ‘asSFuncPtr’ to non-scalar type ‘asSMethodPtr<16>’ requested
  6. Chisser98

    passing class/function to asMETHOD

    Ok, I'm trying to actually figure out how to do it...How do you create a asSMethodPtr struct object without the Macro...?   I've got this:   auto methodPtr = asSMethodPtr<sizeof(void (classObject.pointer)())>::Convert((void (classObject.pointer)())(classObject.addRefMethodPointer));     (Where 'classObject' is a struct of type 'Class' (defined in my first post))   But it doesn't compile, I get:      src/common/as_wrapper/AngelScript.cpp:98:66: error: void value not ignored as it ought to besrc/common/as_wrapper/AngelScript.cpp:98:68: error: template argument 1 is invalid src/common/as_wrapper/AngelScript.cpp:98:107: error: void value not ignored as it ought to be     Any ideas?  I've afraid this asSMethodPtr struct is pushing the limits of my C++ abilities...
  7. Chisser98

    passing class/function to asMETHOD

    Ahh that makes sense.  I'll give wrapping asSFuncPtr a go.   Thanks SiCrane.
  8. Chisser98

    passing class/function to asMETHOD

    hey all   I'm writing a thin wrapper for Angelscript for my game.   I'm a little unsure how to actually 'wrap' the asMETHOD macro.   I've got something like this so far:       void AngelScript::registerClass(Class classObject, std::vector<Method> methods) { registerObjectType(classObject.name.c_str(), 0, asOBJ_REF); registerObjectBehaviour(classObject.name.c_str(), asBEHAVE_FACTORY, classObject.factorySignature.c_str(), asFUNCTION(classObject.factoryPointer), asCALL_CDECL); registerObjectBehaviour(classObject.name.c_str(), asBEHAVE_ADDREF, "void f()", asMETHOD(classObject.pointer, classObject.addRefMethodPointer), asCALL_THISCALL); registerObjectBehaviour(classObject.name.c_str(), asBEHAVE_RELEASE, "void f()", asMETHOD(classObject.pointer, classObject.releaseRefMethodPointer), asCALL_THISCALL); for ( Method m : methods) { registerMethod(classObject, m); } }       where Class and Method are defined as:      struct Class { std::string name; std::string factorySignature; void* pointer; void* factoryPointer; void* addRefMethodPointer; void* releaseRefMethodPointer; }; struct Method { std::string name; std::string signature; void* pointer; };         Unfortuantely, my compiler is giving me an error like this:    src/common/as_wrapper/AngelScript.cpp: In member function ‘void as_wrapper::AngelScript::registerClass(as_wrapper::Class, std::vector<as_wrapper::Method>)’: src/common/as_wrapper/AngelScript.cpp:100:160: error: template argument 1 is invalid src/common/as_wrapper/AngelScript.cpp:101:165: error: template argument 1 is invalid     Where line 100 and 101 are these two lines:     ... registerObjectBehaviour(classObject.name.c_str(), asBEHAVE_ADDREF, "void f()", asMETHOD(classObject.pointer, classObject.addRefMethodPointer), asCALL_THISCALL); registerObjectBehaviour(classObject.name.c_str(), asBEHAVE_RELEASE, "void f()", asMETHOD(classObject.pointer, classObject.releaseRefMethodPointer), asCALL_THISCALL); ...       I'm not sure how I would go about passing (whatever it is) I need to pass to the asMETHOD to get this sucker compiled.   Anyone have any ideas?
  9. Chisser98

    using angelscript compile error

    Apparently, that method is now deprecated. Found out from Chris on stackoverflow (here: http://stackoverflow.com/questions/13370774/using-angelscript-compile-error) According to the source (angelscript.h line 664), GetFunctionIdByDecl is deprecated, so you need to #define AS_DEPRECATED to use it[/quote]
  10. Chisser98

    using angelscript compile error

    Hi all, I'm trying to use angelscript 2.25.1 using gcc 4.7.1 I compiled angelscript without issues. When I try to compile my project that uses angelscript, however, I'm getting this error: jarrett@jarrett-g74s:~/projects/myproject$ scons scons: Reading SConscript files ... scons: done reading SConscript files. scons: Building targets ... g++ -o build/common/as_wrapper/AngelScript.o -c -I"../lwis/src/engine" -I"../ice_engine/src/engine" src/common/as_wrapper/AngelScript.cpp src/common/as_wrapper/AngelScript.cpp: In member function ‘void as_wrapper::AngelScript::loadScripts()’: src/common/as_wrapper/AngelScript.cpp:85:33: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings] src/common/as_wrapper/AngelScript.cpp:87:30: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings] src/common/as_wrapper/AngelScript.cpp:88:31: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings] src/common/as_wrapper/AngelScript.cpp: In member function ‘int as_wrapper::AngelScript::initContext(char*, char*)’: src/common/as_wrapper/AngelScript.cpp:242:20: error: ‘class asIScriptModule’ has no member named ‘GetFunctionIdByDecl’ src/common/as_wrapper/AngelScript.cpp:258:22: error: invalid conversion from ‘int’ to ‘asIScriptFunction*’ [-fpermissive] In file included from src/common/as_wrapper/AngelScript.h:11:0, from src/common/as_wrapper/AngelScript.cpp:8: /usr/local/include/angelscript/angelscript.h:734:26: error: initializing argument 1 of ‘virtual int asIScriptContext::Prepare(asIScriptFunction*)’ [-fpermissive] scons: *** [build/common/as_wrapper/AngelScript.o] Error 1 scons: building terminated because of errors. So basically, it (I guess the compiler) can't find GetFunctionIdByDecl function in asIScriptModule. I'm pretyt sure it should be there though. Also, the code on lin 242 is: int funcId = mod->GetFunctionIdByDecl(function); where 'function' is declared earlier as a 'char*' and 'mod' is of type 'asIScriptModule *mod'. I thought this might be an issue with gcc 4.7.1....but I'm not sure. Does anyone have any ideas? I appreciate any help! Cheers Jarrett
  11. Chisser98

    [Solved] Crazy Quaternion

    Oh man, this problem was a nightmare haha. But I finally got it fixed! Solution: 1) Because this is a Camera, I had to use the Conjugate of the rotation Quaternion to fill the matrix that OpenGL used to change the Model View Matrix. 2) Some of the math I was doing when getting the change in mouse coordinates was producing HUGE float values, so I had to cast some of the results to (float) and it was then producing the correct values. Can't say this was a fun problem, but I learned a crap load. Thanks a lot to anyone who looked over the problem! Jarrett
  12. Chisser98

    [Solved] Crazy Quaternion

    Still can't get it working - everything looks good to me! Here is a quick video of what is happening: http://jarrettchisholm.com/downloads/QuaternionTest.mpeg - To see mouse input, watch from the beginning. - To see to keyboard input (go forward, backward, etc) skip to 0:51 seconds. Again, I appreciate ANY help you guys can offer
  13. Chisser98

    [Solved] Crazy Quaternion

    That's right, I forgot I did that. I didn't used to do that, but I added it while trying to fix it (which probably didn't help any, eh?). Thanks for catching that (and for looking over the code). Unfortunately, the camera is still not working :S
  14. Hi guys, I'm just starting to work with Quaternions, but I'm having some annoying difficulties getting a simple FPS camera to work properly using Quaternions. Basically, whenever I try to move the mouse, a triangle I draw on the screen goes crazy and moves off and on the screen faster than I can see. Also, the movement keys are not at all working as expected.. Here's my Camera .h file: /* * CameraSceneNode.h * * Created on: 2011-05-08 * Author: jarrett */ #ifndef CAMERASCENENODE_H_ #define CAMERASCENENODE_H_ #include "ICameraSceneNode.h" #include "Quaternion.h" //#include "IInputListener.h" namespace icee { namespace engine { class CameraSceneNode: public ICameraSceneNode { public: CameraSceneNode(); CameraSceneNode(vmath::Vector3f position, vmath::Vector3f lookAt, bool active = true); virtual ~CameraSceneNode(); // inherited from ICameraSceneNode virtual void render(); // don't really need this // inherited from ICameraSceneNode virtual const vmath::Vector3f& getLookAt(); virtual void setLookAt(const vmath::Vector3f& newLookAt); virtual void move(MOVE_DIRECTION dir, bool enabled); // up/down virtual void rotateX(float32 degrees); // left/right virtual void rotateY(float32 degrees); virtual void tick(float32 time); protected: vmath::Vector3f lookAt_; Quaternion rotation_; sint32 prevX_, prevY_; char8 movement_[NUM_MOVE_DIRECTIONS]; float32 moveSpeed_, rotSpeed_; void clearMovementBuffer(); float32 xRot_, yRot_; void initialize(); }; } } #endif /* CAMERASCENENODE_H_ */ And here's my Camera .cpp file: /* * CameraSceneNode.cpp * * Created on: 2011-05-08 * Author: jarrett */ #include "CameraSceneNode.h" #include "../common/math/Math.h" #include <GL/gl.h> #include <iostream> namespace icee { namespace engine { CameraSceneNode::CameraSceneNode() { setLookAt(vmath::Vector3f(1, 1, 1)); setPosition(vmath::Vector3f(0, 0, 0)); active_ = true; initialize(); } CameraSceneNode::CameraSceneNode(vmath::Vector3f position, vmath::Vector3f lookAt, bool active) { setPosition(position); setLookAt(lookAt); active_ = active; initialize(); } CameraSceneNode::~CameraSceneNode() { } void CameraSceneNode::initialize() { clearMovementBuffer(); xRot_ = 0; yRot_ = 0; moveSpeed_ = 0.25f; rotSpeed_ = 0.01f; } void CameraSceneNode::render() { if (isActive()) { float32 matrix[16]; rotation_.fillMatrix(matrix); glMultMatrixf(&matrix[0]); glTranslatef(-pos_.x, -pos_.y, -pos_.z); } } const vmath::Vector3f& CameraSceneNode::getLookAt() { return lookAt_; } void CameraSceneNode::setLookAt(const vmath::Vector3f& newLookAt) { lookAt_ = newLookAt; } /** * */ void CameraSceneNode::clearMovementBuffer() { for (uint32 i = 0; i < NUM_MOVE_DIRECTIONS; i++) movement_ = 0; } /** * */ void CameraSceneNode::move(MOVE_DIRECTION dir, bool enabled) { movement_[dir] = (enabled ? 1 : 0); } // up/down /** * */ void CameraSceneNode::rotateX(float32 degrees) { xRot_ = degrees; } // left/right /** * */ void CameraSceneNode::rotateY(float32 degrees) { yRot_ = degrees; } /** * */ void CameraSceneNode::tick(float32 time) { // movement direction if (movement_[MOVE_DIR_FORWARD] == 1) pos_ += rotation_ * vmath::Vector3f(0, 0, -moveSpeed_ * time); if (movement_[MOVE_DIR_BACKWARD] == 1) pos_ += rotation_ * vmath::Vector3f(0, 0, moveSpeed_ * time); if (movement_[MOVE_DIR_LEFT] == 1) pos_ += rotation_ * vmath::Vector3f(-moveSpeed_ * time, 0, 0); if (movement_[MOVE_DIR_RIGHT] == 1) pos_ += rotation_ * vmath::Vector3f(moveSpeed_ * time, 0, 0); // rotation if (xRot_ != 0) { Quaternion quatRotation = Quaternion(vmath::Vector3f(1, 0, 0), (xRot_ * time * rotSpeed_) * math::DEGTORAD); rotation_ = rotation_ * quatRotation; xRot_ = 0; } if (yRot_ != 0) { Quaternion quatRotation = Quaternion(vmath::Vector3f(0, 1, 0), (yRot_ * time * rotSpeed_) * math::DEGTORAD); rotation_ = quatRotation * rotation_; yRot_ = 0; } } } } For good measure, here is also my Quaternion implementation: /* * Quaternion.h * * Created on: 2011-05-12 * Author: jarrett */ #ifndef QUATERNION_H_ #define QUATERNION_H_ #include "../vmath/Vector3f.h" #include "../common/math/Math.h" #include <math.h> namespace icee { namespace engine { using namespace compatibility; class Quaternion { private: float32 real_; vmath::Vector3f imaginary_; public: /** * Constructor. */ Quaternion() { real_ = 1; imaginary_ = vmath::Vector3f(0, 0, 0); } /** * Constructor. */ Quaternion(float32 real, float32 x, float32 y, float32 z) { real_ = real; imaginary_ = vmath::Vector3f(x, y, z); } /** * Constructor. */ Quaternion(float32 real, const vmath::Vector3f& imaginary) { real_ = real; imaginary_ = imaginary; } /** * Constructor. * Create this Quaternion from an axis angle. This is useful if you want to use the Quaternion * to rotate through an angle about the axis (unit) vector. The equation for this is: * q = cos(theta/2) + vector*sin(theta/2) */ Quaternion(const vmath::Vector3f& vec, float32 degrees) { buildFromAxisAngle(vec.x, vec.y, vec.z, degrees); /* // convert from degrees to radians float32 angle = ((degrees / 180.0f) * math::PI); float32 sinAngle; angle *= 0.5f; vmath::Vector3f vector(vec); vector.normalize(); sinAngle = sin(angle); imaginary_.x = (vector.x * sinAngle); imaginary_.y = (vector.y * sinAngle); imaginary_.z = (vector.z * sinAngle); real_ = cos(angle); */ } /** * Build this Quaternion from an axis angle. This is useful if you want to use the Quaternion * to rotate through an angle about the axis (unit) vector. The equation for this is: * q = cos(theta/2) + vector*sin(theta/2) */ void buildFromAxisAngle(float32 x, float32 y, float32 z, float32 degrees) { // convert from degrees to radians float32 angle = ((degrees / 180.0f) * math::PI); float32 sinAngle; angle *= 0.5f; //vmath::Vector3f vector(vec); //vector.normalize(); sinAngle = sin(angle); imaginary_.x = (x * sinAngle); imaginary_.y = (y * sinAngle); imaginary_.z = (z * sinAngle); real_ = cos(angle); } /* // Convert from Euler Angles Quaternion(float32 pitch, float32 yaw, float32 roll) { // Basically we create 3 Quaternions, one for pitch, one for yaw, one for roll // and multiply those together. // the calculation below does the same, just shorter float p = pitch * PIOVER180 / 2.0; float y = yaw * PIOVER180 / 2.0; float r = roll * PIOVER180 / 2.0; float sinp = sin(p); float siny = sin(y); float sinr = sin(r); float cosp = cos(p); float cosy = cos(y); float cosr = cos(r); this->x = sinr * cosp * cosy - cosr * sinp * siny; this->y = cosr * sinp * cosy + sinr * cosp * siny; this->z = cosr * cosp * siny - sinr * sinp * cosy; this->w = cosr * cosp * cosy + sinr * sinp * siny; normalise(); } */ /** * Copy constructor. */ Quaternion(const Quaternion &quat) { real_ = quat.real_; imaginary_ = quat.imaginary_; } /** * Destructor. */ virtual ~Quaternion() { } const Quaternion& operator =(const Quaternion &quat) { real_ = quat.real_; imaginary_ = quat.imaginary_; return *this; } const Quaternion operator +(const Quaternion &quat) const { return Quaternion(real_ + quat.real_, imaginary_ + quat.imaginary_); } const Quaternion operator -(const Quaternion &quat) const { return Quaternion(real_ - quat.real_, imaginary_ - quat.imaginary_); } const Quaternion operator *(const Quaternion &quat) const { return Quaternion( real_ * quat.real_ - imaginary_ * quat.imaginary_, imaginary_.y * quat.imaginary_.z - imaginary_.z * quat.imaginary_.y + real_ * quat.imaginary_.x + imaginary_.x * quat.real_, imaginary_.z * quat.imaginary_.x - imaginary_.x * quat.imaginary_.z + real_ * quat.imaginary_.y + imaginary_.y * quat.real_, imaginary_.x * quat.imaginary_.y - imaginary_.y * quat.imaginary_.x + real_ * quat.imaginary_.z + imaginary_.z * quat.real_); } // Multiplying a quaternion q with a vector v applies the q-rotation to v const vmath::Vector3f operator*(const vmath::Vector3f &vec) { vmath::Vector3f vector(vec); vector.normalize(); Quaternion vectorQuat, resultQuat; vectorQuat.imaginary_.x = vector.x; vectorQuat.imaginary_.y = vector.y; vectorQuat.imaginary_.z = vector.z; vectorQuat.real_ = 0.0f; resultQuat = vectorQuat * getConjugate(); resultQuat = *this * resultQuat; return (vmath::Vector3f(resultQuat.imaginary_.x, resultQuat.imaginary_.y, resultQuat.imaginary_.z)); } const Quaternion operator /(const Quaternion &quat) const { Quaternion retQuat(quat); retQuat.invert(); return *this * retQuat; } const Quaternion& operator /=(float32 scale) { real_ /= scale; imaginary_ /= scale; return *this; } void invert() { conjugate(); *this /= lengthSquared(); } void conjugate() { imaginary_ *= (-1.f); } Quaternion getConjugate() { return Quaternion(-imaginary_.x, -imaginary_.y, -imaginary_.z, real_); } float32 length() const { return (float32) (sqrt(real_ * real_ + imaginary_ * imaginary_)); } /** * Get the squared length of this quaternion. */ float32 lengthSquared() { return (float32) (real_ * real_ + imaginary_ * imaginary_); } void normalize() { *this /= length(); } /** * * Fills in Column-Major order. */ void fillMatrix(float32 matrix[]) { // First row matrix[0] = 1.0f - 2.0f * (imaginary_.y * imaginary_.y + imaginary_.z * imaginary_.z); matrix[1] = 2.0f * (imaginary_.x * imaginary_.y + imaginary_.z * real_); matrix[2] = 2.0f * (imaginary_.x * imaginary_.z - imaginary_.y * real_); matrix[3] = 0.0f; // Second row matrix[4] = 2.0f * (imaginary_.x * imaginary_.y - imaginary_.z * real_); matrix[5] = 1.0f - 2.0f * (imaginary_.x * imaginary_.x + imaginary_.z * imaginary_.z); matrix[6] = 2.0f * (imaginary_.z * imaginary_.y + imaginary_.x * real_); matrix[7] = 0.0f; // Third row matrix[8] = 2.0f * (imaginary_.x * imaginary_.z + imaginary_.y * real_); matrix[9] = 2.0f * (imaginary_.y * imaginary_.z - imaginary_.x * real_); matrix[10] = 1.0f - 2.0f * (imaginary_.x * imaginary_.x + imaginary_.y * imaginary_.y); matrix[11] = 0.0f; // Fourth row matrix[12] = 0; matrix[13] = 0; matrix[14] = 0; matrix[15] = 1.0f; } /* // Convert to Matrix Matrix4 getMatrix() const { float x2 = x * x; float y2 = y * y; float z2 = z * z; float xy = x * y; float xz = x * z; float yz = y * z; float wx = w * x; float wy = w * y; float wz = w * z; // This calculation would be a lot more complicated for non-unit length quaternions // Note: The constructor of Matrix4 expects the Matrix in column-major format like expected by // OpenGL return Matrix4( 1.0f - 2.0f * (y2 + z2), 2.0f * (xy - wz), 2.0f * (xz + wy), 0.0f, 2.0f * (xy + wz), 1.0f - 2.0f * (x2 + z2), 2.0f * (yz - wx), 0.0f, 2.0f * (xz - wy), 2.0f * (yz + wx), 1.0f - 2.0f * (x2 + y2), 0.0f, 0.0f, 0.0f, 0.0f, 1.0f) } */ /* // Convert to Axis/Angles void getAxisAngle(Vector3* axis, float* angle) { float scale = sqrt(x * x + y * y + z * z); axis->x = x / scale; axis->y = y / scale; axis->z = z / scale; *angle = acos(w) * 2.0f; } */ }; } } #endif /* QUATERNION_H_ */ It is important to mention that before CameraSceneNode::render() gets called, the following bit of code is called first: glMatrixMode(GL_MODELVIEW); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); What happens in my game loop is that CameraSceneNode::tick(..) gets called, which updates the movement/rotation variables. Then after some other code, CameraSceneNode::render() is called. I know that's a lot of code to look over, but I would really appreciate it if anyone could see any (hopefully!) glaring omissions or errors on my part. Also, if something isn't clear just ask! Thanks all, Jarrett
  15. Chisser98

    converting char** to const char**

    Oh. Thanks makes a lot of sense. Thanks Brother Bob
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!