Commit 8b25700a authored by Ken Martin's avatar Ken Martin

Initial revision

parents
.git* export-ignore
/*=========================================================================
Program: OSCAR
Module: Actor.cc
Language: C++
Date: $Date$
Version: $Revision$
Description:
---------------------------------------------------------------------------
This file is part of the vis library
- Ken Martin
=========================================================================*/
#include <stdlib.h>
#include <math.h>
#include "Actor.h"
#include <kgl.h>
Actor::Actor()
{
this->Origin[0] = 0.0;
this->Origin[1] = 0.0;
this->Origin[2] = 0.0;
this->Position[0] = 0.0;
this->Position[1] = 0.0;
this->Position[2] = 0.0;
this->Orientation[0] = 0.0;
this->Orientation[1] = 0.0;
this->Orientation[2] = 0.0;
this->Scale[0] = 1.0;
this->Scale[1] = 1.0;
this->Scale[2] = 1.0;
this->Visibility = 1;
}
int Actor::GetVisibility()
{
return this->Visibility;
}
drawcyl()
{
double dy = .2;
double theta, dtheta = 2*M_PI/20;
double x, y, z;
float n[3], v[3];
int i, j;
for (i = 0, y = -1; i < 10; i++, y += dy) {
kgl_StartPrimitive(KGL_TMESH);
for (j = 0, theta = 0; j <= 20; j++, theta += dtheta) {
if (j == 20) theta = 0;
x = cos(theta);
z = sin(theta);
n[0] = x; n[1] = 0; n[2] = z;
kgl_SetNormal3(n);
v[0] = x; v[1] = y; v[2] = z;
kgl_SetVertex3(v);
v[1] = y + dy;
kgl_SetVertex3(v);
}
kgl_EndPrimitive();
}
return 0;
}
void Actor::Render(Renderer *ren)
{
/* render my property */
this->MyProperty->Render(ren);
/* send a render to the modeller */
/* some test junk */
drawcyl();
}
void Actor::GetCompositeMatrix(float mat[4][4])
{
mat[0][0] = 1; mat[0][1] = 0; mat[0][2] = 0; mat[0][3] = 0;
mat[1][0] = 0; mat[1][1] = 1; mat[1][2] = 0; mat[1][3] = 0;
mat[2][0] = 0; mat[2][1] = 0; mat[2][2] = 1; mat[2][3] = 0;
mat[3][0] = 0; mat[3][1] = 0; mat[3][2] = 0; mat[3][3] = 1;
}
ActorCollection::ActorCollection()
{
this->NumberOfItems = 0;
this->Top = NULL;
this->Bottom = NULL;
}
void ActorCollection::AddMember(Actor *actor)
{
ActorListElement *elem;
elem = new ActorListElement;
if (!this->Top)
{
this->Top = elem;
}
else
{
this->Bottom->Next = elem;
}
this->Bottom = elem;
elem->Actor = actor;
elem->Next = NULL;
this->NumberOfItems++;
}
int ActorCollection::GetNumberOfMembers()
{
return this->NumberOfItems;
}
Actor *ActorCollection::GetMember(int num)
{
int i;
ActorListElement *elem;
if (num > this->NumberOfItems)
{
fprintf(stderr,"Actor.cc Requesting illegal index\n");
return this->Top->Actor;
}
elem = this->Top;
for (i = 1; i < num; i++)
{
elem = elem->Next;
}
return (elem->Actor);
}
/*=========================================================================
Program: OSCAR
Module: Camera.cc
Language: C++
Date: $Date$
Version: $Revision$
Description:
---------------------------------------------------------------------------
This file is part of the vis library
- Ken Martin
=========================================================================*/
#include "Camera.h"
Camera::Camera()
{
this->FocalPoint[0] = 0.0;
this->FocalPoint[1] = 0.0;
this->FocalPoint[2] = 0.0;
this->Position[0] = 0.0;
this->Position[1] = 0.0;
this->Position[2] = 1.0;
this->ViewUp[0] = 0.0;
this->ViewUp[1] = 1.0;
this->ViewUp[2] = 0.0;
this->ViewAngle = 30.0;
this->ClippingRange[0] = 0.01;
this->ClippingRange[1] = 1000.01;
}
void Camera::SetPosition(float X, float Y, float Z)
{
this->Position[0] = X;
this->Position[1] = Y;
this->Position[2] = Z;
}
void Camera::SetPosition(float a[3])
{
this->Position[0] = a[0];
this->Position[1] = a[1];
this->Position[2] = a[2];
}
float *Camera::GetPosition()
{
return (this->Position);
}
void Camera::SetFocalPoint(float X, float Y, float Z)
{
this->FocalPoint[0] = X;
this->FocalPoint[1] = Y;
this->FocalPoint[2] = Z;
}
void Camera::SetFocalPoint(float a[3])
{
this->FocalPoint[0] = a[0];
this->FocalPoint[1] = a[1];
this->FocalPoint[2] = a[2];
}
float *Camera::GetFocalPoint()
{
return (this->FocalPoint);
}
void Camera::SetViewUp(float X, float Y, float Z)
{
this->ViewUp[0] = X;
this->ViewUp[1] = Y;
this->ViewUp[2] = Z;
}
void Camera::SetViewUp(float a[3])
{
this->ViewUp[0] = a[0];
this->ViewUp[1] = a[1];
this->ViewUp[2] = a[2];
}
float *Camera::GetViewUp()
{
return (this->ViewUp);
}
/*=========================================================================
Program: OSCAR
Module: Light.cc
Language: C++
Date: $Date$
Version: $Revision$
Description:
---------------------------------------------------------------------------
This file is part of the vis library
- Ken Martin
=========================================================================*/
#include <stdlib.h>
#include "Light.h"
Light::Light()
{
this->FocalPoint[0] = 0.0;
this->FocalPoint[1] = 0.0;
this->FocalPoint[2] = 0.0;
this->Position[0] = 0.0;
this->Position[1] = 0.0;
this->Position[2] = 1.0;
this->Color[0] = 1.0;
this->Color[1] = 1.0;
this->Color[2] = 1.0;
this->OnStatus = 1;
this->Intensity = 1.0;
}
void Light::SetPosition(float X, float Y, float Z)
{
this->Position[0] = X;
this->Position[1] = Y;
this->Position[2] = Z;
}
void Light::SetPosition(float a[3])
{
this->Position[0] = a[0];
this->Position[1] = a[1];
this->Position[2] = a[2];
}
float *Light::GetPosition()
{
return (this->Position);
}
void Light::SetFocalPoint(float X, float Y, float Z)
{
this->FocalPoint[0] = X;
this->FocalPoint[1] = Y;
this->FocalPoint[2] = Z;
}
void Light::SetFocalPoint(float a[3])
{
this->FocalPoint[0] = a[0];
this->FocalPoint[1] = a[1];
this->FocalPoint[2] = a[2];
}
float *Light::GetFocalPoint()
{
return (this->FocalPoint);
}
int Light::GetStatus()
{
return this->OnStatus;
}
LightCollection::LightCollection()
{
this->NumberOfItems = 0;
this->Top = NULL;
this->Bottom = NULL;
}
void LightCollection::AddMember(Light *light)
{
LightListElement *elem;
elem = new LightListElement;
if (!this->Top)
{
this->Top = elem;
}
else
{
this->Bottom->Next = elem;
}
this->Bottom = elem;
elem->Light = light;
elem->Next = NULL;
this->NumberOfItems++;
}
int LightCollection::GetNumberOfMembers()
{
return this->NumberOfItems;
}
Light *LightCollection::GetMember(int num)
{
int i;
LightListElement *elem;
if (num > this->NumberOfItems)
{
fprintf(stderr,"Light.cc Requesting illegal index\n");
return this->Top->Light;
}
elem = this->Top;
for (i = 1; i < num; i++)
{
elem = elem->Next;
}
return (elem->Light);
}
/*=========================================================================
Program: OSCAR
Module: Property.cc
Language: C++
Date: $Date$
Version: $Revision$
Description:
---------------------------------------------------------------------------
This file is part of the vis library
- Ken Martin
=========================================================================*/
#include <stdlib.h>
#include "Property.h"
Property::Property()
{
this->Color[0] = 1;
this->Color[1] = 1;
this->Color[2] = 1;
this->AmbientColor[0] = 1;
this->AmbientColor[1] = 1;
this->AmbientColor[2] = 1;
this->DiffuseColor[0] = 1;
this->DiffuseColor[1] = 1;
this->DiffuseColor[2] = 1;
this->SpecularColor[0] = 1;
this->SpecularColor[1] = 1;
this->SpecularColor[2] = 1;
this->EdgeColor[0] = 1;
this->EdgeColor[1] = 1;
this->EdgeColor[2] = 1;
this->Ambient = 0.0;
this->Diffuse = 1.0;
this->Specular = 0.0;
this->SpecularPower = 1.0;
this->Transparency = 1.0;
this->Interpolation = 1; /* gouraud */
this->Representation = 2; /* solid */
this->EdgeVisibility = 0;
this->Backface = 0;
this->Subdivide = 0;
}
void Property::SetFlat (void)
{
this->Interpolation= FLAT;
}
void Property::SetGouraud (void)
{
this->Interpolation = GOURAUD;
}
void Property::SetPhong (void)
{
this->Interpolation = PHONG;
}
void Property::SetPoints (void)
{
this->Interpolation = POINTS;
}
void Property::SetWireframe (void)
{
this->Representation = WIREFRAME;
}
void Property::SetSurface (void)
{
this->Representation = SURFACE;
}
/* this is a standard vector set method except that it sets the */
/* ambient diffuse and specular colors as well */
void Property::SetColor(float R,float G,float B)
{
/* store the coordinates */
this->Color[0] = R;
this->AmbientColor[0] = R;
this->DiffuseColor[0] = R;
this->SpecularColor[0] = R;
this->Color[1] = G;
this->AmbientColor[1] = G;
this->DiffuseColor[1] = G;
this->SpecularColor[1] = G;
this->Color[2] = B;
this->AmbientColor[2] = B;
this->DiffuseColor[2] = B;
this->SpecularColor[2] = B;
}
float Property::GetTransparency (void)
{
return this->Transparency;
}
int Property::GetRepresentation (void)
{
return this->Representation;
}
int Property::GetInterpolation (void)
{
return this->Interpolation;
}
/*=========================================================================
Program: OSCAR
Module: Renderer.cc
Language: C++
Date: $Date$
Version: $Revision$
Description:
---------------------------------------------------------------------------
This file is part of the vis library
- Ken Martin
=========================================================================*/
#include <stdlib.h>
#include <string.h>
#include "Renderer.h"
Renderer::Renderer()
{
this->ActiveCamera = NULL;
this->Ambient[0] = 1;
this->Ambient[1] = 1;
this->Ambient[2] = 1;
this->Background[0] = 0;
this->Background[1] = 0;
this->Background[2] = 0;
this->BackLight = 1;
strcpy(this->name,"oscar");
}
void Renderer::SetBackground(float R, float G, float B)
{
this->Background[0] = R;
this->Background[1] = G;
this->Background[2] = B;
}
void Renderer::SetActiveCamera(Camera *cam)
{
this->ActiveCamera = cam;
}
void Renderer::AddLights(Light *light)
{
this->Lights.AddMember(light);
}
void Renderer::AddActors(Actor *actor)
{
this->Actors.AddMember(actor);
}
void Renderer::GetBackground(float *result)
{
result[0] = this->Background[0];
result[1] = this->Background[1];
result[2] = this->Background[2];
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment