OpenCores
URL https://opencores.org/ocsvn/wf3d/wf3d/trunk

Subversion Repositories wf3d

[/] [wf3d/] [trunk/] [demo_app/] [main_bear.c] - Blame information for rev 2

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 specular
//=======================================================================
2
// Project Monophony
3
//   Wire-Frame 3D Graphics Accelerator IP Core
4
//
5
// File:
6
//   main_bear.c
7
//
8
// Abstract:
9
//   3D model(Bears) rendering sample program.
10
//
11
// Author:
12
//   Kenji Ishimaru (kenji.ishimaru@prtissimo.com)
13
//
14
//======================================================================
15
//
16
// Copyright (c) 2015, Kenji Ishimaru
17
// All rights reserved.
18
//
19
// Redistribution and use in source and binary forms, with or without
20
// modification, are permitted provided that the following conditions are met:
21
//
22
//  -Redistributions of source code must retain the above copyright notice,
23
//   this list of conditions and the following disclaimer.
24
//  -Redistributions in binary form must reproduce the above copyright notice,
25
//   this list of conditions and the following disclaimer in the documentation
26
//   and/or other materials provided with the distribution.
27
//
28
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
29
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
30
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
31
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
32
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
33
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
34
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
35
// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
36
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
37
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
38
// EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39
//
40
// Revision History
41
 
42
#include <stdio.h>
43
#include <unistd.h>
44
#include <system.h>
45
#include "mp_lib.h"
46
#include "mp_hwdep.h"
47
 
48
//#define BLENDER_OBJ_TEST
49
 
50
#ifdef BLENDER_OBJ_TEST
51
#include "blender_obj.h"
52
#else
53
#include "bear.h"
54
#endif
55
 
56
void mp_loop() {
57
  static float transY = 0.0f;
58
  static int cframe = 1;
59
  static float cScale = 4.0;
60
  float pos_z_l,pos_z_r;
61
  int pos_z_l_inc,pos_z_r_inc;
62
  unsigned char col;
63
  int i;
64
  int frame  = 0;
65
  int mat_index;
66
  mpClearColor(0.5, 0, 0.4);
67
  mpViewport(640, 480);
68
  mpMatrixMode(MP_PROJECTION);
69
  mpPerspective(30.0, 4.0 / 3.0, 1, 100);
70
  mpVertexPointer(vtx_array);
71
  pos_z_l = 0.0;
72
  pos_z_r = 0.0;
73
  pos_z_l_inc = 0;
74
  pos_z_r_inc = 0;
75
  col = 0x00;
76
  while(1) {
77
    for (i=0;i<360;i++) {
78
      printf("frame %d\n",frame++);
79
      mpClear();
80
      mpMatrixMode(MP_MODELVIEW);
81
      mpLoadIdentity();
82
      mpLookAt(0, 0, 1, 0, 0, 0, 0, 1, 0);
83
      mpPushMatrix();
84
      mpTranslate(0.0, 0.0, -8+pos_z_l);
85
      mpTranslate(-1.3, 0.0, 0.0);
86
      mpRotate(i, 0, 1, 0);
87
      mpScale(2.0,2.0,2.0);
88
      //mpRenderColor(1.0,0.0,0.0);
89
      mpRenderColorU(col);
90
      mpDrawArrays(num_vtx*3);
91
      mpPopMatrix();
92
      mpTranslate(0.0, 0.0, -8+pos_z_r);
93
      mpTranslate(1.3, 0.0, 0.0);
94
      mpRotate(i, 0, 1, 0);
95
      mpScale(2.0,2.0,2.0);
96
      mpRenderColor(1.0,0.4,0.1);
97
      //mpRenderColorU(~col);
98
      mpDrawArrays(num_vtx*3);
99
      cframe++;
100
      mpSwapBuffers();
101
      // color
102
      if (col == 0xff) col = 0;
103
      else col++;
104
      // pos_z_l 0:-30
105
      if (pos_z_l_inc) {
106
        pos_z_l += 0.1;
107
        if (pos_z_l > 0.0) {
108
          pos_z_l_inc = 0;
109
        }
110
      } else {
111
        pos_z_l -= 0.1;
112
        if (pos_z_l < -30.0) {
113
          pos_z_l_inc = 1;
114
        }
115
      }
116
      // pos_z_r 0:-30
117
      if (pos_z_r_inc) {
118
        pos_z_r += 0.4;
119
        if (pos_z_r > 0.0) {
120
          pos_z_r_inc = 0;
121
        }
122
      } else {
123
        pos_z_r -= 0.4;
124
        if (pos_z_r < -30.0) {
125
          pos_z_r_inc = 1;
126
        }
127
      }
128
    }
129
  }
130
}
131
 
132
int main()
133
{
134
 
135
  printf("Hello from Nios II!\n");
136
  buffer_clear(0xcdcdcdcd,0);
137
  buffer_clear(0xdededede,1);
138
  mpInit();
139
  mp_loop();
140
  return 0;
141
}
142
 
143
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.