Attaching extra data on PolygonPoints in poly2tri - c#

I know this is very specific but since they poly2tri's Google code doesn't contain contact info I'd feel good about using, I figured I might as well ask here since someone's bound to have used the library themselves.
So here's what I want. My polygons contain coordinate information, but each point also contains stuff like color and tex coord info. Unfortunately, poly2tri only takes it's own PolygonPoint implementation that has no Tag that would let me attach extra info on it. So after the polygon gets translated to triangles, I don't know which points to attach my data to.
What would be the best approach to solving this? I was thinking of editing the code myself since it seems trivial but I don't know if poly2tri retains the same PolygonPoint instances through the algorithm or if it makes new ones (rendering my Tags useless).

Just extend your PolygonPoint class and add what you need.
The points you send into the triangulation are the same you get out. Internally poly2tri does add two points outside the bound of your points just to start the triangulation these are removed when triangulation is done.

Related

What is the best way to dynamically generate 3D objects on a grid in Unity?

I am an inexperienced programmer, I am looking for advice on a new unity project:
I need to generate terrain for a 3d game from fairly large tiles. For now I only need one type of tile, but I was thinking, I better set up a registry system now and dynamically generate that default tile in an infinite grid. I have a few concerns though, like will the objects continue to load as the character moves into the render distance of a new tile (or chunk if you rather). Also, all the tutorials I have found are wrong for me in some way, like it only works in 2d and doesn't have collision, or is just a static registry and does not allow for changing the content of the tiles in-game.
Right now I don't even know what the code looks like to place a 3d object in the scene without building them from vectors, which maybe I could do. I also don't know how I would want to trigger the code.
Could someone give me an idea of what the code would look like / terminology to look up / a tutorial that gives me what I need?
This looks like a pretty big scope for a new programmer but lets give it a shot. Generating terrain will be a large learning experience when it comes to performance and optimization when you don't know what you're doing.
First off, you'll probably want to make a script that acts as a controller for generating your objects and put this inside of the player. I would start by only making a small area, or one chunk, generate and then move on to making multiple chunks generate when you understand what you're doing. To 'place' an object in your scene you will want to make an instance of the object. I'd start by trying to make your grid of objects, this can be done pretty easily on initialization (Start() function) through a for loop, for testing purposes. IE, if you are trying to make 16x16 squares like minecraft; have a for loop that runs 16 times (For the x) and a for loop inside of that to run 16 times (for the z). That way you can make a complete square of, in this case, cubes. Here is some very untested code just to give you an example of what I'm talking about.
public GameObject cube; //Cube you want to make a copy of, this will appear in the editor
void Start(){
for(var x=0; x < 16; x++){
for(var z=0; z < 16; z++){
GameObject newCube = Instantiate(cube); //Creates an instance of the 'cube' object, think of this like a copy.
newCube.transform.position = new Vector3(x, 0, z); //Places the cube on the x and z which is updated in the for loops
}
}
}
Now where you go from here will be very different depending on what you're trying to do exactly but you can start by looking into perlin noise to add in a randomized y level that looks good. It's very easy to use once you grasp the general concept and this example I provided should help you understand how to use it. They even give good examples of how to use this on the Unity docs.
In all, programming is all about learning. You'll have to learn how to only take the parts of resources that you need for what you're trying to create. I think what I provided you should give you a good start on what you want to create but it will take a deeper understanding to carry things out on your own. Just test different things and truly try and understand how they work and you'll be able to implement parts of them into your own project.
I hope this helps, good luck!

Remove all markers without the use of map.clear() Google maps - Xamarin

I am attempting to have a GPS location system that will update the users position every second, continuously draw the route they have traveled with Poly-lines, and move the marker to their newest position on every change.
Is there a nice way in Xamarin to remove all markers, but without clearing the previously attached polyline (like map.clear() would)
Now I understand that I could store the co-ordinates locally and then re-draw them each time, however this could end up being a very long route, and I would rather not have to do this, as eventually there will be a hard limit, where it cannot draw the full route, before the next set of co-ordinates come through and would prefer just to append the newest line to the previously drawn lines, and just move the marker.
Any information on this would be greatly appreciated.
The Marker object that that returned from the map AddMarker method has a .Remove method.
Casting this returned object as a Maker will allow you access to the .Remove method to delete it from the map that it is currently attached to.
Most developers store these returned masker objects in a dictionary/list/... You can either save them as the generic java object that is returned or create a Maker-based generic collection so casting later is not required.
To remove markers without clearing the map through the Clear method you need to keep track of all your markers.
var marker = Map.AddMarker(new MarkerOptions().SetPosition(new LatLng(MyPosition.Latitude, MyPosition.Longitude)));
markerList.Add(marker);
Each marker has a Remove method you can than call by iterating through the markerList.

Unity 3D - Transforming beetween worlds/planes?

Let's say I want to replicate Planeshifting from Legacy of Kain: Soul Reaver in Unity.
There are 2 realms: Spectral realm and Material realm.
The Spectral realm is based on the Material realm, only has the geometry distorted and certain objects fade out/become non-interactive.
In Soul Reaver, it is used as means to go to areas where you normally wouldn't be able to in Material (distorting geometry), to use other powers (such as going through grates).
My question is: Is it even possible at all to implement this in Unity 3D? (I would need the Scene(level) or the objects to have 2 states somehow that I could switch beetween/distort to real-time.)
I would call this a rather advanced topic and there are multiple ways of accomplishing a at least similar effect.
But to answer your actual question straight away - Yes it is possible.
And here are some approaches i would take (i guess that would be your next question ;))
The easiest way is obviously having game object which have their collider and renderer disabled (or the whole object) when "changing
realms". But this for sure isn't the best-looking way of doing it,
even tho a lot of motion blur or other image effect could help.
(Depending on what shaders you use, animating the alpha value can
create a fading effect as well)
The more advanced way would be the actual manipulation of vertices (changing the object). There are quite a few tutorials on
how to change the geometry of object. Take a look at Mesh() in the
official documentation:
http://docs.unity3d.com/ScriptReference/Mesh.html
A class that allows creating or modifying meshes from scripts.
Another way (didn't try) thats rather easy would be using shape keys. I don't know which Software you use to create your
world/models but blender has this function which allows you to define
a base shape, then edit the verticies in blender and save it as a
second (or more) shapes. Unity can blend smoothly between those
shapes as being shown in this video:
https://www.youtube.com/watch?v=6vvNV1VeXhk
Yes it will be possible in Unity3D, but your question is quite general. You could try something like having 2 models per GameObject (perhaps as children or fields on the script) and disabling 1 of them depending on which realm the player is in. You could have 2 scenes for each level and switch between them, though that might be too slow. You could see if there are any plugins/assets that allow you to define 2 models and morph between them. There are probably a number of other routes you could take, but I can't really help more until you've chosen a path.

PhysX: collision onContact does not work

I'm using PhysX.NET (C# wrapper for PhysX) and I am trying to get a notification of collision between two spheres using onContact in SimulationEventCallBack.
I have created a new subclass for SimulationEventCallback and overridden the OnContact method so that it will give me a message when collision happens. I have then set the simulationEventCallback of the scene to an instance of my subclass. This does not work even though the two spheres (rigid dynamic) obviously collide. Below is my code:
// Creating subclass
public class robotCollision : SimulationEventCallback
{
public override void OnContact(ContactPairHeader pairHeader, ContactPair[] pairs)
{
base.OnContact(pairHeader, pairs);
Rhino.RhinoApp.Write("Contact!");
}
}
// Create scene
scene = engine.CreateScene(sceneDesc);
scene.SetSimulationEventCallback(myContactCallback,0);
Is there something else that needs to be considered? Any flags to be set?
I am sorry if this is a very naive question, but I have worked on this for the whole day for something that seems to be quite simple and I can't wrap my head around it.
Thanks in advance.
I'm a PhysX C++ user so I would no mark this as a solution.
In general, you need to define a contact between two actors using either PxSimulationFilterShader or PxSimulationFilterCallback.
The later is a specific callback you need to implement, so I doubt you want to do that.
A default PxSimulationFilterShader will be provided so no worries there.
In order for the filter shader to work, you must define the actors a collision group and mask. see PxSetGroup and PxSetGroupsMask.
The group is just a number ID between 0-31.
The mask is a 4 shorts (PxU16) bit set that defines "for each group, whom should I collide with".
Now the group mask is a bit finicky.. The math behind is.. annoying...
But you can implement your own collision filtering with a more simple one, using the input data in the group mask. There are samples on how to do so in the PhysX code and documentation. see Collision Filtering
Again, I'm a C++ answer, I'm sure there is something similar in the C# wrapper.

Intersection Simulation in C#

I am making project for school "simulation of intersection" and i need few advices.
Canvas is a parent.
For now i have created class "Car" which contains some properties like Rectangle(body), Speed, Enums (Car type, Direction of moving etc.). So:
What is a best way to move objects in wpf? (I think about DispatcherTimer, but here is a question - each for one object or just one and just in one tick move all objects?)
I have some problem with some math i mean how to create a animation of turn. Tried to find this, but all i found was some spirals. I know there will be some use of Math Class + angle. (Some code, ideas or keywords for search would be nice.)
Sry for english if someone will have troubles to understand what i wrote.
The usual way it is done in games is by having one main loop. You can do this in WPF just the way you mentioned - make a DispatcherTimer, and update their position all during one call. Creating more timers is needlessly consuming resources for hardly any benefit.
Real car physics are relatively complex, but for your use case, you can go with something really simple. This is a great (and short) article on simple but good looking car physics: http://engineeringdotnet.blogspot.com/2010/04/simple-2d-car-physics-in-games.html
You can use XAML or Code behind to make animation. Here

Categories

Resources