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

Subversion Repositories wf3d

[/] [wf3d/] [trunk/] [demo_app/] [main_cubes.c] - Blame information for rev 3

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_cubes.c
7
//
8
// Abstract:
9
//   3D model(Cubes) 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
float triangle[] = {
49
  // front
50
  0.25,  0.25, 0.25,  // trianmpe0
51
  -0.25,  0.25, 0.25,
52
  -0.25, -0.25, 0.25,
53
   0.25,  0.25, 0.25,  // trianmpe1
54
  -0.25, -0.25, 0.25,
55
   0.25, -0.25, 0.25,
56
  // top
57
   0.25,  0.25, 0.0,      // trianmpe0
58
  -0.25,  0.25, 0.0,
59
  -0.25,  0.25, 0.25,
60
   0.25,  0.25, 0.0,      // trianmpe1
61
  -0.25,  0.25, 0.25,
62
   0.25,  0.25, 0.25,
63
  // bottom
64
   0.25, -0.25, 0.25,  // trianmpe0
65
  -0.25, -0.25, 0.25,
66
  -0.25, -0.25, 0,
67
  0.25, -0.25, 0.25,  // trianmpe1
68
  -0.25, -0.25, 0,
69
  0.25, -0.25, 0,
70
  // left
71
  -0.25, 0.25, 0.25,  // trianmpe0
72
  -0.25, 0.25, 0,
73
  -0.25, -0.25, 0,
74
  -0.25, 0.25, 0.25,  // trianmpe1
75
  -0.25, -0.25, 0,
76
  -0.25, -0.25, 0.25,
77
  // right
78
  0.25, 0.25, 0,  // trianmpe0
79
  0.25, 0.25, 0.25,
80
  0.25, -0.25, 0.25,
81
  0.25, 0.25, 0,  // trianmpe1
82
  0.25, -0.25, 0.25,
83
  0.25, -0.25, 0,
84
  // back
85
  -0.25, 0.25, 0,  // trianmpe0
86
  0.25, 0.25, 0,
87
  0.25, -0.25, 0,
88
  -0.25, 0.25, 0,  // trianmpe1
89
  0.25, -0.25, 0,
90
  -0.25, -0.25, 0
91
};
92
 
93
void mp_loop() {
94
  int i,m,k,l;
95
  int frame  = 0;
96
  mpClearColor(0.1, 0.1, 0.1);
97
  mpViewport(640, 480);
98
  mpMatrixMode(MP_PROJECTION);
99
  mpPerspective(30.0, 4.0 / 3.0, 1, 100);
100
  mpVertexPointer(triangle);
101
  while(1) {
102
    for (i = 0; i <360; i++) {
103
      printf("frame %d\n",frame++);
104
 
105
      mpClear();
106
      mpMatrixMode(MP_MODELVIEW);
107
      mpLoadIdentity();
108
      mpLookAt(0, 0, 1, 0, 0, 0, 0, 1, 0);
109
      mpTranslate(-2, 2,-10);
110
      for (m = 0; m < 4; m++) {
111
        mpPushMatrix();
112
        for (k = 0; k < 4; k++) {
113
          mpPushMatrix();
114
          for (l = 0; l < 4; l++) {
115
            mpTranslate(1.0*l, 0,0);
116
            mpRotate((float)i, 0,0,1);
117
            mpRotate((float)i, 1,0,0);
118
            mpDrawArrays(36);
119
            mpPopMatrix();
120
            mpPushMatrix();
121
          }
122
          mpPopMatrix();
123
          mpTranslate(0, -1,0);
124
        }
125
        mpPopMatrix();
126
        mpTranslate(0, 0, -1);
127
      }
128
      mpSwapBuffers();
129
    }
130
  }
131
}
132
 
133
int main()
134
{
135
 
136
  printf("Hello from Nios II!\n");
137
  buffer_clear(0x00000000,0);
138
  buffer_clear(0x00000000,1);
139
  mpInit();
140
  mp_loop();
141
  return 0;
142
}
143
 
144
 

powered by: WebSVN 2.1.0

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