/*
 * $Id: NullObject.java,v 1.11 2000/06/15 13:55:51 yamauchi Exp $
 *     (M\pi)^2 : NummObject
 *	Copyright 1999 By YAMAUCHI Hitoshi 山内 斉 
 *	@author YAMAUCHI Hitoshi 山内 斉
 *	
 * original source object.h
 * 
 *-- 1999年7月28日(水) 本日より前田さんがこの研究に加わった．
 *-- やったね．
 * 形のない Primitive，通信終了の印などに使用する．
 */

package jp.ac.tohoku.is.archi.mpi2.obj;

import java.lang.String;
import java.lang.Double;
import java.io.Serializable;

import jp.ac.tohoku.is.archi.mpi2.util.IntVec3;
import jp.ac.tohoku.is.archi.mpi2.util.Vector3;
import jp.ac.tohoku.is.archi.mpi2.util.Encodable;
import jp.ac.tohoku.is.archi.mpi2.util.ObjectDecoder;
import jp.ac.tohoku.is.archi.mpi2.obj.Ray;
import jp.ac.tohoku.is.archi.mpi2.obj.Ray;
import jp.ac.tohoku.is.archi.mpi2.sysparam.Mpi2Enum;

/**
 * <code>NullObject<code> special primitive.
 *
 * @author 	YAMAUCHI Hitoshi (山内斉)
 */
public final class NullObject extends ObjectPrimitive
implements Mpi2Enum, Encodable
, Serializable
{
    public NullObject()
    {
	super(-2, -1, new IntVec3(-1, -1, -1));
	// this.mSpcPos 	= new IntVec3(-1, -1, -1); // illegal value
	// this.mMaterial  = null;
    }

    //----- pure virtual functios
    // 物体までの距離(if ret PlusInfty =  not hit)
    public double getDistance(Ray aRay, Vector3 hitPositionRef)
    {
	return(Double.POSITIVE_INFINITY);
    }

    /**
     * flat shading 
     */
    public Vector3 newFlatRadiosityColor(Vector3 hitPos)
    {
	throw new RuntimeException("Null object : newFlatRadiosityColor");
    }
    
    /**
     * Gouroud shading 
     */
    public Vector3 newShadedRadiosityColor(Vector3 hitPos)
    {
	throw new RuntimeException("Null object : newShadedRadiosityColor");
    }

    /** 
     * peek normal vector of hit point
     */
    public Vector3 peekNormal(Vector3 hitpos)
    {
	throw new RuntimeException("Null object : peekNormal");
    }
    
    public String toString()
    {
	return("NullObject");
    }

    public String toStringWithHead(String s)
    {
	return(s + this.toString());
    }

    public String getMgfForm(int type)
    {
	return("");
    }

    public int who()
    {
	return(OBJ_NULL);	
    }

    public boolean isAtValidSpcPos(Vector3 partmin, 
				   Vector3 subSpcSize, int subduvnum)
    {
	return(false);
    }

    /*
     * 通信用のタグを返す
     */
    public static int getTAG() 
    { 
	return(Mpi2Enum.TAG_NULL_OBJ);	
    }

    /**
     * For Encodable interface (and ObjectDecoder object).
     */
    final static int doubleSize = 1;
    public int sizeInDouble() 
    {
	return doubleSize;
    }
    public void encodeInDouble(double[] array, int offset) 
    {
	array[offset] = -100.0;	// NullObject ということがわかれば良い
	offset++;
    }
    static class NullObjectDecoder implements ObjectDecoder {
        public int sizeInDouble() {
	    return doubleSize;
	}
        public Object decodeFromDouble(double[] array, int offset) {
	    return(new NullObject());
	}
    }
    private final static ObjectDecoder odInstance = new NullObjectDecoder();
    public static ObjectDecoder getObjectDecoder() {
	return odInstance;
    }
}
