This page has been translated automatically.
UnigineEditor
Interface Overview
Assets Workflow
Settings and Preferences
Adjusting Node Parameters
Setting Up Materials
Setting Up Properties
Landscape Tool
Using Editor Tools for Specific Tasks
FAQ
Programming
Fundamentals
Setting Up Development Environment
UnigineScript
C++
C#
UUSL (Unified UNIGINE Shader Language)
File Formats
Rebuilding the Engine and Tools
GUI
Double Precision Coordinates
API
Containers
Common Functionality
Controls-Related Classes
Engine-Related Classes
Filesystem Functionality
GUI-Related Classes
Math Functionality
Node-Related Classes
Networking Functionality
Pathfinding-Related Classes
Physics-Related Classes
Plugins-Related Classes
CIGI Client Plugin
Rendering-Related Classes
Warning! This version of documentation is OUTDATED, as it describes an older SDK version! Please switch to the documentation for the latest SDK version.
Warning! This version of documentation describes an old SDK version which is no longer supported! Please upgrade to the latest SDK version.

Creating Pylons and Wires Using Ropes

A Wire Attached to Pylons

A Wire Attached to Pylons

This example shows how to create a wire using a rope body and attach it to pylons. A tutorial teaching how to reproduce the same scene in UnigineEditor can be found here.

Source code (C#)
// AppWorldLogic.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Unigine;

namespace UnigineApp
{
	class AppWorldLogic : WorldLogic
	{
		// World logic, it takes effect only when the world is loaded.
		// These methods are called right after corresponding world script's (UnigineScript) methods.

        ObjectDummy dummy1;
        ObjectDummy dummy2;
        ObjectMeshDynamic pylon1;
        ObjectMeshDynamic pylon2;
        ObjectMeshDynamic rope;
		PlayerSpectator player;
		
        /// method, creating a named pylon with a specified radius and height at pos	
        ObjectMeshDynamic create_pylon(String name, float radius, float length, vec3 pos)
        {
	        // creating a cylinder dynamic mesh
	        ObjectMeshDynamic OM = Primitives.createCylinder(radius, length, 1, 6);
	
	        // setting parameters
	        OM.setWorldTransform(new dmat4(MathLib.translate(pos)));
	        OM.setMaterial("mesh_base", "*");
	        OM.setMaterialParameter("albedo_color", new vec4(0.1f, 0.1f, 0.0f, 1.0f), 0);
	        OM.setProperty("surface_base", "*");
	        OM.setName(name);

	        //passing node ownership to the Editor
	        OM.release();
	        Editor.get().addNode(OM.getNode());

	        return OM;
        }

        /// method, creating a named dummy body of a specified size at pos
        ObjectDummy createBodyDummy(String name, vec3 size, vec3 pos)
        {
	        // creating a dummy object
	        ObjectDummy OMD = new ObjectDummy();

        	// setting parameters
	        OMD.setWorldTransform(new dmat4(MathLib.translate(pos)));
	        OMD.setName(name);

	        //assigning a dummy body to the dummy object and adding a box shape	to it
	        new BodyDummy(OMD.getObject());
	        OMD.getBody().addShape(new ShapeBox(size).getShape(), MathLib.translate(0.0f, 0.0f, 0.0f));

	        //passing node ownership to the Editor
	        OMD.release();
	        Editor.get().addNode(OMD.getNode());

	        return OMD;
        }

        /// method, creating a named rope with specified parameters at pos
        ObjectMeshDynamic createBodyRope(String name, float radius, float length, int segments, int slices, dmat4 tm)
        {
	        // creating a cylinder dynamic mesh
	        ObjectMeshDynamic OMD = Primitives.createCylinder(radius, length, segments, slices);

	        // setting parameters
	        OMD.setWorldTransform(tm);
	        OMD.setMaterial("mesh_base", "*");
	        OMD.setMaterialParameter("albedo_color", new vec4(0.5f, 0.5f, 0.0f, 1.0f), 0);
	        OMD.setProperty("surface_base", "*");
	        OMD.setName(name);

	        //assigning a rope body to the dynamic mesh object and setting rope parameters
	        BodyRope body = new BodyRope(OMD.getObject());
	        body.setMass(1.0f);
	        body.setRadius(0.25f);
	        body.setFriction(0.5f);
	        body.setRestitution(0.05f);
	        body.setRigidity(0.05f);
	        body.setLinearStretch(0.5f);

	        //passing node ownership to the Editor
	        OMD.release();
	        Editor.get().addNode(OMD.getNode());

	        return OMD;
        }

		/* .. */

		public override int init()
		{
        	// setting up player
	        player = new PlayerSpectator();
	        player.release();
	        player.setPosition(new dvec3(0.0f, -23.401f, 15.5f));
	        player.setDirection(new vec3(0.0f, 1.0f, -0.4f), new vec3(0.0f, 0.0f, -1.0f));
	        Game.get().setPlayer(player.getPlayer());

        	// creating dummy objects to attach a rope to and placing them on the top of each pylon
	        dummy1 = createBodyDummy("fixpoint1", new vec3(0.5f, 0.5f, 0.5f), new vec3(-12.0f, 0.0f, 15.0f));
	        dummy2 = createBodyDummy("fixpoint2", new vec3(0.5f, 0.5f, 0.5f), new vec3(12.0f, 0.0f, 15.0f));
	
	        // creating pylons 
	        pylon1 = create_pylon("Pylon1", 0.3f, 17, new vec3(-12.2f, 0.0f, 7.0f));
	        pylon2 = create_pylon("Pylon2", 0.3f, 17, new vec3(12.2f, 0.0f, 7.0f));
	
	        // creating a rope
	        rope = createBodyRope("MyRope", 0.05f, 24, 96, 6, new dmat4(MathLib.translate(0.0f, 0.0f, 15.0f)*MathLib.rotateY(-90.0f)));

            // creating 2 particles joints to attach the rope to dummy bodies
	        new JointParticles(dummy1.getBody(), rope.getBody(), dummy1.getPosition(), new vec3(0.55f));
	        new JointParticles(dummy2.getBody(), rope.getBody(), dummy2.getPosition(), new vec3(0.55f));

			return 1;
		}
		
		/* .. */
		
	}
}
Last update: 2018-08-10
Build: ()