103 lines
2.8 KiB
C
103 lines
2.8 KiB
C
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include "ri.h"
|
|
#include "types.h"
|
|
#include "stack.h"
|
|
#include "graph_state.h"
|
|
#include "object.h"
|
|
#include "matrix.h"
|
|
#include "vars.h"
|
|
#include "engine.h"
|
|
|
|
static char RI_DEFAULT_FILNAME[] = "ri.pic";
|
|
|
|
// Graphics state functions
|
|
void GS_init(graph_state_t *pObj)
|
|
{
|
|
uint32_t i;
|
|
|
|
pObj->pAttr_stack = Stack_push(NULL, &pObj->pAttr, sizeof(attr_t));
|
|
pObj->pOpt_stack = Stack_push(NULL, &pObj->pOpt, sizeof(opt_t));
|
|
pObj->pXform_stack = Stack_push(NULL, &pObj->pXform, sizeof(xform_t));
|
|
|
|
// Initialize coordinate systems
|
|
for (i=0; i < NUM_COORD_SYSTEMS; i++)
|
|
{
|
|
IdentityMatrix(&pObj->pXform->space[i]);
|
|
}
|
|
|
|
// Init options
|
|
memset(pObj->pOpt, 0, sizeof(opt_t));
|
|
pObj->pOpt->display.name = RI_DEFAULT_FILNAME;
|
|
pObj->pOpt->display.type = RI_FILE;
|
|
pObj->pOpt->display.mode = RI_RGBA;
|
|
pObj->pOpt->format.xres = 640;
|
|
pObj->pOpt->format.yres = 480;
|
|
pObj->pOpt->format.ar_f = (RtFloat)1;
|
|
pObj->pOpt->format.ar_p = (RtFloat)1;
|
|
pObj->pOpt->crop[0] = (RtFloat)0;
|
|
pObj->pOpt->crop[1] = (RtFloat)1;
|
|
pObj->pOpt->crop[2] = (RtFloat)0;
|
|
pObj->pOpt->crop[3] = (RtFloat)1;
|
|
pObj->pOpt->screen[0] = (RtFloat)-1.33;
|
|
pObj->pOpt->screen[1] = (RtFloat)+1.33;
|
|
pObj->pOpt->screen[2] = (RtFloat)-1.00;
|
|
pObj->pOpt->screen[3] = (RtFloat)+1.00;
|
|
pObj->pOpt->projection.type = RI_PERSPECTIVE;
|
|
pObj->pOpt->projection.fov = (RtFloat)90;
|
|
pObj->pAttr->cs[0] = 1.0;
|
|
pObj->pAttr->cs[1] = 1.0;
|
|
pObj->pAttr->cs[2] = 1.0;
|
|
pObj->pAttr->ubasis = (RtPointer)RiBezierBasis;
|
|
pObj->pAttr->vbasis = (RtPointer)RiBezierBasis;
|
|
pObj->pAttr->ustep = RI_BEZIERSTEP;
|
|
pObj->pAttr->vstep = RI_BEZIERSTEP;
|
|
pObj->pAttr->nsides = 1;
|
|
}
|
|
|
|
void GS_free(graph_state_t *pObj)
|
|
{
|
|
pObj->pAttr_stack = Stack_free(pObj->pAttr_stack);
|
|
pObj->pOpt_stack = Stack_free(pObj->pOpt_stack);
|
|
pObj->pXform_stack = Stack_free(pObj->pXform_stack);
|
|
|
|
}
|
|
|
|
void GS_opt_push(graph_state_t *pObj)
|
|
{
|
|
pObj->pOpt_stack = Stack_push(pObj->pOpt_stack, (void*)&pObj->pOpt, sizeof(opt_t));
|
|
}
|
|
|
|
void GS_opt_pop(graph_state_t *pObj)
|
|
{
|
|
pObj->pOpt_stack = Stack_pop(pObj->pOpt_stack, (void*)&pObj->pOpt);
|
|
}
|
|
|
|
void GS_attr_push(graph_state_t *pObj)
|
|
{
|
|
pObj->pAttr_stack = Stack_push(pObj->pAttr_stack, (void*)&pObj->pAttr, sizeof(attr_t));
|
|
}
|
|
|
|
void GS_attr_pop(graph_state_t *pObj)
|
|
{
|
|
pObj->pAttr_stack = Stack_pop(pObj->pAttr_stack, (void*)&pObj->pAttr);
|
|
}
|
|
|
|
void GS_xform_push(graph_state_t *pObj)
|
|
{
|
|
pObj->pXform_stack = Stack_push(pObj->pXform_stack, (void*)&pObj->pXform, sizeof(xform_t));
|
|
GS_xform_set(pObj, pObj->curr_xform);
|
|
}
|
|
|
|
void GS_xform_pop(graph_state_t *pObj)
|
|
{
|
|
pObj->pXform_stack = Stack_pop(pObj->pXform_stack, (void*)&pObj->pXform);
|
|
GS_xform_set(pObj, pObj->curr_xform);
|
|
}
|
|
|
|
void GS_xform_set(graph_state_t *pObj, uint32_t id)
|
|
{
|
|
pObj->curr_xform = id;
|
|
pObj->pXform_curr = &pObj->pXform->space[id];
|
|
}
|