Page 4 of 29

Posted: Wed Sep 08, 2010 1:44 pm
by greenya
Jesterstear wrote:Yeah, Visual Studio messed up for a bit, the device is now working.

But cube.Rotation is defined like this:

Code: Select all

public Vector3Df Rotation
{
get
{
return Node.Rotation;
}
set
{
Node.Rotation = Rotation;
}
}
Maybe I'm not allowed to do that, because directly modifying the node rotates the camera (which I will try to figure out what is going on while I'm in class).
Your setter is wrong.
Looks like when you writing "Node.Rotation = Rotation;", you just do "Node.Rotation = Node.Rotation;", because "Rotation" is your property and its getter returns Node.Rotation again.

Indeed, when in setter scope, you have special reserved keyword called "value", which holds real value from right side of operation. So i believe you should write next:

Code: Select all

set
{
Node.Rotation = value;
}

Posted: Wed Sep 08, 2010 9:35 pm
by Jesterstear
Haha, such a noob mistake, I'm still working my way around C#.
Thank you for the information!

Anyway, I have been messing around with more things, and it seems as though the only problems I have are with the camera:

Code: Select all

cam.Position = new Vector3Df(cam.Position.X, cam.Position.Y, cam.Position.Z - 1);
This code works, but the camera's rotation gets resets to 0 every time the camera moves.

I also found out why the camera wasn't rotating when the mouse moved:
cam.TargetAndRotationBinding = true;
That is set to false by default, a simple change allows the camera to move.

But now the weird part, the camera keeps rotating when my cube rotates. I removed all of the cam.Target = xx, but the camera keeps locking onto the last created object. I can't figure it out.

Code: Select all

CubeObject cube = new CubeObject("GameObject" + GameObject.indexAmount, 10, new Vector3Df(0, 0, 0), new Vector3Df(0, 0, 0));
            GameObjects.Add(cube);

Code: Select all

public CubeObject(String newName, float newSize, Vector3Df newPos, Vector3Df rotation)
        {
            indexAmount++;
            Index = indexAmount;
            MeshNode = smgr.AddCubeSceneNode(newSize, smgr.RootNode, indexAmount, newPos, rotation);
            MeshNode.Name = newName;
            Node = MeshNode;
        }
There's nothing there that should lock the camera onto the object, but the rotation of the camera is relative to how the cube moves =\

EDIT: Actually, it seems as though the entire scene is rotating.
The camera isn't rotating (it is locked at 0, 0, 0), but a grid that I have drawn and the cube are rotating.

Posted: Wed Sep 08, 2010 11:11 pm
by greenya
Jesterstear wrote: Anyway, I have been messing around with more things, and it seems as though the only problems I have are with the camera:

Code: Select all

cam.Position = new Vector3Df(cam.Position.X, cam.Position.Y, cam.Position.Z - 1);
This code works, but the camera's rotation gets resets to 0 every time the camera moves.
Please, try to make as short as possible separate test case which demonstrates the problem and post source code here, because i just checked next code:

Code: Select all

CameraSceneNode cam = smgr.AddCameraSceneNode();
cam.Rotation = new Vector3Df(10, 20, 30);
cam.Position = new Vector3Df(cam.Position.X, cam.Position.Y, cam.Position.Z - 1);
and after the third line, cam.Rotation still equals (10,20,30), so no resets.
Jesterstear wrote: EDIT: Actually, it seems as though the entire scene is rotating.
The camera isn't rotating (it is locked at 0, 0, 0), but a grid that I have drawn and the cube are rotating.
I don't know how you draw a grid, but please note, if you draw some sort of graphics using VideoDriver methods, like Draw3DLine, Draw3DTriangle and so on, you should remember:
- draw only between BeginScene() and EndScene();
- if you draw after SceneManager' DrawAll() call, before you start drawing -- reset world transformation matrix to identity; call something like next:

Code: Select all

device.VideoDriver.SetTransform(TransformationState.World, Matrix.Identity);
because if you don't, your drawing will use transform state from last drawn scene node (of previous "device.SceneManager.DrawAll();" call).

Posted: Thu Sep 09, 2010 12:00 am
by Jesterstear
Well, I don't know what to say. I made Irrlicht Lime set the window's title to the rotation, and the rotation is apparently staying the same, but the view is different. When I move the mouse a bit, the view teleports back to where it was.

Code: Select all

            if (e.KeyChar == 'w')
                    {
                        cam.Position = new Vector3Df(cam.Position.X, cam.Position.Y, cam.Position.Z - 1);
                    }
                    else if (e.KeyChar == 's')
                    {
                        cam.Position = new Vector3Df(cam.Position.X, cam.Position.Y, cam.Position.Z + 1);
                    }
                    if (e.KeyChar == 'a')
                    {
                        cam.Position = new Vector3Df(cam.Position.X + 1, cam.Position.Y, cam.Position.Z);
                    }
                    if (e.KeyChar == 'd')
                    {
                        cam.Position = new Vector3Df(cam.Position.X - 1, cam.Position.Y, cam.Position.Z);
                    }
                

Code: Select all

if (e.X < prevX)
                {
                    cam.Rotation = new Vector3Df(cam.Rotation.X, cam.Rotation.Y - (prevX - e.X), cam.Rotation.Z);
                }
                else
                {
                    cam.Rotation = new Vector3Df(cam.Rotation.X, cam.Rotation.Y + (e.X - prevX), cam.Rotation.Z);
                }
                if (e.Y < prevY)
                {
                    cam.Rotation = new Vector3Df(cam.Rotation.X - (prevY - e.Y), cam.Rotation.Y, cam.Rotation.Z);
                }
                else
                {
                    cam.Rotation = new Vector3Df(cam.Rotation.X + (e.Y - prevY), cam.Rotation.Y, cam.Rotation.Z);
                }
And I don't remember having to use device.VideoDriver.SetTransform(TransformationState.World, Matrix.Identity); in Irrlicht. It has been awhile since I have used Irrlicht though.

EDIT: Here is the executable, to use it, go to Scene and to move/look around, hold down the right mouse button.
http://dl.dropbox.com/u/5735064/Release.rar

EDIT2: Don't mock the grid! I actually fixed that, but that build is from earlier today :oops:

Posted: Thu Sep 09, 2010 12:38 am
by greenya
Jesterstear wrote:Well, I don't know what to say. I made Irrlicht Lime set the window's title to the rotation, and the rotation is apparently staying the same, but the view is different. When I move the mouse a bit, the view teleports back to where it was.
If you talking about the moment when camera looks almost straight down and you continue moving camera until it reaches perpendicular and you continue moving and suddenly image swaps (turns on 180 degree) --- this is because camera has UpVector which used each time by camera when calculating its view.

Posted: Thu Sep 09, 2010 12:49 am
by Jesterstear
Oh no, not that. I mean actually moving the camera while rotating it.
Try using D while rotating the camera, the camera becomes all jittery yet the rotation stays the same.

Posted: Tue Sep 14, 2010 2:55 pm
by Sylence
First of all: This is a great project.

Any idea how to port the complete MeshBuffer interface? Especially I'm refering to getVertices() and a possibility to create them by hand.

I wonder if there's a clean solution for the getVertices() method.

Posted: Tue Sep 14, 2010 4:52 pm
by greenya
As you may see in /source/MeshBuffer.h i commented out these methods:

Code: Select all

	//void Append(const void *const vertices, u32 numVertices, const u16 *const indices, u32 numIndices);

	//u16* getIndices();
	//void* getVertices();
And, yes, i plain to port them too.
The reason why i skipped them was that i was not sure what actually getVertices() returns and need time to looks into it.

Posted: Thu Sep 16, 2010 2:09 pm
by greenya
Sylence,

check out SVN trunk, now it contains functionality to manipulate mesh buffer's data. I will describe in details how to use it when release 0.7, but if you waтt -- you can check it already now. :wink:

Posted: Thu Sep 16, 2010 7:22 pm
by Sylence
Wow that was fast :)
Great!

Posted: Tue Oct 12, 2010 12:19 am
by greenya
Version 0.7 has been released.

New native example: 10.Shaders.
New Lime examples: L03.RGBSwirl and L04.ParticleEmitterViewer (read below about them).

Release Notes


~
Added class Logger. I don't know how could i forget about it :), but found its usage only in 10.Shaders example, so ported it. Now you can easily write to log next way:

Code: Select all

device.Logger.Log("a log message");

~
Added class GPUProgrammingServices. Now its possible to use shaders as shown in 10.Shaders example.
1) There are some changes in adding new materials in Irrlicht (from native c++ version): GPUProgrammingServices.Add*() methods and Video.AddMaterialRenderer() now returns MaterialType (was int); however the return value should be compared with "-1" (you have to cast return value to int to do this).
2) GPUProgrammingServices class has 2 static events: OnSetMaterial and OnSetConstants; you should handle this events if you want to pass parameters to your shaders (see 10.Shaders example). Please note: maybe in future OnSetMaterial will be removed and combined with OnSetConstants because they called synchronously, so if you have more than 1 material and in OnSetConstants you want to know which one is under processing right now -- you have to handle OnSetMaterial (this is the way its done in native Irrlicht, and looks a bit strange for me... i'm not very familiar with shaders and its programming, so i decided to do not change the way its done).


~
Added method FileSystem.CreateMemoryReadFile(filename, content). The content is an array of bytes that you may generate to create in-memory file. Please note, that "content" is "input"-only argument (it is not "reference"), so it is one-way-only and the content of returned ReadFile object will not be changed if you change your input array after the call (it is possible in native c++ Irrlicht, but not in this wrapper). Probably some sort of "update" method will be added in future.


~
MeshBuffer class has been extended. Added get-only properties: Indices and Vertices. Both returns Object. This is due to each MeshBuffer can hold different index type and vertex type. You can check VertexType (or IndexType) property at run time to know how to cast the value. For example if you work only with VertexType.Standard, you just do:

Code: Select all

Vertex3D[] v = (Vertex3D[])meshBuffer.Vertices;
// now you can read value of each vertex;
// ofcause if you do then v[0].Color = ... , you just edit your local array copy; read below how to modify data.
Added support for mesh manipulation. Next methods added:

Code: Select all

public void Append(Vertex3D[] verticesStandard, ushort[] indices16bit);
public void Append(Vertex3DTangents[] verticesTangents, ushort[] indices16bit);
public void Append(Vertex3DTTCoords[] verticesTTCoords, ushort[] indices16bit);
Each method works with its own vertex type. Indeed, you can check VertexType, and use proper methods. For example, if you have VertexType == VertexType.Standard and will try to use Append() with Vertex3DTangents array, you will get failed assertion check. Current native IMeshBuffer do not support appending data with indices other than IndexType._16Bit type, so there is no ability to add data with 32 bit indices for now.

Native Irrlicht much flexible here, it allows you to get vertices pointer (with void* getVertices()) and change values directly. As compensation to this cool native ability, i have invented next methods:

Code: Select all

public void UpdateIndices(ushort[] indices16bit, int startIndex);
public void UpdateVertices(Vertex3D[] verticesStandard, int startIndex);
public void UpdateVertices(Vertex3DTangents[] verticesTangents, int startIndex);
public void UpdateVertices(Vertex3DTTCoords[] verticesTTCoords, int startIndex);
These methods able to modify certain parts of incides and vertices. Please note, you have also use only proper type: if your VertexType == VertexType::Tangents, you can use UpdateVertices() method with tangents array only, or assertion check will fail. Also in this methods VertexCount (and IndexCount in case of UpdateIndices()) takes place, for example: if you have mesh buffer with 20 vertices, and you will call UpdateVertices(newVertices, 10) and newVertices.Length would 15, you will also get assertion check failed. These methods can only modify existing continuous parts of data (they do not append/remove data).

Next sample shows the usage of these methods:

Code: Select all

// We create simple cube mesh scene node
MeshSceneNode cube = smgr.AddCubeSceneNode(20); // this creates cube with -10 .. +10 coords at all three axies.

// We add triangle just above the cube (not touching it)
MeshBuffer mb = cube.Mesh.GetMeshBuffer(0);
Vertex3D[] av = new Vertex3D[3];
av[0] = new Vertex3D( 11,11, 11); // we do not care about normal vectors (as we do not use lighting),
av[1] = new Vertex3D(-11,11,-11); // and we do not care about texture coords,
av[2] = new Vertex3D(  0,18,  0); // and vertex color in this example; if we care -- we can use more specific contructors.
ushort[] ai = new ushort[3] { 0, 1, 2 };
mb.Append(av, ai);

// Now our new triangle became a part of the whole mesh,
// this means that indices and vertices now do not have old
// 0, 1 and 2 positions, but appended to all the mesh.

// Next code shows how to change (flip face) only the triangle that we just added.
int oldIndexCount = mb.IndexCount - 3;
int oldVertexCount = mb.VertexCount - 3;
ai[0] = (ushort)(2 + oldVertexCount); // was 0
ai[1] = (ushort)(1 + oldVertexCount); // was 1 (we could do not use this line at all)
ai[2] = (ushort)(0 + oldVertexCount); // was 2
mb.UpdateIndices(ai, oldIndexCount);

// Now our custom triangle has flipped its face.

~
Added intellisense documentation for Visual Studio. Now when you compile IrrlichtLime, bin folder will also contain IrrlichtLime.xml file, which will be used by VS' intellisense automatically when you reference IrrlcihtLime.dll in your project. Currently next namespaces are documented:
IrrlichtLime
IrrlichtLime.Core
IrrlichtLime.IO
IrrlichtLime.Video

This should really help those, who started to use Irrlicht Lime without experience with native C++ Irrlicht Engine.
Image


~
Two new Lime examples added.

L03.RGBSwirl
This example draw nice RGB swirl. It looks like its complete 2D graphics, but its not. Indeed its 3D: there is a sphere in pointcloud mode rapidly rotating, the camera with affected view matrix which makes all looks quite unrecognizable, BeginScene() do not clears the backbuffer, so the image repaints itself over and over again. There are also 3 lights with colors red, green and blue, which rotates and lights the sphere parts, you may see it when running example, in places where light ranges overlaps -- we can see color mix, and in the center -- white color, which is mix of red, green and blue at the same time. Source code quite short.

Sceenshot:
Image

L04.ParticleEmitterViewer
This example is a simple particle viewer, that allows to change some parameters on the fly of created particle system and see the changes immediatly.
This example demonstates some cool features:
- correctly react on window resizes; you may even choose the behavior: keep aspect ratio or not;
- renders all its graphics in separete thread (now Thread class used, not BackgroundWorker component like it was in L02.WinFormsWindow example);
- implements a command queue mechanism, when UI send commands to rendering thread and does not wait its processing to finish, they added to the queue and wait for processing there. This makes all runs much safe and smooth;
- shows how to calculate time spent on rendering of each frame;

Sceenshot:
Image


~
Updated Irrlicht SDK to trunk rev. 3427.
Full list of changes: http://irrlichtlime.svn.sourceforge.net ... athrev=212

Thank you so much!

Posted: Sat Nov 06, 2010 6:39 pm
by SirDregan
Thank you so much for creating this great .NET dll!
I tried the older projects and got frustrated, beacause none of the samples worked and I couldn't get anything done.
I registered just to be up to date and thank you for your effort!

We have a big game planned and it's so great that we can use Irrlicht easier now. Thanks again!

Keep up the good work!

Posted: Wed Nov 10, 2010 6:33 pm
by roxaz
wrapper looks amazing, thumbs up :]

what about inheriting SceneNodeAnimator tho? compiler is not happy about parent class not having constructor..

Posted: Thu Nov 11, 2010 1:01 am
by greenya
roxaz wrote:what about inheriting SceneNodeAnimator tho? compiler is not happy about parent class not having constructor..
Yes. Currently its not possible to inherit SceneNodeAnimator. Maybe i will add it soon.

The inheritance in my wrapper made with some tricks. Its not so simple as may look like. Its simple to use but not to implement (and actually hide implementation inside c++ .net core). Its not possible to inherit unmanaged class by a managed one. But C# sees only managed part of the assembly.

If you know c++ .net, you may check how its made with SceneNode (and how its used in example). SceneNodeInheritor.h defines a class which actually inherits native ISceneNode and provides a bridge to managed SceneNode by delegating calls.

Anyway, its good that you said it, because now i know that its need to be added :)

Posted: Thu Nov 11, 2010 6:05 am
by roxaz
righty, i had done some coding in c++.NET, gonna try to implement this myself.

Another thought... if you used source control system like git it would be much easier for random ppl to contribute. Anyone could make a patch and commit it to repository, and you could pull suitable patches from those people to your own branch which would be project main branch. :]