<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>BlackHC's Adventures in the Dev World &#187; Macros</title>
	<atom:link href="http://blog.blackhc.net/tag/macros/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.blackhc.net</link>
	<description>Just another weblog</description>
	<lastBuildDate>Wed, 16 Nov 2011 23:12:15 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Seminar about Motion Retargeting</title>
		<link>http://blog.blackhc.net/2009/01/seminar-about-motion-retargeting/</link>
		<comments>http://blog.blackhc.net/2009/01/seminar-about-motion-retargeting/#comments</comments>
		<pubDate>Fri, 30 Jan 2009 23:32:20 +0000</pubDate>
		<dc:creator>BlackHC</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Maths]]></category>
		<category><![CDATA[University]]></category>
		<category><![CDATA[CCD]]></category>
		<category><![CDATA[Inverse Kinematics]]></category>
		<category><![CDATA[Macros]]></category>
		<category><![CDATA[Motion Retargeting]]></category>
		<category><![CDATA[Particle IK]]></category>
		<category><![CDATA[PowerPoint]]></category>
		<category><![CDATA[Spore]]></category>
		<category><![CDATA[VBA]]></category>

		<guid isPermaLink="false">http://blog.blackhc.net/?p=290</guid>
		<description><![CDATA[<a href="http://blog.blackhc.net/2009/01/seminar-about-motion-retargeting/" title="Seminar about Motion Retargeting"></a>Two weeks ago I had to give a presentation about Motion Retargeting, which I want to share with you now. I created it due to me attending a seminar about the latest developments in Computer Graphics at university and my &#8230;<p class="read-more"><a href="http://blog.blackhc.net/2009/01/seminar-about-motion-retargeting/">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<a href="http://blog.blackhc.net/2009/01/seminar-about-motion-retargeting/" title="Seminar about Motion Retargeting"></a><p><a href="http://blog.blackhc.net/wp-content/uploads/2009/01/creatureanimationwb.gif"><img class="alignright size-full wp-image-300" title="creatureanimationwb" src="http://blog.blackhc.net/wp-content/uploads/2009/01/creatureanimationwb.gif" alt="creatureanimationwb" width="147" height="110" /></a>Two weeks ago I had to give a presentation about Motion Retargeting, which I want to share with you now.<br />
I created it due to me attending a seminar about the latest developments in Computer Graphics at university and my presentation was about the Siggraph '08 paper "<a href="http://www.chrishecker.com/images/c/cb/Sporeanim-siggraph08.pdf" target="_blank">Real-time Motion Retargeting to Highly Varied User-Created Morphologies</a>" from Chris Hecker et al.<br />
You can check it out on <a href="http://www.chrishecker.com/Real-time_Motion_Retargeting_to_Highly_Varied_User-Created_Morphologies" target="_blank">Chris Hecker's homepage</a> - his website also contains a bunch of other really cool articles and presentations from various conferences, so it certainly is worth taking a look at it.</p>
<p>I've also sifted through quite a lot of IK papers and lectures for my presentation to understand the later part about the IK solver in Spore and I've found a few links that are a nice read:</p>
<ul>
<li><a href="http://www.chrishecker.com/Inverse_Kinematics" target="_blank">Chris Hecker's talk</a> about IK is a nice introduction (you also get an audiostream which is nice, too).</li>
<li><a href="http://ir.lib.sfu.ca/handle/1892/7119" target="_blank">Chris Welman's Master Thesis</a> is nice for reading about some of the common methods to solve IK problems.</li>
<li><a href="http://graphics.ucsd.edu/courses/cse169_w05/index.html" target="_blank">Steve Rotenberg's Computer Animation</a> course is awesome - the slides about IK are nice, but the ones about locomotion are just awesome<a class="annotation" title="they really really are!" href="javascript:;"><strong>&#180;</strong></a>!</li>
<li>Particle IK and particle physics in games are related a lot (the constraint solver is pretty much the same) and for a nice read I can recommend <span lang="EN-US"><a href="http://www.teknikus.dk/tj/gdc2001.htm" target="_blank">Thomas Jakobsen's Advanced Character Physics</a>.</span></li>
<li><span lang="EN-US"><a href="http://www.pixar.com/companyinfo/research/pbm2001/" target="_blank">Pixar's Physically Based Modelling</a> course from 2001 is also nice to get going with physics again - it also explains everything you need to understand the idea behind ODE solvers in rigid body simulations  and also has a very nice explanation of stiffness in ODEs.</span></li>
<li><span lang="EN-US"><a href="http://books.google.com/books?id=2anZacrFaxoC&amp;printsec=frontcover" target="_blank">Principles of Animal Locomotion</a> is a very neat book that is about, well, the principles of animal locomotion, which I have read a bit thanks to Google books and it certainly is quite interesting.</span></li>
<li><span lang="EN-US"><a href="http://www.robotom.de/robi.htm" target="_blank">Numerical Robot Kinematics Based on Stochastic and Molecular Simulation Methods</a> is interesting, too, just to see what's possible with particle IK</span></li>
</ul>
<p>Ive created a huge PowerPoint presentation for my seminar  <img src='http://blog.blackhc.net/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />  It includes a few videos (thanks again to Chris Hecker for uploading them and replying to my emails incredibly fast <a class="annotation" title="he replied to each and every one of them within 20 minutes, which is crazy fast, if you're used to university communication ;-)" href="javascript:;"><strong>&#180;</strong></a>) and two <strong>awesome</strong> IK solvers that I've implemented with VBA macros<a class="annotation" title="VBA is horrible BTW" href="javascript:;"><strong>&#180;</strong></a> to show how CCD and Particle IK solvers work.</p>
<p>You can find a zip with all the videos and high resolution images <a href="http://blog.blackhc.net/wp-content/uploads/2009/01/MotionRetargeting.zip">here </a>(includes both a PPT 2003 file and a 2007 file). I've also uploaded a small version without videos, macros as PPT 2003 file <a href="http://blog.blackhc.net/wp-content/uploads/2009/01/motionretargetingcompat.ppt">here</a>, if you don't feel like downloading the 23 MB .zip file.</p>
<p>Here's a YouTube video of the two IK solvers:</p>
<p><a href="http://blog.blackhc.net/2009/01/seminar-about-motion-retargeting/"><em>Click here to view the embedded video.</em></a></p>
<div class="expandable"><a class="expandable_link" href="javascript:blackhc_replacements_togglediv('blackhc_expandable_1');">Click to expand &#187;</a>
<div class="expandable_text" name="blackhc_expandable_1" id="blackhc_expandable_1" style="display:none">The CCD solver usually works by solving one bone per inner iteration - I only added a max delta angle to create smooth animations (same for the max delta length in the Particle IK solver).</p>
<p>It seems as if the CCD solver could converge faster if it randomly chose the first joint instead of starting with the end effector joint in every outer iteration.</p></div>
<p></div>
<p>I've exported the code into an additional IK Playground presentation which contains just one slide and the two IK solvers with the setup you see in the video above. You can find the PPT 2003 version of it <a href="http://blog.blackhc.net/wp-content/uploads/2009/01/ikplayground.ppt">here</a> and the 2007 one <a href="http://blog.blackhc.net/wp-content/uploads/2009/01/ikplayground.pptm">here</a>.</p>
<p>I've zipped up the macros <a href="http://blog.blackhc.net/wp-content/uploads/2009/01/mr-pptmacros.zip">here</a> if you want to use them in your own slides. I've also written a handy VBA form that allows one to edit everything more easily (the macros are hardly documented though, but if anyone really wants to use them and runs into problems - you can always drop me a line or two in a comment <img src='http://blog.blackhc.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> )</p>
<p style="text-align: center;">
<div id="attachment_302" class="wp-caption aligncenter" style="width: 501px"><a href="http://blog.blackhc.net/wp-content/uploads/2009/01/iksolvertool1.jpg"><img class="size-large wp-image-302" title="iksolvertool1" src="http://blog.blackhc.net/wp-content/uploads/2009/01/iksolvertool1-1024x622.jpg" alt="The IK Solver Tool Form" width="491" height="298" /></a><p class="wp-caption-text">The IK Solver Tool Form</p></div>
<p>BTW I'm not sure you know about it<a class="annotation" title="I only learned of it by chance" href="javascript:;"><strong>&#180;</strong></a>, but <a href="http://www.blender.org/">Blender</a> contains an awesome video editor - the UI needs some time to get used to, but the online documentation has improved a lot and with it, it works like a charm. Blender also supports some <a href="http://wiki.blender.org/index.php/Manual/Sequence_Plugins">pretty professional filters</a>, so it's going to be my video editing tool of choice from now on.</p>
<p>Cheers,<br />
Andreas</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.blackhc.net/2009/01/seminar-about-motion-retargeting/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>A Visual Studio Macro Day</title>
		<link>http://blog.blackhc.net/2008/10/a-visual-studio-macro-day/</link>
		<comments>http://blog.blackhc.net/2008/10/a-visual-studio-macro-day/#comments</comments>
		<pubDate>Mon, 06 Oct 2008 21:08:32 +0000</pubDate>
		<dc:creator>BlackHC</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Visual Studio Extensibility]]></category>
		<category><![CDATA[Code Model]]></category>
		<category><![CDATA[Extensibility]]></category>
		<category><![CDATA[Macros]]></category>
		<category><![CDATA[Visual Basic]]></category>
		<category><![CDATA[Visual Studio]]></category>

		<guid isPermaLink="false">http://blackhc.wordpress.com/?p=237</guid>
		<description><![CDATA[<a href="http://blog.blackhc.net/2008/10/a-visual-studio-macro-day/" title="A Visual Studio Macro Day"></a>Today I decided to continue work on a Visual Studio macro I started developing on Sunday (I mainly worked on it today though - Sunday was just document reading before heading back to Munich and going out with friends). The &#8230;<p class="read-more"><a href="http://blog.blackhc.net/2008/10/a-visual-studio-macro-day/">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<a href="http://blog.blackhc.net/2008/10/a-visual-studio-macro-day/" title="A Visual Studio Macro Day"></a><p>Today I decided to continue work on a Visual Studio macro I started developing on Sunday (I mainly worked on it today though - Sunday was just document reading before heading back to Munich and going out with friends).</p>
<p>The samples from Microsoft simply use the comments from MSDN on functions/methods that are part of a class's interface implementation.</p>
<p>I 'documented' a few of my functions by copying the summary out of MSDN but it's a tedious job and consequently I decided to try and automate it.<br />
Although Visual Basic 'sucks' or is a least quite some change from writing C/C++/C# code all the time, the Automation model is very powerful and quite nice to use.</p>
<p>My macro provides two methods:</p>
<ul>
<li>One to add comments to all methods that are part of an interface's implementation</li>
<li>One to add comments to the method the cursor currently resides in</li>
</ul>
<p>My code currently only adds comments from interface definitions that have been defined outside the current project. It's pretty nifty in my opinion because usually these interface comments won't change a lot and thus it's safe to add them to the source code, while the interfaces one has written themself can still change and the macros can't track that and/or update the comments afterwards.</p>
<p>However, I've added a configuration boolean, so this behavior can be turned off if needed.</p>
<p><em>My code won't remove or replace comments, it will just add the comment in front of other comments - if the comment doesn't already exist - I've tried to make it quite safe, so code loss or corruption will be avoided.<br />
</em></p>
<p>I hope this code is helpful. I'm releasing it under the Microsoft Public License. If there are good reasons to use a different license, feel free to tell me so <img src='http://blog.blackhc.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Cheers,<br />
Andreas</p>
<p><span id="more-123"></span></p>
<pre class="brush: vb; title: ; notranslate">
' Andreas 'BlackHC' Kirsch 2008
' released under Microsoft Public License
Imports System
Imports EnvDTE

Public Module CommentImplementedMethods
    ' we usually only want to use external interfaces because it's safer to assume those won't change anytime soon
    Const UseExternalInterfaceCommentsOnly = True

    Private Function GetSummaryFromDocComment(ByVal docComment As String) As String
        Const summaryStartTag = &quot;&lt;summary&gt;&quot;
        Const summaryEndTag = &quot;&lt;/summary&gt;&quot;
        Dim summaryIndex = docComment.IndexOf(summaryStartTag)
        If summaryIndex = -1 Then
            Return &quot;&quot;
        End If
        Dim summaryStart = docComment.Substring(summaryIndex + summaryStartTag.Length)
        Return summaryStart.Substring(0, summaryStart.IndexOf(summaryEndTag))
    End Function

    'Private Function GetInterfaceByName(ByRef classObject As CodeClass, ByRef name As String) As CodeInterface
    '    For Each implementedInterface As CodeInterface In classObject.ImplementedInterfaces
    '        If implementedInterface.Name = name Then
    '            Return implementedInterface
    '        End If
    '    Next
    'End Function

    Private Function GetMethod(ByRef interfaceObject As CodeInterface, ByRef methodObject As CodeFunction) As CodeFunction
        Dim prototypeFlags As Int32 = vsCMPrototype.vsCMPrototypeParamTypes Or vsCMPrototype.vsCMPrototypeType
        Dim prototype As String = methodObject.Prototype(prototypeFlags)

        Dim separationIndex = methodObject.Name.IndexOf(&quot;.&quot;c)
        If separationIndex &lt;&gt; -1 Then
            Dim interfaceName = methodObject.Name.Substring(0, separationIndex)
            If interfaceName &lt;&gt; interfaceObject.Name Then
                Return Nothing
            End If

            Dim realMethodName = methodObject.Name.Substring(separationIndex + 1)
            prototype = prototype.Replace(methodObject.Name, realMethodName)
        End If

        For Each member As CodeElement In interfaceObject.Members
            If member.Kind &lt;&gt; vsCMElement.vsCMElementFunction Then
                Continue For
            End If

            Dim method As CodeFunction = member
            If method.Prototype(prototypeFlags) = prototype Then
                Return method
            End If
        Next

        Return Nothing
    End Function

    Private Function GetInterfaceMethod(ByRef methodObject As CodeFunction) As CodeFunction
        Dim parentClass As CodeClass = methodObject.Parent
        For Each implementedInterface As CodeInterface In parentClass.ImplementedInterfaces
            If implementedInterface.InfoLocation = vsCMInfoLocation.vsCMInfoLocationProject And UseExternalInterfaceCommentsOnly Then
                Continue For
            End If
            Dim matchedMethod = GetMethod(implementedInterface, methodObject)
            If Not IsNothing(matchedMethod) Then
                Return matchedMethod
            End If
        Next
    End Function

    Private Function GetCurrentMethod() As CodeFunction
        Dim sel As TextSelection = _
            CType(DTE.ActiveDocument.Selection, TextSelection)
        Dim pnt As TextPoint = CType(sel.ActivePoint, TextPoint)

        Dim method As CodeFunction = pnt.CodeElement(vsCMElement.vsCMElementFunction)
        Return method
    End Function

    Private Sub AddCommentToMethod(ByRef methodObject As CodeFunction, ByRef newComment As String)
        If methodObject.Comment.IndexOf(newComment) &lt;&gt; -1 Then
            ' This comment has already been added
            Exit Sub
        End If
        methodObject.Comment = newComment &amp; vbNewLine &amp; methodObject.Comment
    End Sub

    Public Sub CommentImplementedMethod()
        Try
            Dim currentMethod = GetCurrentMethod()
            If IsNothing(currentMethod) Then
                MsgBox(&quot;Not inside a method scope at the moment!&quot;)
                Exit Sub
            End If

            Dim interfaceMethod = GetInterfaceMethod(currentMethod)
            If IsNothing(interfaceMethod) Then
                If UseExternalInterfaceCommentsOnly Then
                    MsgBox(&quot;*External* interface method could not be found!&quot;)
                Else
                    MsgBox(&quot;Interface method could not be found!&quot;)
                End If
                Exit Sub
            End If

            Dim newComment = GetSummaryFromDocComment(interfaceMethod.DocComment)
            AddCommentToMethod(currentMethod, newComment)
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub

    Private Sub TraverseAndCommentImplementedMethods(ByRef elements As CodeElements)
        For Each child As CodeElement In elements
            If child.Kind = vsCMElement.vsCMElementFunction Then
                Dim currentMethod = CType(child, CodeFunction)
                If IsNothing(currentMethod) Then
                    Exit Sub
                End If

                Dim interfaceMethod = GetInterfaceMethod(currentMethod)
                If IsNothing(interfaceMethod) Then
                    Exit Sub
                End If

                Dim newComment = GetSummaryFromDocComment(interfaceMethod.DocComment)
                AddCommentToMethod(currentMethod, newComment)
            End If
            TraverseAndCommentImplementedMethods(child.Children)
        Next
    End Sub

    Public Sub CommentAllImplementedMethodsInFile()
        Try
            TraverseAndCommentImplementedMethods(DTE.ActiveDocument.ProjectItem.FileCodeModel.CodeElements)
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub
End Module
</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.blackhc.net/2008/10/a-visual-studio-macro-day/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

