To get the point where two lines intersect, we will do some maths. To the mathematicians who will come across this post, I’m truly sorry for the heart attacks or strokes you may experience by reading this post.
Ok, let’s take a look on the figure:
Figure 1
First, sorry, I was too lazy to make a proper figure using computer tools so I just put a scan. XD
Next, here are the definitions:
& : the two lines,
, : the arbitrary starting points of the two lines,
, : the arbitrary points which tells the direction of the two lines,
: the intersection point,
: the origin point.
Kewl. Now, what we want is the intersection point between those two lines. In other words, we want to know the position which starts from either lines’ arbitrary starting point, added by the direction of the line multiplied by a scalar value. So in our figure 1, the position is:
the position added by the components of multiplied by an unknown which I named
the position added by the components of multiplied by an unknown which I named
In this case, it is clear that so it will be easy to check if our final formula is correct. 🙂
At the point of intersection, we know that:
… which gives us:
But we can’t use this statement exactly like this to solve our equation as we cannot multiply and divide vectors in this raw format. Also we need to reduce the unkowns count to 1. So we will separate our equation into two equations with the magic of matrices (which I don’t understand well at the moment), one for the x component and one for the y:
To make our equation more readable, we will use some shorthands:
… so:
From this point, we can reduce the unknown count. In my case, I have chosen to keep instead of :
And finally, you have to check if . This will happen if your two lines are parallel or if there is one line defined as a point such as or ; no solution exists in those cases.
Je viens de passer trente minutes à chercher la solution à un problème empêchant d’ouvrir le navigateur par défaut sur Windows depuis un logiciel C++ via ShellExecuteA(), en l’occurrence, le jeu Esteren : Les Griffes du Seigneur Sorcier dont le kickstarter est toujours en cours au moment où j’écris cet article. 😛
La solution dans mon cas a été de redéfinir le navigateur par défaut, par exemple en passant par Chrome puis en revenant à Firefox. Juste avec cette simple manipulation, le ShellExecuteA() a fonctionné de nouveau. C’est tout !
Et oui, rien à voir avec un bug de votre code, c’est probablement de la faute des autres qui ne font pas bien leur boulot !
Il fallait que j’intègre des boutons dans un projet cocos2d-x pour rediriger sur des pages de réseaux sociaux. Mais à mon grand regret, il n’existe pas de fonction préparée dans le framework de cocos2d-x (version 3.2) pour ouvrir une page de navigateur. Il m’a alors fallu l’implémenter moi-même.
Content.
Fort heureusement, des personnes se sont déjà penchées sur la question et une source m’a été particulièrement utile. Pour info, ce qui va suivre pourrait aussi servir à ouvrir des fichiers en local (file://) ou toute ressource pointable par un URI (tant qu’il y a un logiciel qui peut gérer cet URI, of course) ! Mes chers lecteurs francophones (parce qu’aucun anglophone ou autre ne viendrait ici huhu), voici un récapitulatif :
Partie Windows
cocos/platform/win32/CCApplication.h
C++
1
voidApplication::openURL(constchar*url);// à ajouter parmi les membres publics
cocos/platform/win32/CCApplication.cpp
C++
1
2
3
4
5
/* Opens URL in browser. */
voidApplication::openURL(constchar*url)
{
ShellExecuteA(NULL,« open »,url,NULL,NULL,SW_SHOWNORMAL);
}
Partie Android
cocos/platform/android/CCApplication.h
C++
1
voidApplication::openURL(constchar*url);// à ajouter parmi les membres publics
Alors que je devais préparer un exécutable d’un projet sur Visual Studio Community (VS2013), j’ai dû configurer le projet pour que l’exécutable puisse fonctionner sur Windows XP. Les paramètres par défaut provoquent une erreur de type « application win32 non valide ».
Pour corriger cela, il suffit d’aller dans les propriétés du projet et de définir Platform Toolset à Visual Studio 2013 – Windows XP (v120_xp). Ainsi, l’exécutable pourra fonctionner sur Windows XP si toutes les bibliothèques (dll) — telles que les pilotes et le package redistribuable Visual C++ 2013 — ont été installées.