Jump to content

Emitters in c#?


Von04
 Share

Recommended Posts

I'm trying to create an emitter using c# 2010 without any luck.

 

To create a mesh you would use Mesh cube = Mesh.CreateCube(), but their doesn't seem to be a function like that for an emitter. I've tried using Emitter fire = new Emitter(IntPtr.Zero) which doesn't give me an error, but as soon as I try to manipulate the emitter the program crashes likes it was never created. Am I doing something wrong or is the c# wrapper not working with emitters right now. Any help would be appreciated.

3d world studio. 3ds Max 8. GTX 260. Visual Studio 2010. Dual Core 2.6 Mhz processor.

Link to comment
Share on other sites

Emitter fire = new Emitter()

 

use the standard constructor.

 

When I use that line of code I get the "Object reference not set to an instance of an object" error.

 

Here is the Emitter class I am using:

using System;

namespace Leadwerks
{
   public class Emitter : Entity
   {
       public Emitter(IntPtr pointer);
       public Emitter(int intensity = 100, int lifetime = 1000, Vector3 velocity = null, EmitterCycleMode cycleMode = EmitterCycleMode.Loop, Entity parent = null);

       public Vector3 Acceleration { set; }
       public Vector3 Area { set; }
       public bool Paused { get; set; }
       public float RotationSpeed { set; }
       public Vector3 Velocity { set; }
       public float Waver { set; }

       public void Pause();
       public void Resume();
       public void SetRadii(float inner, float outer);
   }
}

 

Emitter fire = new Emitter()

 

use the standard constructor.

 

If I use Emitter fire = new Emitter(100, 100, new Vector3(0,0,0), EmitterCycleMode.Loop, Entity.NullPointer), then I get an "Object reference not set to an instance of an object" error also.

3d world studio. 3ds Max 8. GTX 260. Visual Studio 2010. Dual Core 2.6 Mhz processor.

Link to comment
Share on other sites

Don't use Entity.NullPointer, these Pointers are needed if you use the standard Pointer functions and not the OOP classes. Replace it with null or don't use it at all, it is an optional parameter.

  • Intel® Core™ i7-8550U @ 1.80 Ghz 
  • 16GB RAM 
  • INTEL UHD Graphics 620
  • Windows 10 Pro 64-Bit-Version
Link to comment
Share on other sites

You are using outdated headers. "SetRadii" doesn't exist anymore in version 2, and is replaced by the "Radii" member with dynamic get and set accessors. Has anybody noticed this link? http://www.middlewerks.com/headers/ I posted it many times with barely no comment, which is surprising since people had been waiting on it for over 2 months.

 

Now onto the fix: Vector comparison didn't support null checks, which is now fixed. I'm uploading the new revision. Should be on in 5 minutes at most.

Link to comment
Share on other sites

Thanks Lazlo, while waiting I figured out this workaround.

           [DllImport("Engine.DLL", EntryPoint = "CreateEmitter", CallingConvention = CallingConvention.StdCall)]
           public static extern IntPtr CreateEmitter(int Intensity, int Lifetime, Vector3 Acceleration, int CycleMode, IntPtr Parent);

           IntPtr emitter = CreateEmitter(100, 1000, new Vector3(0, 5, 0), 0, IntPtr.Zero);
           Emitter fire = new Emitter(emitter);

3d world studio. 3ds Max 8. GTX 260. Visual Studio 2010. Dual Core 2.6 Mhz processor.

Link to comment
Share on other sites

Good, but feel free to use the latest version of the headers, with the following parameters:

 

Emitter fire = new Emitter(velocity: new[3] { 0, 5, 0 });

 

It's less than a quarter of the previous code in terms of characters. :)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...