## OpenGL rotation, translation, projection matrices

I’ve finally written my next progression program and generated a cube.

If you simply drew this cube, you would only see the front part of the cube and nothing else. To get some 3D effect, I had to rotate the cube, then translate it out into the world and projected it into our screen. I used Jamie King’s 3D Computer Graphics Using OpenGL tutorial to create this program.

I’ve used following glm math functions to generate the full transformation Matrix:

• glm::perspective: The first parameter describes the field of view angle. It describes the angle the viewer can see. The second parameter is the aspect ratio and is the ratio between the screen width and screen height. The third and forth parameter describe the near and far clipping plane. Those two values need to be positive and near < far. These two values describe the area the camera can see. The resulting matrix is the projection matrix.
• glm::translate: The first parameter is the projection matrix generated before. The second on requires a vector which contains the coordinates the object has to move to. E.g., if you take following vector glm::vec3(2.0f, 1.0f, -2.0f), you tell the function to move the object 2 points along the positive x axis, 1 point along the positive y axis, and 2 points along the negative z axis. The point to remember here is that we look into the negative z axis. For some reason, this changes as soon as we are in the projection matrix (we look into the positive z axis). The resulting matrix is the projection translation matrix.
• glm::rotate: The first parameter is the projection translation matrix that has been generated before. The second one requires the degree by which the object needs to be rotated. The rotation uses the right hand rule. The third parameter requires a vector. If you want the rotation to be along the x axis, the vector would be glm::vec3(1.0f, .0f, .0f). Along the y axis, you need the vector to be glm::vec3(0f, 1.0f, .0f) and along the z axis glm::vec3(.0f, .0f, 1.0f). This function is fairly straight forward and easy to use.

Additionally, this program also uses a uniform matrix shader variable which can be written to by using the two OpenGL functions glGetUniformLocation and glUniformMatrix4fv. That’s the first program, that’s actually a bit exciting and already gives a lot of room for playing and experimenting. The code can as always be found in github.

Last but not least, the code generates two programs. One uses MFC (as before) as window creation/input wrapper and the other one uses freeglut. You can compile both by using NMAKE.

## Parenthood joys and sleep

My little one is currently in a phase again, where it takes him forever to fall asleep. It takes him around an hour in bed till he finally falls asleep. That by itself is already bad, but my problem in particular is that my body wants to go into sleep mode as soon as I lay down with him.

I need to lay next to him till he falls asleep, otherwise he won’t fall asleep at all. Normally, it only takes him about 20 minutes which is bearable. But an hour and more?

I’m one of those lucky persons that can fall asleep within minutes. I lie down, close my eyes, and shortly after I’m deep asleep. Without any doubt, I’m very happy about this, but when I have to lay down with my sweetheart, I need to stay up and work afterwards.

The last few weeks were hell on my body. I’m lying in bed waiting for my sweetheart to finally be quiet and fall asleep and my inner voice just screams: ‘Hey, you’re lying, why the hell aren’t you sleeping already? Stop fighting! Relax and sleep!’. But my little one doesn’t here my inner voice. He continues, ‘La, la, la, …, eye, eye (pointing at his or my eye), la, la, la, …’. I mean he is incredibly sweet and smiling all the time and it’s impossible to be mad, but at the same time it’s incredibly hard to not just get up again and let him fall asleep exhausted on the couch downstairs hours later.

As mother of a young one you don’t get much sleep in general and I’m not complaining. But why does it currently take him so long to relax? I have to admit, the last few weeks I definitely lost the fight against my inner ‘sleep’ voice a few times which means I fell asleep sometimes even before my little one. Hours later, I wake up fully dressed and wondering what’s going on.

Anyhow, I keep telling myself it’s just a phase and it’s going to be over soon. I just hope ‘soon’ comes sooner than later!

## My passion for C++

Not too long ago, I was asked why I liked C++ more than other programming languages. I honestly couldn’t come up with a good answer. In hindsight, there is no specific reason for it and I don’t think there has to be. I love the color brown. Why? I don’t know, I just do.

I’ve done a bit of Java programming in the past and even less in C# (during a university course, that’s it). I could just never really get into those languages. I guess I missed what so many developers hate: the pointer. I like being able to mess around with pointers (maybe that’s because I was embedded systems programmer for years) and I do enjoy the speed advantage C++ gives. Do I think C++ is superior over others, such as Java and Ruby? Nope, not at all. Every language has it’s pros and cons. If you need performance, you’ll likely need C++ and possibly also OpenMP/MPI/Cuda/etc. But let’s face it, 95% (if not even more) of programs don’t need to be super fast. And C++ has the big drawback that it is not very safe due to the pointers.

I think, my passion for C++ became even stronger with the release of the C++11 standard. It truly improved the language by a lot and introduced many cool features (for an overview, have a look at the Wiki page). A bit over a year ago, C++14 was released and honestly, I couldn’t wait for Visual Studio 2015 to support this release (with a few exceptions).

Developers often argue which language is the best, but at the end, the choice of language depends on many factors. Which programming language are the developers in the company most familiar with, what kind of application has to be developed, which platforms does it have to run on, how big will it be, etc. As developer, I think it is important to be open to new languages and to know a few, but it is just natural that we all favor one language over the other, whatever the reason for that may be.

There are other programming languages I do enjoy using as well. I’m currently learning ELisp and I definitely like it quite a bit. I’ve little experience in Ruby, but would love to properly learn it soon, since I love looking at Ruby code. Lately, I also use Javascript and PHP as well as HTML5 and CSS3. Therefore, my programming world doesn’t just consist of C++, but so far (and who knows, that might change one day) it is my programming language of choice.

## Cooking: Getting organized

I prefer staying at home and eating a homemade meal than going out and spending money for a meal I might not even enjoy that much. This attitude might have to do that I’m an introvert, but I also prefer knowing what’s in the food I’m eating (therefore, I’m not the biggest fan of ordering in either). Especially since I have my little sweetheart, I’m way more concerned about healthy nutrition than I was before.

Currently, I fall back to quick and boring suppers way too often due to a few reasons:

1. There are days, were I just simply don’t feel like cooking.
2. My little one tends to be very clingy later in the afternoon and as soon as I step into the kitchen, he wants me to pick him up (also because he wants to watch me cooking).
3. Although cooking is generally cheaper than going out, it can get quite expensive if you choose organic ingredients. Therefore, it’s best to look weekly at the local flyers, buy groceries that are on a good sale and then plan recipes that use those ingredients. Also, stocking up on items while they are on sale is a good idea (as long as they have a due date far in the future of course).

I’ve struggled with the above-mentioned hurdles for quite a while now. It’s time I tackle them finally.

### Overcome ‘I’m too tired/lazy’

• Write down recipes (it’s ingredients and maybe just a link to a site) that I like and some that I would like to try in the future.
• Plan for 5 to 6 quick meals and only one or two more labor intense suppers.
• Create the list of recipes via org-mode in emacs. Save the files in my gdrive so that I can access it on my phone.
• Write an elisp script that copies ingredient lists into the ‘grocery shopping’ list via a key-press.
• Write a script that organizes the weekly grocery shopping list by combining groceries and sorting them by store aisles.
• Have a few quick meals (such as fish and chips) in the freezer for days where I’m truly lacking time for cooking or just really badly lazy.
• ### Manage cooking with my little one

• Find recipes that don’t require a lot of cutting.
• Ask my hubby more often for help.
• Prepare food already on the weekend while my husband and the little one are busy playing.
• ### Keep the pantry full and organized

• Create a list with all pantry items (name and amount) and it’s due date.
• Create an emacs extension which will automatically search for recipes that use soon to be due pantry items.
• ### Keep it cheap

• Start searching every week for groceries that are on sale and create the meal plan accordingly.
• Write an elisp script that takes as input groceries (that are on sale that week) and as output all kind of recipes that use those groceries.
• ### Elisp code

So far I have only one little function implemented which helps me copy an ingredients list in org-mode into my grocery.org file.
An example ingredient list looks like:

``````|   2 | small | shallots                 | minced      |
|   1 |       | garlic clove             | minced      |
|   2 | tsp   | Dijon mustard            |             |
| 1/4 | cup   | balsamic vinegar         |             |
|     |       | salt and pepper to taste |             |
| 1/2 | cup   | olive oil                |             |
``````

If I have the pointer at the start of the table and call my elisp function, then it automatically puts the first three columns of my table in the kill ring. Afterwards, I just need to yank it into my grocery file and create a macro so that moving ingredient lists into my grocery list goes even faster. Below is my short unspectacular code.

``````(defun custom/save-till-end-of-table()
(interactive)
(setq cont t)
(setq startpoint (point))
(while cont
(next-line)
(if (not(char-equal ?| (char-after)))
(progn
(backward-char)
(setq cont nil))))
(org-shifttab)
(backward-char 2)
(kill-ring-save startpoint (point))
(message (string (char-after))))``````

My goal is to improve this code still so that it automatically yanks the table into a user-specified file.

## Do. Or do not. There is no try.

I love this statement from Yoda. If we just try, we don’t really put our heart into it. We demonstrate that we don’t have enough passion for the subject and are likely to give up before finishing. If you really want something, you just have to do it, no matter how hard. Unfortunately, goals are generally always hard to reach. A consequence of reaching a goal might be a change of a daily routine, of a favorite activity, and so on.

I believe we all frequently tend to try things instead of just doing them. For example, I tried to study Spanish already a few times in the past, but after just a few weeks my motivation vanished every single time. Why is that? First of all, there is no actual need for me to speak Spanish. I don’t live in a Spanish country and I don’t actually know anyone from Spain, Mexico, etc.. My main motivation was just always that I like the language and that I would like to be able to speak more than two languages. I still would like to speak more languages (Spanish and Russian in particular), but I’m just facing the facts: I don’t have time right now. There are things that are more important and also more urgent. Also, the goal: ‘Learn a new language’ is quite big. It’s not an easy task that can be done within a few weeks or even months. Since I’m not particularly good in learning languages, it would take me a few years to learn a new one. Instead, ‘I’ll master Aurebesh and will read articles in Aurebesh effortlessly’ is a way easier task and quicker to reach. I won’t try learning Aurebesh. I’m simply doing it. I’ll continue studying till I’m fluent. As soon as learning a new language becomes truly important to me, I’ll have to split this goal in smaller more manageable tasks (e.g. I’ll master numbers and the alphabet; I’ll be able to go grocery shopping in Spain without having to look up the dictionary for any of the food items on my list; …)

To be honest, I frequently have goals that I don’t fully commit to. I start something but don’t finish it. I think that’s just part of being human and I also believe that there’s nothing wrong about it as long as ‘not finishing what started’ doesn’t become a way of living. I guess that means I don’t completely agree with Yoda after all. For me the sentence is more along the lines ‘Do. Or do not. But there is always also try.’. For the most part, I don’t consider it a big fail when I don’t finish something as long as I figure out the reason and the consequences. Was I unrealistic with respect to the time-frame? Have my interests changed? Have I set my priorities incorrectly? Did I spend too much time gaming, relaxing, etc.? No matter what the reason, it’s good to know why I failed since that helps me to correct my goals and fix issues. I try not to make myself down just because I didn’t reach a goal (and yes, I know I just used the word ‘try’). For example, maybe I played too many games on the PC because I just needed relax time. I might have been over-disciplined for weeks and I then got the pay back. My lesson would then be to plan for more breaks and ‘lazy times’.

At the end, there are things I’m trying to do (like learning Spanish), but there are also things I’m just doing (like studying Aurebesh). There will be a time, when I’ll just simply stop trying and actually do study a new language, but that time has not come yet. If you tried something and failed, find out why. As soon as you’re convinced that something is very important to you, you’ll stop trying and actually do it.