/* -*- coding: utf-8 -*- */ package demo1; /** * 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 4-dimensional vectors. */ public class Vec4 { private static final int N_ROWS = 4; private double[] v = null; private Vec4(double[] shallowValues){ v = shallowValues; } /** Become (0,0,0,1), "homogeneous 3d origin", by default. */ public Vec4(){v = new double[N_ROWS]; v[3] = 1.0; } /** Representation of a 3D vector which is embedded on the "3-space * floating at w==1" */ public Vec4(double x, double y, double z){ v = new double[N_ROWS]; v[0] = x; v[1]=y; v[2]=z; v[3] = 1.0; } public Vec4(double x, double y, double z, double w) { v = new double[N_ROWS]; v[0] = x; v[1] = y; v[2] = z; v[3] = w; } /** Scalar product. (multiplies also the fourth element, which might * not be very useful with actual graphics codes; but we'll be doing * vertex scaling by matrix multiplications anyway) */ public void times(double scal){ for (int i=0; i