Do I need to map skeletal data into color image point? - kinect/XNA - kinect

I have been working on a project where I need to interact with 3D objects using a hand joint, now I do that using distance formula but however . . i'm using hand joint (X,Y,Z) and using a formula to convert them to 3D space to be able to have the interact with the Models.
Instead of using a formula to do the conversion . . do i actually need to use the function MapSkeletalpoint to color image point??
To give an idea about what i'm doing:
var rightHands = playerSkeleton.Joints[JointType.HandRight];
var rightHandsX = rightHands.Position.X;
var rightHandsY = rightHands.Position.Y;
var rightHandsZ = rightHands.Position.Z;
HandX = rightHands.Position.X;
HandY = rightHands.Position.Y;
HandZ = rightHands.Position.Z;
foreach (_3DModel s in Solar)
{
x_mod = (float)Math.Floor(((HandX * 0.5f)) * maxWidth);
y_mod = (float)Math.Floor(((HandY * -0.5f)) * maxHeight);
z_mod = (float)Math.Floor((HandZ) / 4 * 20000);
if (Math.Sqrt(Math.Pow(x_mod - s.modelPosition.X, 2) + Math.Pow(y_mod- s.modelPosition.Y, 2) + Math.Pow(z_mod - s.modelPosition.Z,2)) < 20)
{
sound.Play();
Console.WriteLine("1" + "handx:" + x + "," + " " + "modelPos.X:" + s.modelPosition.X + "," + " " + "handY:" + y + "modelPos.Y:" + s.modelPosition.Y);
}

Actually, it's not easy to create effective hit test especially when there is larger number of objects.
The thing you need is a collision system. My recommendation to you is that you should use some existing, for example BEPU might be helpful:
http://bepu.squarespace.com/
You should bind the position of an object with the position of the hand (reported by Kinect) and BEPU will do the rest (it will trigger a handler in case of collision).
Just a small advice - it's always good to use relative position of the hand (e.g. to the shoulder). Using absolute coordinates reported by Kinect is not always desired in Kinect-based games (but you know better what you want)

Related

Best way to return a functions string in another method?

I'm trying to simplify/cut down a bunch of repeating SQL code in a ruby program, and so am taking repeated lines of code and placing them in their own function.
def companies_data
"""
companies.data->>'creditor_number' as creditor_number,
companies.data -> 'pay_to_bank_account' ->> 'iban' AS iban,
company_invoices.from_date,
company_invoices.to_date,
concat(company_invoices.r_number, company_invoices.s_number) as rechnungsnummer,
companies.send_invoice_automatically,
companies.claim_netting,
ROUND(company_invoices.total_cents)/100 AS netting_betrag,
ROUND(company_invoices.billable_dca_fees_recovered_to_creditor_cents + company_invoices.billable_dca_fees_recovered_to_creditor_vat_cents + company_invoices.billable_dca_flat_fees_cents + company_invoices.billable_dca_flat_fees_vat_cents + company_invoices.billable_dca_success_fees_cents + company_invoices.billable_dca_success_fees_vat_cents + company_invoices.billable_tax_free_dca_costs_cents + company_invoices.billable_taxable_dca_costs_cents + company_invoices.billable_taxable_dca_costs_vat_cents)/100 AS rechnungsbetrag,
round(company_invoices.billable_dca_fees_recovered_to_creditor_cents + company_invoices.billable_dca_fees_recovered_to_creditor_vat_cents + company_invoices.billable_dca_flat_fees_cents + company_invoices.billable_dca_flat_fees_vat_cents + company_invoices.billable_dca_success_fees_cents + company_invoices.billable_dca_success_fees_vat_cents + company_invoices.billable_tax_free_dca_costs_cents + company_invoices.billable_taxable_dca_costs_cents + company_invoices.billable_taxable_dca_costs_vat_cents - company_invoices.total_cents)/100 AS abrechnungsbetrag,
case_files.currency,
companies.vat_perspective,
companies.creditor_payout_by_case_file_invoice
"""
I would then like to be able to print that string where I require it inside other functions down the line like
def query_for_non_vat_payer
"SELECT
distinct NAME,
#{companies_data}
FROM case_file_invoices
JOIN case_files ON case_file_invoices.case_file_id = case_files.id
JOIN companies ON companies.id = case_files.company_id
JOIN company_invoices ON company_invoices.id = case_file_invoices.company_invoice_id
WHERE date_part('year', company_invoices.to_date) = 2021
AND date_part('month', company_invoices.to_date) = 07
AND companies.vat_perspective = 'not_vat_payer'
and companies.invoicing_cycle = 'monthly'"
end
Is #{companies_data} really the best way?
This depends what you call "best". In your case, companies_data does not do any calculation, but returns the same string always. In this case, I would find it more natural to not have a function, but a constant:
COMPANIES_DATA = ....
But I don't know your object model. If you are in a class hierarchy, where query_for_non_vat_payer is in a parent class, and the subclasses are allowed/expected to provide their own version of companies_data, a method is of course the way to go.

Problem with setting indent of bullet items in textframe

I am trying to port some existing VBA code to C#. One routine controls the indentation of bullet items, and is roughly:
indentStep = 13.5
For Each parag In shp.TextRange.Paragraphs()
parag.Parent.Ruler.Levels(parag.IndentLevel).FirstMargin = indentStep * (parag.IndentLevel - 1)
parag.Parent.Ruler.Levels(parag.IndentLevel).LeftMargin = indentStep * (parag.IndentLevel)
Next parag
The code works, but appears to be spooky black magic. In particular, each time a particular ruler's margins are set ALL NINE rulers margins are actually set.
But somehow the appropriate information is being set. Unfortunately, when you do the same thing in C#, the results change. The following code has no visible effect:
const float kIndentStep = 13.5f;
foreach (PowerPoint.TextRange pg in shp.TextFrame.TextRange.Paragraphs())
{
pg.Parent.Ruler.Levels[pg.IndentLevel].FirstMargin = kIndentStep * (pg.IndentLevel - 1);
pg.Parent.Ruler.LevelS[pg.IndentLevel].LeftMargin = kIndentStep * pg.IndentLevel;
}
This appears to be a limitation/bug when automating PowerPoint from C#. I confirm it works with VBA.
I do see an effect after the code runs: it changes the first level with each run so that, at the end, the first level has the settings that should have been assigned to the last level to be processed, but none of the other levels appear to be affected, visibly. I do see a change in the values returned during code execution, but that's all.
If the code changes only one, specific level for the text frame, it works. The problem occurs only when attempting to change multiple levels.
I tried various approaches, including late-binding (PInvoke) and putting the change in a separate procedure, but the result was always the same.
Here's my last iteration
Microsoft.Office.Interop.PowerPoint.Application pptApp = (Microsoft.Office.Interop.PowerPoint.Application) System.Runtime.InteropServices.Marshal.GetActiveObject("Powerpoint.Application"); // new Microsoft.Office.Interop.PowerPoint.Application();
//Change indent level of text
const float kIndentStep = 13.5f;
Microsoft.Office.Interop.PowerPoint.Shape shp = pptApp.ActivePresentation.Slides[2].Shapes[2];
Microsoft.Office.Interop.PowerPoint.TextFrame tf = shp.TextFrame;
object oTf = tf;
int indentLevelLast = 0;
foreach (Microsoft.Office.Interop.PowerPoint.TextRange pg in tf.TextRange.Paragraphs(-1, -1))
{
int indentLevel = pg.IndentLevel;
if (indentLevel > indentLevelLast)
{
Microsoft.Office.Interop.PowerPoint.RulerLevel rl = tf.Ruler.Levels[indentLevel];
object oRl = rl;
System.Diagnostics.Debug.Print(pg.Text + ": " + indentLevel + ", " + rl.FirstMargin.ToString() + ", " + rl.LeftMargin.ToString()) ;
object fm = oRl.GetType().InvokeMember("FirstMargin", BindingFlags.SetProperty, null, oRl, new object[] {kIndentStep * (indentLevel - 1)});
//rl.FirstMargin = kIndentStep * (indentLevel - 1);
object lm = oRl.GetType().InvokeMember("LeftMargin", BindingFlags.SetProperty, null, oRl, new object[] { kIndentStep * (indentLevel) });
//rl.LeftMargin = kIndentStep * indentLevel;
indentLevelLast = indentLevel;
System.Diagnostics.Debug.Print(pg.Text + ": " + indentLevel + ", " + tf.Ruler.Levels[indentLevel].FirstMargin.ToString() + ", " + tf.Ruler.Levels[indentLevel].LeftMargin.ToString()) ;
rl = null;
}
}
FWIW neither code snippet provided in the question compiles. The VBA snippet is missing .TextFrame. The C# snippet doesn't like Parent.Ruler so I had to change it to TextFrame.Ruler.

How can this code be written shorter/clearer?

newRow("OrderReference") = line.Substring(line.IndexOf("*1003") + 5, line.IndexOf("*", line.IndexOf("*1003") + 5) - line.IndexOf("*1003") - 5)
There you have it. Very long and ugly. I was thinking about this:
Dim indexPlus = line.IndexOf("*1003") + 5
Dim indexMinus = line.IndexOf("*1003") - 5
newRow("OrderReference") = line.Substring(indexPlus, line.IndexOf("*", indexPlus) - indexMinus)
But that introduces new and meaningless vars. Unsatisfying.
Maybe RegEx is the savior here?
Unfortunately I mustn't change the input data :-(
The input data consist of the BWA-format (popular with books). Here you can see the part in question:
All codes in this example set are required. Only corresponding values change.
I don't even think your second code works. It seems more like this.
Dim index = line.IndexOf("*1003") + 5
newRow("OrderReference") = line.Substring(index, line.IndexOf("*", indexPlus) - index)
10 - 5 - 2 isn't the same as 10 - (5 - 2) but instead it's the same as 10 - (5 + 2).
Next time, check out the codereview stack exchange.
Given that your data is always constant, and what you're looking for always begins with "*1003", you don't need to use Regex (Even though you could). Just use what you're already using but with some corrections.
using System;
public class Program
{
public static void Main()
{
string input = "L10113540 VD44444 VD2002100234949 000116161 04201261\r\n";
input += " KN00010000000129000LPEUR003000001*1003A.Muller-Schulz*1017Bastei\r\n";
input += "Lubbe.61204 Laund.Meine Schuld*1019KL*102990300*1030NO*1032EUR*1131KT";
int start = input.IndexOf("*1003");
int end = input.IndexOf("*", start + 1);
string result = input.Substring(start + 5, end - start - 5);
Console.WriteLine(result);
// Your code
start = input.IndexOf("*1003") + 5;
end = input.IndexOf("*1003") - 5;
result = input.Substring(start, input.IndexOf("*", start) - end);
Console.WriteLine(result);
}
}
Result
A.Muller-Schulz
A.Muller-Schulz*1017Baste
You can see that what you posted in your question, doesn't give the results you want. All you're really looking for is just the next asterisk after the first "*1003". You can see the difference between your code and what I've given.
.NET Fiddle Example

Cannot use contenteditable widget on server side paged tablesorter

I have a tablesorter project which has been working good with client side paging since some months. Now I have to turn it to server side paging but I can't get it to work with all the features I was using with client side version.
As on subject, my problem is to make the contenteditable feature to work.
What I've done to achieve that, is to write a custom function to bind to ajaxProcessing handler on the tablesorterPager config:
ajaxProcessing: function (data) {
if (data && data.hasOwnProperty('rows')) {
var str = "", d = data.rows,
// total number of rows (required)
total = data.total_rows,
// len should match pager set size (c.size)
len = d.length;
for (var i = 0; i < len; i++) {
str += '<tr>';
for (var column = 0; column < orderedFieldMapping.length; column++) {
if (orderedFieldMapping[column].toUpperCase() != 'ACTIVATIONDATE' || bReadOnly)
str += '<td class="' + orderedFieldMapping[column].toUpperCase() + '"' + ($('#' + orderedFieldMapping[column].toUpperCase()).prop('checked') ? '' : 'style="display:none;"') + '><div>' + (eval('d[i].' + orderedFieldMapping[column]) != null ? eval('d[i].' + orderedFieldMapping[column]) : '') + '</div></td>';
else
str += '<td class="' + orderedFieldMapping[column].toUpperCase() + '"' + ($('#' + orderedFieldMapping[column].toUpperCase()).prop('checked') ? '' : 'style="display:none;"') + '><div ' + (eval('d[i].' + orderedFieldMapping[column]) != null ? '' : 'class="emptyPlaceholder"') + 'onmouseup="javascript:SelectActivationDateText(this);" onblur="javascript:RestoreCellStyle(this);">' + (eval('d[i].' + orderedFieldMapping[column]) != null ? eval('d[i].' + orderedFieldMapping[column]) : emptyTextString) + '</div></td>';
}
str += '</tr>';
}
// in version 2.10, you can optionally return $(rows) a set of table rows within a jQuery object
return [total, $(str)];
}
},
Please note that I'm returning a set of table rows within a jQuery object, option allowed as stated on the docs example comment (also visible on this code sample). The reason why I do such thing is that I need to control table markup to add styles, handlers and classes. That's what I do in the inner for cycle, and it's not very important knowing exactly what I'm doing there.
What is important is that I get the expected result and markup for my table, and server side paging is working with no issue, BUT contenteditable widget is not working.
I get no warnings on js console and all is working just fine, but I can't edit columns I marked as editable. I can see that also looking at the markup because contenteditable attribute is not present at all. Of course the widget is inintialized and configured (in the same way that it was on previous version, with client side paging).
Another hint that points on some widget malfunction (maybe): I managed to manually add (inside the very same function I posted above) the contenteditable attribute on the markup just to see if it would give me some information. In this case I can edit the content as expected, but I get no handler for editComplete event, and data acceptance settings are not applying. I could still manually add handlers and custom code to get it to work as intended, but it would be bad and I don't want to use a hack to get an already implemented feature to work.
Any hint would be appreciated, thanks to everyone who will answer.
I think I see the issue. The contenteditable widget does not re-apply the contenteditable property on the elements within the table cells when the content is updated (via the pager, or whatever).
So this is definitely a bug, I just opened a ticket: https://github.com/Mottie/tablesorter/issues/732
In the mean time, you can add the contenteditable property to the div in your markup:
str += '<td><div contenteditable>...</div></td>';

List checked nodes in Dynatree

I have tree created with Dynatree, with checkboxes in it.
Can you help me how can I get a list (or array) of checked checkboxes in it, so I can manipulate with them (move them into another tree)?
Tnx in adv!
Ok, here it is:
var selNodes = node1.tree.getSelectedNodes();
// convert to title/key array
var selKeys = $.map(selNodes, function(node1){
alert("[" + node1.data.key + "]: '" + node1.data.title + "'");
});