Irrlicht .NET CP

Announce new projects or updates of Irrlicht Engine related tools, games, and applications.
Also check the Wiki
sh1ny
Posts: 21
Joined: Mon Jul 17, 2006 6:21 pm

Post by sh1ny »

While i was playing around with World Of Ideas and trying to convert it to use your CP i found that you lack Vector2D. Was easy to copy/paste it from the irrlicht source, so here it is :

Code: Select all

using System;

namespace Irrlicht.NET
{
    public struct Vector2D
    {
        public Vector2D(float x, float y)
        {
            X = x;
            Y = y;
        }

        public float X, Y;
        public float LengthSQ { get { return NewMath.Sqr(X) + NewMath.Sqr(Y); } set { SetLength((float)Math.Sqrt(value)); } }
        public float Length { get { return (float)Math.Sqrt(LengthSQ); } set { SetLength(value); } }
        public void Set(float nx, float ny) { X = nx; Y = ny; }
        public void Set(Vector2D p) { X = p.X; Y = p.Y; }

        public Vector2D Normalize()
        {
            float len = Length;

            X /= len;
            Y /= len;
            return this;
        }

        public void SetLength(float newlength)
        {
            Normalize();
            this = this * newlength;
        }

        public float DotProduct(Vector2D other)
        {
            return X * other.X + Y * other.Y;
        }

        public double GetDistanceFrom(Vector2D other)
        {
            double vx = X - other.X; double vy = Y - other.Y;
            return Math.Sqrt(vx * vx + vy * vy);
        }

        /// <summary>
        /// Returns squared distance from an other point. 
        /// Here, the vector is interpreted as point in 3 dimensional space.
        /// </summary>
        public float GetDistanceFromSQ(Vector2D other)
        {
            float vx = X - other.X; float vy = Y - other.Y;
            return (vx * vx + vy * vy);
        }

        /// <summary>
        /// Returns if the point represented by this vector is between to points
        ///</summary>
        ///<param name="begin">Start point of line</param>
        ///<param name="end">End point of line</param>
        ///<returns> True if between points, false if not. </returns>
        bool IsBetweenPoints(Vector2D begin, Vector2D end)
        {
            float f = (float)((end - begin).LengthSQ);
            return (float)GetDistanceFromSQ(begin) < f &&
                (float)GetDistanceFromSQ(end) < f;
        }

        public static Vector2D operator +(Vector2D first, Vector2D other)
        {
            return new Vector2D(first.X + other.X, first.Y + other.Y);
        }

        public static Vector2D operator -(Vector2D first, Vector2D other)
        {
            return new Vector2D(first.X - other.X, first.Y - other.Y);
        }

        public static Vector2D operator *(Vector2D first, float other)
        {
            return new Vector2D(first.X * other, first.Y * other);
        }

        public static Vector2D operator /(Vector2D first, float other)
        {
            return new Vector2D(first.X / other, first.Y / other);
        }

        public static bool operator ==(Vector2D first, Vector2D other)
        {
            return first.X == other.X && first.Y == other.Y;
        }

        public static bool operator !=(Vector2D first, Vector2D other)
        {
            return first.X != other.X || first.Y != other.Y;
        }

        public override bool Equals(object o)
        {
            if (o is Vector2D)
                return ((Vector2D)o).X == X && ((Vector2D)o).Y == Y;
            return base.Equals(o);
        }

        public void Invert()
        {
            X *= -1.0f;
            Y *= -1.0f;
        }

        public override int GetHashCode()
        {
            return ToString().GetHashCode();
        }

        public void rotateBy(double degrees, Vector2D center)
        {
            degrees *= Math.PI / 180.0;
            float cs = (float)Math.Cos(degrees);
            float sn = (float)Math.Sin(degrees);
            X -= center.X;
            Y -= center.Y;

            Set(X * cs - Y * sn, X * sn + Y * cs);

            X += center.X;
            Y += center.Y;
        }

        //! Calculates the angle of this vector in grad in the trigonometric sense.
        //! This method has been suggested by Pr3t3nd3r.
        //! \return Returns a value between 0 and 360.
        public double getAngleTrig()
        {
            if (X == 0.0)
                return Y < 0.0 ? 270.0 : 90.0;
            else
                if (Y == 0)
                    return X < 0.0 ? 180.0 : 0.0;

            if (Y > 0.0)
                if (X > 0.0)
                    return Math.Atan(Y / X) * Math.PI;
                else
                    return 180.0 - Math.Atan(Y / -X) * Math.PI;
            else
                if (X > 0.0)
                    return 360.0 - Math.Atan(-Y / X) * Math.PI;
                else
                    return 180.0 + Math.Atan(-Y / -X) * Math.PI;
        }

        //! Calculates the angle of this vector in grad in the counter trigonometric sense.
        //! \return Returns a value between 0 and 360.
        public double getAngle()
        {
            if (Y == 0.0)  // corrected thanks to a suggestion by Jox
                return X < 0.0 ? 180.0 : 0.0;
            else if (X == 0.0)
                return Y < 0.0 ? 90.0 : 270.0;

            double tmp = Y / Math.Sqrt(X * X + Y * Y);
            tmp = Math.Atan(Math.Sqrt(1 - tmp * tmp) / tmp) * Math.PI;

            if (X > 0.0 && Y > 0.0)
                return tmp + 270;
            else
                if (X > 0.0 && Y < 0.0)
                    return tmp + 90;
                else
                    if (X < 0.0 && Y < 0.0)
                        return 90 - tmp;
                    else
                        if (X < 0.0 && Y > 0.0)
                            return 270 - tmp;

            return tmp;
        }

        //! Calculates the angle between this vector and another one in grad.
        //! \return Returns a value between 0 and 90.
        public double getAngleWith(Vector2D b)
        {
            double tmp = X * b.X + Y * b.Y;

            if (tmp == 0.0)
                return 90.0;

            tmp = tmp / Math.Sqrt((X * X + Y * Y) * (b.X * b.X + b.Y * b.Y));
            if (tmp < 0.0) tmp = -tmp;

            return Math.Atan(Math.Sqrt(1 - tmp * tmp) / tmp) * Math.PI;
        }

        //! Returns interpolated vector.
        /** \param other: other vector to interpolate between
        \param d: value between 0.0f and 1.0f. */
        public Vector2D GetInterpolated(Vector2D other, float d)
        {
            float inv = 1.0f - d;
            return new Vector2D(other.X * inv + X * d,
                            other.Y * inv + Y * d);
        }

        //! sets this vector to the interpolated vector between a and b. 
        public void Interpolate(Vector2D a, Vector2D b, float t)
        {
            X = b.X + ((a.X - b.X) * t);
            Y = b.Y + ((a.Y - b.Y) * t);
        }
    }
}
:P
DeusXL
Posts: 114
Joined: Sun Mar 14, 2004 9:37 am
Contact:

Post by DeusXL »

Thanks a lot, indeed I forgot it because it was on the wrapper's beginning and I thought Vector2D was not "that" useful... But thanks to this, I'll be able to implement it on 0.4 !
Irrlicht .NET complete and Cross Platform Wrapper
The kid on my avatar wrote:A painless lesson is one without any meaning
sh1ny
Posts: 21
Joined: Mon Jul 17, 2006 6:21 pm

Post by sh1ny »

Another one :oops:

IrrlichtW/videodriver.h add :

Code: Select all

EXPORT void VideoDriver_DeleteAllDynamicLights(IntPtr videodriver);
IrrlichtW/videodriver.cpp add :

Code: Select all

void VideoDriver_DeleteAllDynamicLights(IntPtr videodriver)
{
	GetVideoFromIntPtr(videodriver)->deleteAllDynamicLights();
}
Irrlicht.NET/Video/VideoDriver.cs :

Code: Select all

        [DllImport(Native.Dll)]
        static extern void VideoDriver_DeleteAllDynamicLights(IntPtr videodriver);

Code: Select all


        public void DeleteAllDynamicLights()
        {
            VideoDriver_DeleteAllDynamicLights(_raw);
        }
I hope im not boring ya :)
sh1ny
Posts: 21
Joined: Mon Jul 17, 2006 6:21 pm

Post by sh1ny »

Ops and yea i also changed the billboard scene to actually use the vector for position, dunno why you made it use vector3d(0,0,0) ?
buhatkj
Posts: 444
Joined: Fri Dec 12, 2003 4:53 am
Contact:

performance

Post by buhatkj »

OK i finally got around to testing some more for that performance issue im having. I commented everything out that had to do with physics, then recompiled and ran my physics demo, still just 59 FPS.

then, I ran the included shaders and particles demo too, that also had only 59 FPS.

so I know now it was NOT the physics causing the slowdown, its either CP, or something i don't understand.

I have half decent hardware, and similar programs using stock irrlicht.NET get much better performance than this.
my laptop:
1.73ghz pentium M
geforce 6800 go 256mb
1gb RAM

In sotck irrlicht.NET apps I can get over 400FPS, so there must be some factor limitimg my FPS artificially at 59FPS. it's wierd, I don't think it's hardware, my work PC shows a significant slowdown using CP vs stock Irr.NET too. that never gets of 5 FPS with CP, but can get 20+ in Irr.NET(it sorta sucks)

perhaps its my compiler? I use the academic version of VS2005.
My irrlicht-based projects have gone underground for now, but if you want, check out my webcomic instead! http://brokenboomerang.net
Rowan Lewis
Posts: 24
Joined: Tue Jul 11, 2006 2:24 pm
Contact:

Post by Rowan Lewis »

Hmmr, thats not good at all, performance wise I must be blessed or something, my game often sits on 1000FPS... sometimes it even peaks at 4000!

How CPU intensive is it when you're running it? If there is some sort of limiter on the academic version, you won't get 100% cpu usage... I know it sounds silly, but then these people made Bob did they not?
DeusXL
Posts: 114
Joined: Sun Mar 14, 2004 9:37 am
Contact:

Post by DeusXL »

sh1ny => Again thanks but i did not understand what you meant :
Ops and yea i also changed the billboard scene to actually use the vector for position, dunno why you made it use vector3d(0,0,0) ?
buhatkj => As I told you, the performance difference must be really low because even with some sort of P/Invoke problem you related above, such difference is really amazing and I think there must be a bug somewhere else.

Did you try to convert CP's first example (the one with dwarves) to Irrlicht.NET ? Without changing nothing but some names and overloads, this should not be big deal. If you want I'll send you, just ask by private messenger ;)
Irrlicht .NET complete and Cross Platform Wrapper
The kid on my avatar wrote:A painless lesson is one without any meaning
sh1ny
Posts: 21
Joined: Mon Jul 17, 2006 6:21 pm

Post by sh1ny »

Well in scenemanager.cpp

Code: Select all

IntPtr SceneManager_AddBillboardSceneNode(IntPtr scenemanager, IntPtr parent, M_DIM2DF size, int id)
{
   return GetSceneFromIntPtr(scenemanager)->addBillboardSceneNode((ISceneNode *)(parent), MU_DIM2DF(size), vector3df(0, 0, 0), id);
}

I've made it look like :

Code: Select all

IntPtr SceneManager_AddBillboardSceneNode(IntPtr scenemanager, IntPtr parent, M_DIM2DF size, M_VECT3DF position, int id)
{
   return GetSceneFromIntPtr(scenemanager)->addBillboardSceneNode((ISceneNode *)(parent), MU_DIM2DF(size), MU_VECT3DF(position), id);
}
(Updating the respective code in the .NET also).

And im also having some weird issues with the .NET while using it for that game i mentioned above but ill post again when i struggle with it some more.
DeusXL
Posts: 114
Joined: Sun Mar 14, 2004 9:37 am
Contact:

Post by DeusXL »

(0, 0, 0) is the default position for a node, I removed some overloads with position and that's many nodes do not have position in their creation function because they are automatically positioned to (0, 0, 0). Actually I wanted to reduce creation functions and you would only need to set :

Code: Select all

Scene.AddBillboardSceneNode(blablabla).Position = new Vector3D(x, y, z);
Irrlicht .NET complete and Cross Platform Wrapper
The kid on my avatar wrote:A painless lesson is one without any meaning
sh1ny
Posts: 21
Joined: Mon Jul 17, 2006 6:21 pm

Post by sh1ny »

Ah this makes it clearer now :)
Rowan Lewis
Posts: 24
Joined: Tue Jul 11, 2006 2:24 pm
Contact:

Post by Rowan Lewis »

Unfortunately for me, all the terrain meshes I've made in blender export inverted, so I searched and found this code:

Code: Select all

irr::scene::IMeshManipulator has a member flipSurfaces (IMesh *mesh)
Which flips the mesh... however I can't figure out how to do this with .net :/
sh1ny
Posts: 21
Joined: Mon Jul 17, 2006 6:21 pm

Post by sh1ny »

Rowan Lewis wrote:Unfortunately for me, all the terrain meshes I've made in blender export inverted, so I searched and found this code:

Code: Select all

irr::scene::IMeshManipulator has a member flipSurfaces (IMesh *mesh)
Which flips the mesh... however I can't figure out how to do this with .net :/
I think the wrapper for the meshmanipulator is far from finished :wink:
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Re: performance

Post by hybrid »

buhatkj wrote:OK i finally got around to testing some more for that performance issue im having. I commented everything out that had to do with physics, then recompiled and ran my physics demo, still just 59 FPS.

then, I ran the included shaders and particles demo too, that also had only 59 FPS.
Disable vsync and you should get more than 60 FPS. It's simply the refresh rate of your screen that's causing this slowdown.
sh1ny
Posts: 21
Joined: Mon Jul 17, 2006 6:21 pm

Re: performance

Post by sh1ny »

hybrid wrote:
buhatkj wrote:OK i finally got around to testing some more for that performance issue im having. I commented everything out that had to do with physics, then recompiled and ran my physics demo, still just 59 FPS.

then, I ran the included shaders and particles demo too, that also had only 59 FPS.
Disable vsync and you should get more than 60 FPS. It's simply the refresh rate of your screen that's causing this slowdown.
On a different topic, may i ask how long will it take to get the .NET svn version up ? And what is being worked on it atm ? Just curious. Im not very good at c++ ( i just have abit more experience with c# ) so i'd prefer to use the .NET wrapper, because exept for haddd there isnt any real c# rendering engine, and i want to experiment/work with something simple than ogre/ogredotnet.
DeusXL
Posts: 114
Joined: Sun Mar 14, 2004 9:37 am
Contact:

Post by DeusXL »

sh1ny wrote:
Rowan Lewis wrote:Unfortunately for me, all the terrain meshes I've made in blender export inverted, so I searched and found this code:

Code: Select all

irr::scene::IMeshManipulator has a member flipSurfaces (IMesh *mesh)
Which flips the mesh... however I can't figure out how to do this with .net :/
I think the wrapper for the meshmanipulator is far from finished :wink:
That's exact, I'll try to improve it for 0.4 but now I haven't got much time to work on it :cry:
I hope I'll also be able to add things such as custom scene nodes because I realize it is very important.
Irrlicht .NET complete and Cross Platform Wrapper
The kid on my avatar wrote:A painless lesson is one without any meaning
Post Reply