Monday, 23 September 2019

Programming Adventures 2 - Unity3D Translation

Programming Adventures 2 - Unity3D Translate

When moving objects using gameObject.transform.translate(x,y,z), its direction is based on the object's local transformation.

That means that a square object rotated 90 degrees right will translate +Y when translated by (10, 0, 0).

This bug happens when trying to translate objects using world space vectors.


Solution

The solution is to use gameObject.transform.SetPositionAndRotation( gameObject's position + translation direction, __); this avoids the local transformation stack!

Sunday, 22 September 2019

Programming Tricks 1 - PHP and JS/CSS

Programming Tricks 1

PHP

When creating PHP scripts, there is a funny error that if there are spaces before the first <?php tag, the session information is sent before the php script is executed.

So if you get:
 [22-Sep-2019 12:09:17 America/New_York] PHP Warning:  session_start(): Cannot start session when headers already sent in /home/esceqrkk/groundstationdatabase/main.php on line 3
 And there is no code before that main.php file, it's due to the spaces.

Javascript + CSS

A super easy way to animate and control your CSS animations is to use css transitions, css variables and jquery all in one go for example:

JQuery side:
        var currentXTranslation = 0;
        
        $(document).ready(function () {
            $("#NavigateLeftButton").hide();
            
            $("#NavigateLeftButton").click(function(evt) {
     
                currentXTranslation += 100;

                $(':root').css('--current-x-translation', currentXTranslation + "vw"); 
CSS Side:
:root {
        --main-bg-color: #141414;
        --current-x-translation: 0vw;
    }

   
    .Slide {
        margin:auto;
        
        transform: translateX(var(--current-x-translation));
        transition-property: transform;
        transition-duration: 3s;
    }
 
This results in the "Slide" element's transform to be controlled by the JQuery, and the CSS to do the updating.

Friday, 8 April 2016

Project 6: Marching cubes algorithm and metaballs.

The marching cubes algorithm is a way of creating polygons from volumes of data. The data it works on is varied such as 1 / R^2 (the one used to produce metaballs) and a noise function like perlin noise.

My implementation of marching cubes in a nutshell is initially the scene is split into a 3d grid of voxels, then at the corners and center of each voxel an isovalue is calculated (to form the isosurface).
Then using the comparison between the isovalue at each vertex with a threshold value, a table of indices which tell you which edges have been intersected and how each edge is connected to form the triangle facets is referenced.

To generate metaballs from this technique, i used the function 1 / distance^2 to calculate the isovalues at vertices.

Calculating the normal at each triangle facet was done through assuming that each point charge in the scene was a sphere, and the triangle was sitting on the surface of each sphere, individually taking the normals each time. I then took the average of these normals and divided them by the isovalue at the triangles centre. This worked because each charge contributes Q to the triangle, and since the sum of all Q's is equal to the threshold value (or near enough) this allowed me to use it like a weighted average.

--- WARNING AUDIO IN VIDEOS (sorry i forgot) ---

A cool feature of this is that the number of voxels in the grid determines how detailed the object is, here is a scene with 14608 triangles generated (normals enabled):


3416 triangles (no normals):



1384 triangles (no normals):

 

Heres one showing 2 charges close:


Saturday, 12 March 2016

University work: The Column.

This assignment for 3d graphics and simulation module involves rendering a scene from scratch using opengl and simulating physics with collisions between different shapes.

Here's what I have so far:


I still have a bunch of work to do with the portals (you can see that they disappear and reappear), the collision responses between the objects (it is kind of `glitchy` and I want to implement proper prediction and intersection calculations) and attenuation of the light sources.

I'm pretty happy with what I have so far, but with projects like these I feel like I could add a million things and never feel like it is fully completed!
 

 

Thursday, 25 February 2016

Graphics Work

A quick update on what I've been working on recently.

For one of my modules Simulations and 3D Graphics, we were set a task to learn lighting and materials. So far I have implemented a single light, using ADS and blinn-phong (again).


The camera can rotate, move forward/backward. The armadillo can be rotated on it's pedestal and the whole scene can be rotated.

Sunday, 7 February 2016

Project 5: Stanford dragon rendering



This dragon is one of the many models which the Stanford University Computer Graphics Laboratory scanned. More info http://graphics.stanford.edu/data/3Dscanrep/. I used this to practice for an upcoming module, it is made in OpenTK and uses OpenGL 4.5.
 
Work for this included:
  • Loading vertex and normal data from .OBJ.
  • Parsing material file for Blinn-Phong attributes.
  • Blinn-Phong glsl shaders.
  • Setting model/view/projection matrices.
  • Configuring camera and light positions.

OpenGL Transform Feedback