WPF: Check if two ModelVisual3Ds are mostly overlapping - wpf

I have a question regarding WPF programming, and it's with regards to whether we can check if a certain percentage of a shape is intersecting/overlapping with another shape. My intention is to create a minigame where there will be a model (e.g. a cube), and the app will apply a random Transform to it. The user then needs to manually rotate and resize the model using given controls, and fit it into (roughly) the randomly Transform-ed cube.
Is there any method/algorithm I can apply for two ModelVisual3Ds within the same Viewport3D? It would be ideal if the method can return a percentage (e.g. 0.8, 0.9), so that I can tweak it to accept only if the percentage is above a certain level.
Many thanks!

Related

Using Viewboxes in wpf

I was looking for a way to scale part of a wpf form properly when I came across this post on SO. It actually told me quickly and succinctly what I needed to know but got me to wondering on the following question.
I have identified a need for a control with a particular degree of functionality and as such it's a perfect candidate for a user control. One thing that it will need to be is scalable. If I were to enclose the contents of my user control in a viewbox (and there were several of those controls on a form in a wpf application) would they conflict with any viewbox that might be wrapping all of the controls on a form? In other words when designing user controls that require a degree of scalability is it acceptable to just 'wrap' the contents of the user control in a viewbox?
Thanks
The Viewbox will "stretch/scale a single child element to the fill the available space". You shouldn't run into any issues with Viewboxes at various nested levels composing a larger control (and it's fairly easy to test some general layouts in a mock project).
What is worth considering, is if the simple Viewbox scaling behaviour is actually what you're after. If you wanted say, a particular button to increase in size, or certain elements to stretch horizontally, you may get more mileage from various Grid layout options, with relative / proportional sizing/stretching.
Of course, the Viewbox scaling may be exactly what you're after =D

A lot of GUI controls indicating different states

This question is very open and probably, the answer to this question will depend on the system, but say in average which is the best way to show a large matrix (say 128 elements) of different states?
Create one control for each cell and let GUI library deal with all events and stuff (In Windows 128 HWND:s)
Draw the entire matrix by using lower-level graphics primitives
Is there a difference in memory/CPU performance depending on choice? The number of states in my application is 4 for each cell so they need 2 bits each to represent their state. Each cell will be represented by an image related to the state.
Sure there is a difference. I will try to illustrate this and also the assumptions this is based on.
Cost of a control = memory for control + event handlers for control + references to control + one extra control in event pipeline
Benefit of "tight" control per cell mapping. Conceptually clean, simple code, easiest to think about.
Cost of tight mapping : multiply the cost per control by the number of cells.
The alternative I'm about to suggest assumes that the cost delta between tight mapping and a loose "one ring" mapping is important.
alternative : just add one control that is registered for events only within the bounds of the whole matrix view you present, has a piece of code to determine the pointer position and what cell that corresponds to, and then updates only that cell depending on the user interaction there.
The advantages of this are you get the marginal cost of only one extra control but the benefit of handling interactions for the entire matrix. The marginal benefit or this control is much higher than for a single tight control. Aldo, the implementation cost is small as it is a common pattern and not too difficult.
Good luck!

Making WPF User Control transformations internal

I am developing my system using WPF with MVVM and I am having trouble to find out the best way to solve the following problem:
I have a screen in which many components (User Controls) are drawn at specific positions. All components in the screen are rotated, translated and scaled according to binded variables calculated by the screen's VM.
However, each of this components could have a different center for the rotation, a different origin for the translation and a different scale, dependent of internal variables and the screen scale.
How is it possible to make this transformations calculated internally in the User Control? I think the easier approach is using the Converter, however since I have many different User Controls with different behaviours, I would have to create multiple converters very similar to each other, which would not be the ideal solution.
Thank you very much for the help!
A UIElement has only one RenderTransformOrigin.
Some transformations allow you to set the origin for that transformation but in coordinates relative to the control bounds (e.g.: 125, 34) not in proportional coordinates like the RenderOrigin (e.g.: 0.5, 0.75)
So if you can use the coordinates you're good to go.
If not, you could compose the transformations by creating Transformation groups that first translate the control, then perform the transformation, and then translate the control back.
If you need more help, please post an example of what you are trying to achieve.

Display percentage value as a fill in a custom shape

I'm looking at some new options for displaying a percentage value as a fill in a custom shape. Consider the effect to be similar to a "progress thermometer" in a traditional dashboard UI sense.
Considerations
Goal - a graphic element showing a percentage value for a custom report.
Format - Either a full graphic (or infographic) itself, or part of a PDF via Photoshop/InDesign or even iBooks (as an excuse to use it).
Usage - I'd like the process to be programmatic, for re-use. It needs to be accurate, and I'd like the solution to be somewhat object oriented to apply to other datasets and graphical containers. This rules out hand-drawn charting.
Source data - currently a pivot table in Excel, but I can work with any other host as required.
Shape - is a custom vector shape that will originate from Illustrator/Inkscape. final format as best fits resolution and rendering of the report. I would also be interested in any other generative shape ideas (such as java/javascript).
Fill - I'd like to be able to represent the fill as both an actual percentage of total area (true up), and as a percentage of the vertical scale. I'd imagine this flexibility would also help reuse of the method as a fill value against selected object variables (height, area, whatever).
I know I'm being slightly vague in the programming languages or hosts side of things, but this gives me an opportunity to break out of the usual analytic toolchain and scope out some innovative or new solutions. I'm specifically interested in open source solutions, but I'm very keen to review other current methods you might suggest.
This might be a little open ended for you, but d3.js is very powerful. There might be some useful templates on the site, or you can build your own from the library.
If you limit yourself to shapes where the percentage can be easily converted into a new shape by varying one of the dimensions, then the display part can be covered by creating a second shape based on the first one, and filling in 100% of the second shape.
This obviously works best with simple shapes like squares, rectangles, circles, etc, where it is simple to convert "50% of the area" or "75% of the height" into manipulation of vector nodes.
However, things gets significantly more difficult if you want to support genuinely arbitrary custom shapes. One way to handle that would be to break up a complex "progress bar" into "progress pieces" (e.g. a thermometer bulb that represents 10% of total progress, then a simple bar for the remaining 90%).
As has been mentioned, D3 seems like it would meet your needs - here are some simple examples of what I think you are asking:
Changing the fill color of a distinct shape: http://jsfiddle.net/jsl6906/YCMb8/
Changing the 'fill amount' of a simple shape: http://jsfiddle.net/jsl6906/YCMb8/1/

Evenly distibuted scatterViewItems that dont overlap

I have an app that creates a variable number of ScatterviewItems based on which tagged object is placed on the surface table.
The ScatterViewItems are added programatically to the ScatterView based on info looked up in a DB
The Scatterview does a good job of displaying this info
However, I would like them to be
evenly distributed across the table and
not have any items overlapping
Any ideas how to do that?
Sounds like you need collision detection.
There's two parts to this problem: detection and resolution. Detection is seeing if any item's bounding intersects with any other item's bounding. If the items are retangular or circular this is pretty straightforeward. It can get complex if you're dealing with other geometries.
Resoltion is what to do once you've detected a collision. Google will help you find the myriad algorithms for this. Here's a couple links to stackoverflow discussions: WPF: Collision Detection with Rotated Squares, Applying Coefficient of Restitution in a collision resolution method, Best way to detect collision between sprites?.
You can implement collision to work so that items bound off of each other as they scatter. Depending on the number of items, this might cause so much collision that the items don't scatter well. If this happens, just run the collision detection one items have stopped moving.
UniformGrid ?
You can also create your own panel by iheriting from Panel.
You will find some uber-valuable info in the Dr. WPF ItemsControl How-To series : http://drwpf.com/blog/itemscontrol-a-to-z/
That's a must-read, period.
ScatterViewItem has properties Center and Orientation which you can use to programmatically position items. If you know the size of each item you should be able to use these properties to position them in whichever way is ideal for your situation. By hooking into the Loaded event of each and checking ActualWidth/ActualHeight, you can get the dimensions. If you can use a fixed initial size for all of your SVIs, that's even easier.
You could lay them out by calculating a simple grid (plus some randomness to make it look more natural), or you may be looking for what's called a "force directed layout", which gives each object a repellent force relative to its size. After a while the elements will naturally be evenly spaced from one another, though they may still overlap if they run out of room. I haven't seen a WPF example of this, but see flare.prefused.org/demo (layout > force) for what I mean in Flash.

Resources