Jump to content

Calling an ObjectWaterGlobal and a RigidBody from the editor


photo

Recommended Posts

Hello everyone,

 

I'm a little bit new to the engine, I'm still learning how to make a C# app. I'm making a boat simulator for my PHD. I created with the editor an ObjectWaterGlobal and a RigidBody (the boat). I managed to call the editor and the nodes to get their Pointers as nodes in the init function of the application. The problem is that I can't use the ObjectWaterGlobal and the RigidBody functions with the nodes pointers. The idea is to make all the physical calculations with an external dll called from the flush function. It's a correct way to call these objects in the application from the editor? Even if I managed to get the pointers when I build the solution I get:

 

simulator.vshost.exe' ends with code -1073741819 (0xc0000005) 'Access violation'

 

How can I avoid this error?

 

Thanks for your help,

 

Best regards

 

Nacho 

 

 

 

 
Link to comment

Hi silent,

 

Thanks for your help. I manage to solve the access violation code. I have some sort of compiler misconfiguration on Visual studio. My code is the following one.

 

Best Regards

 

Ignacio

 

//Code

 

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Diagnostics;

using System.Threading;

 

using Unigine; 

 

namespace UnigineApp

{

class AppWorldLogic : WorldLogic

{

        Stopwatch Timing;

        Node cuad1;

        Node cuad2;

        Node cuad3;

        Node cuad4;

        Node cuad5;

        Node cuad6;

        Node cuad7;

        Node cuad8;

        Node cuad9;

        Node cuad10;

        Node waterPtr;

        ObjectWaterGlobal water;

        Node Boat_BodyPtr;

        BodyRigid Boat_Body;

 

        public AppWorldLogic()

{

}

 

public override int init()

{

            // Write here code to be called on world initialization: initialize resources for your world scene during the world start.

            // This function is similar to the world script's init() function.

 

            Timing = Stopwatch.StartNew();

 

            Editor e = Editor.get();

            waterPtr = e.getNodeByName("water");

            if (waterPtr == null || waterPtr.getType() != Node.OBJECT_WATER_GLOBAL)

            {

                return 1;

            }

 

            cuad1 = e.getNodeByName("cuad1");

            if (cuad1 == null)

            {

                return 1;

            }

            cuad2 = e.getNodeByName("cuad2");

            if (cuad2 == null)

            {

                return 1;

            }

            cuad3 = e.getNodeByName("cuad3");

            if (cuad3 == null)

            {

                return 1;

            }

            cuad4 = e.getNodeByName("cuad4");

            if (cuad4 == null)

            {

                return 1;

            }

            cuad5 = e.getNodeByName("cuad5");

            if (cuad5 == null)

            {

                return 1;

            }

            cuad6 = e.getNodeByName("cuad6");

            if (cuad6 == null)

            {

                return 1;

            }

            cuad7 = e.getNodeByName("cuad7");

            if (cuad7 == null)

            {

                return 1;

            }

            cuad8 = e.getNodeByName("cuad8");

            if (cuad8 == null)

            {

                return 1;

            }

            cuad9 = e.getNodeByName("cuad9");

            if (cuad9 == null)

            {

                return 1;

            }

            cuad10 = e.getNodeByName("cuad10");

            if (cuad10 == null)

            {

                return 1;

            }

            Boat_BodyPtr = e.getNodeByName("boat");

            if (Boat_BodyPtr == null)

            {

                return 1;

            }

 

            ObjectWaterGlobal water = ObjectWaterGlobal.create(waterPtr);

 

            BodyRigid Body_Boat = BodyRigid.create(Boat_BodyPtr); //Can't create an object from a Node Error!

            return 1;

}

 

public override int shutdown()

{

            // Write here code to be called on world shutdown: delete resources that were created during world script execution to avoid memory leaks.

            // This function is similar to the world script's shutdown() function.

            Timing.Stop();

            

            return 1;

}

 

public override int destroy()

{

            // Write here code to be called when the video mode is changed or the application is restarted (i.e. video_restart is called). It is used to reinitialize the graphics context.

            // This function is similar to the world script's destroy() function.

            water.clearPtr();

            waterPtr.clearPtr();

            cuad1.clearPtr();

            cuad2.clearPtr();

            cuad3.clearPtr();

            cuad4.clearPtr();

            cuad5.clearPtr();

            cuad6.clearPtr();

            cuad7.clearPtr();

            cuad8.clearPtr();

            cuad9.clearPtr();

            cuad10.clearPtr();

            Boat_Body.clearPtr();

            Boat_BodyPtr.clearPtr();

            return 1;

}

 

public override int update()

{

// Write here code to be called before updating each render frame: specify all graphics-related functions you want to be called every frame while your application executes.

// This function is similar to the world script's update() function.

return 1;

}

 

public override int render()

{

// The engine calls this function before rendering each render frame: correct behavior after the state of the node has been updated.

// This function is similar to the world script's render() function.

return 1;

}

 

public override int flush()

{

            List<float> SectionWaterHeight = new List<float>(11);

            List<float> Boatvel = new List<float>(6);

 

            vec3 c1 = cuad1.getNodeWorldPosition();

            vec3 c2 = cuad2.getNodeWorldPosition();

            vec3 c3 = cuad3.getNodeWorldPosition();

            vec3 c4 = cuad4.getNodeWorldPosition();

            vec3 c5 = cuad5.getNodeWorldPosition();

            vec3 c6 = cuad6.getNodeWorldPosition();

            vec3 c7 = cuad7.getNodeWorldPosition();

            vec3 c8 = cuad8.getNodeWorldPosition();

            vec3 c9 = cuad9.getNodeWorldPosition();

            vec3 c10 = cuad10.getNodeWorldPosition();

 

            float c1_Height = c1.z;

            float c2_Height = c2.z;

            float c3_Height = c3.z;

            float c4_Height = c4.z;

            float c5_Height = c5.z;

            float c6_Height = c6.z;

            float c7_Height = c7.z;

            float c8_Height = c8.z;

            float c9_Height = c9.z;

            float c10_Height = c10.z;

            

            float c1_WaterHeight = water.getHeight(c1);

            float c2_WaterHeight = water.getHeight(c2);

            float c3_WaterHeight = water.getHeight(c3);

            float c4_WaterHeight = water.getHeight(c4);

            float c5_WaterHeight = water.getHeight(c5);

            float c6_WaterHeight = water.getHeight(c6);

            float c7_WaterHeight = water.getHeight(c7);

            float c8_WaterHeight = water.getHeight(c8);

            float c9_WaterHeight = water.getHeight(c9);

            float c10_WaterHeight = water.getHeight(c10);

 

            SectionWaterHeight[1] = 0;

            SectionWaterHeight[1] = c1_WaterHeight - c1_Height;

            SectionWaterHeight[2] = c2_WaterHeight - c2_Height;

            SectionWaterHeight[3] = c3_WaterHeight - c3_Height;

            SectionWaterHeight[4] = c4_WaterHeight - c4_Height;

            SectionWaterHeight[5] = c5_WaterHeight - c5_Height;

            SectionWaterHeight[6] = c6_WaterHeight - c6_Height;

            SectionWaterHeight[7] = c7_WaterHeight - c7_Height;

            SectionWaterHeight[8] = c8_WaterHeight - c8_Height;

            SectionWaterHeight[9] = c9_WaterHeight - c9_Height;

            SectionWaterHeight[10] = c10_WaterHeight - c10_Height;

 

            TimeSpan ElapsedTime = Timing.Elapsed;

 

            Boatvel = BoatPhysics(SectionWaterHeight,ElapsedTime); //Call to external dll

 

            vec3 Boatlinvel = new vec3(Boatvel[1], Boatvel[2], Boatvel[3]);

            vec3 Boatangvel = new vec3(Boatvel[4], Boatvel[5], Boatvel[6]);

 

            Boat_Body.setLinearVelocity(Boatlinvel);

            Boat_Body.setAngularVelocity(Boatangvel);

            

            return 1;

}

 

public override int save(Stream stream)

{

// Write here code to be called when the world is saving its state (i.e. state_save is called): save custom user data to a file.

// This function is similar to the world script's save() function.

return 1;

}

 

public override int restore(Stream stream)

{

// Write here code to be called when the world is restoring its state (i.e. state_restore is called): restore custom user data to a file here.

// This function is similar to the world script's restore() function.

return 1;

}

}

}

Link to comment

I continue to get an error when I use:

 

 BodyRigid Body_Boat = BodyRigid.create(Boat_BodyPtr);

 

Your help already solve the problem with the water object.

 

Thanks a lot. 

 

Best Regards

Link to comment

Hi Ignacio,

BodyRigid.create takes as the first parameter reference to Unigine.Object. You should cast Boat_BodyPtr to Unigine.Object:

Unigine.Object Boat_ObjectPtr = Unigine.Object.create(Boat_BodyPtr);
BodyRigid Body_Boat = new BodyRigid(Boat_ObjectPtr);

Best regards

Link to comment

Thank you very much vermillion. I'm sorry if my topics are very basic. I'm quite new to game engines in general and Unigine in particular. Thanks again.

 

Best Regards

Link to comment
×
×
  • Create New...