/* -*- coding: utf-8 -*- */ package demo1; import java.util.Random; /** * Example code for the course "Tietokonegrafiikan perusteet" 2012 * and 2013. Likely not useful for "production use". * * Exercise 1: preliminary vector, matrix, and image classes. * * @author Paavo Nieminen * */ /** A class for 4x4 square matrices. */ public class Mat4 { private static final int N_ROWS = 4; private static final int N_ELEMS = N_ROWS * N_ROWS; /* For initial experimentation.. */ private static Random generator = new Random(); /** Computes a linear index into the storage array */ private static int pos(int i, int j){ return i*N_ROWS + j; } private double value[] = null; private Mat4(double[] shallowElementArray){ this.value = shallowElementArray; } /** By default, become an array of zeros. */ public Mat4(){value = new double[N_ELEMS];} /** Sets the value of the (i, j):th element */ public void set(int i, int j, double val){ value[pos(i,j)] = val; } /** Returns the (i, j):th element */ public double at(int i, int j){ return value[pos(i,j)]; } /** Sets all elements to the same scalar value. */ public void allToConst(double val){ for(int i=0; i