-
Notifications
You must be signed in to change notification settings - Fork 0
/
models_cubicmap.c
240 lines (210 loc) · 7 KB
/
models_cubicmap.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
/*******************************************************************************************
*
* raylib [models] example - Cubicmap loading and drawing
*
* This example has been created using raylib 1.8 (www.raylib.com)
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
*
* Copyright (c) 2015 Ramon Santamaria (@raysan5)
* Copyright (c) 2020 Antonio Jose Ramos Marquez (@psxdev) adapt sample to liborbis
********************************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <kernel.h>
#include <systemservice.h>
#include <orbis2d.h>
#include <orbisPad.h>
#include <orbisKeyboard.h>
#include <orbisAudio.h>
#include <ps4link.h>
#include <debugnet.h>
#include <orbisNfs.h>
#include <orbisGl2.h>
#include <unistd.h>
#include <stdarg.h>
OrbisPadConfig *confPad;
bool flag=true;
typedef struct OrbisGlobalConf
{
Orbis2dConfig *conf;
OrbisPadConfig *confPad;
OrbisAudioConfig *confAudio;
OrbisKeyboardConfig *confKeyboard;
ps4LinkConfiguration *confLink;
int orbisLinkFlag;
debugNetConfiguration *confDebug;
OrbisNfsConfig *confNfs;
}OrbisGlobalConf;
OrbisGlobalConf *myConf;
void updateController()
{
int ret;
unsigned int buttons=0;
ret=orbisPadUpdate();
if(ret==0)
{
if(orbisPadGetButtonPressed(ORBISPAD_L2|ORBISPAD_R2) || orbisPadGetButtonHold(ORBISPAD_L2|ORBISPAD_R2))
{
debugNetPrintf(DEBUG,"Combo L2R2 pressed\n");
buttons=orbisPadGetCurrentButtonsPressed();
buttons&= ~(ORBISPAD_L2|ORBISPAD_R2);
orbisPadSetCurrentButtonsPressed(buttons);
}
if(orbisPadGetButtonPressed(ORBISPAD_L1|ORBISPAD_R1) )
{
debugNetPrintf(DEBUG,"Combo L1R1 pressed\n");
buttons=orbisPadGetCurrentButtonsPressed();
buttons&= ~(ORBISPAD_L1|ORBISPAD_R1);
orbisPadSetCurrentButtonsPressed(buttons);
}
if(orbisPadGetButtonPressed(ORBISPAD_L1|ORBISPAD_R2) || orbisPadGetButtonHold(ORBISPAD_L1|ORBISPAD_R2))
{
debugNetPrintf(DEBUG,"Combo L1R2 pressed\n");
buttons=orbisPadGetCurrentButtonsPressed();
buttons&= ~(ORBISPAD_L1|ORBISPAD_R2);
orbisPadSetCurrentButtonsPressed(buttons);
}
if(orbisPadGetButtonPressed(ORBISPAD_L2|ORBISPAD_R1) || orbisPadGetButtonHold(ORBISPAD_L2|ORBISPAD_R1) )
{
debugNetPrintf(DEBUG,"Combo L2R1 pressed\n");
buttons=orbisPadGetCurrentButtonsPressed();
buttons&= ~(ORBISPAD_L2|ORBISPAD_R1);
orbisPadSetCurrentButtonsPressed(buttons);
}
if(orbisPadGetButtonPressed(ORBISPAD_UP) || orbisPadGetButtonHold(ORBISPAD_UP))
{
debugNetPrintf(DEBUG,"Up pressed\n");
}
if(orbisPadGetButtonPressed(ORBISPAD_DOWN) || orbisPadGetButtonHold(ORBISPAD_DOWN))
{
debugNetPrintf(DEBUG,"Down pressed\n");
}
if(orbisPadGetButtonPressed(ORBISPAD_RIGHT) || orbisPadGetButtonHold(ORBISPAD_RIGHT))
{
debugNetPrintf(DEBUG,"Right pressed\n");
}
if(orbisPadGetButtonPressed(ORBISPAD_LEFT) || orbisPadGetButtonHold(ORBISPAD_LEFT))
{
debugNetPrintf(DEBUG,"Left pressed\n");
}
if(orbisPadGetButtonPressed(ORBISPAD_TRIANGLE))
{
debugNetPrintf(DEBUG,"Triangle pressed exit\n");
flag=0;
}
if(orbisPadGetButtonPressed(ORBISPAD_CIRCLE))
{
debugNetPrintf(DEBUG,"Circle pressed\n");
}
if(orbisPadGetButtonPressed(ORBISPAD_CROSS))
{
debugNetPrintf(DEBUG,"Cross pressed\n");
}
if(orbisPadGetButtonPressed(ORBISPAD_SQUARE))
{
debugNetPrintf(DEBUG,"Square pressed\n");
}
if(orbisPadGetButtonPressed(ORBISPAD_L1))
{
debugNetPrintf(DEBUG,"L1 pressed\n");
}
if(orbisPadGetButtonPressed(ORBISPAD_L2))
{
debugNetPrintf(DEBUG,"L2 pressed\n");
}
if(orbisPadGetButtonPressed(ORBISPAD_R1))
{
debugNetPrintf(DEBUG,"R1 pressed\n");
}
if(orbisPadGetButtonPressed(ORBISPAD_R2))
{
debugNetPrintf(DEBUG,"R2 pressed\n");
}
}
}
void finishApp()
{
//orbisAudioFinish();
//orbisKeyboardFinish();
//orbisGlFinish();
orbisPadFinish();
orbisNfsFinish();
//ps4LinkFinish();
}
bool initApp()
{
int ret;
//orbisNfsInit(NFSEXPORT);
//orbisFileInit();
sceSystemServiceHideSplashScreen();
ret=orbisPadInitWithConf(myConf->confPad);
if(ret)
{
confPad=orbisPadGetConf();
}
else
{
return false;
}
return true;
}
int main(int argc, char *argv[])
{
uintptr_t intptr=0;
sscanf(argv[1],"%p",&intptr);
myConf=(OrbisGlobalConf *)intptr;
debugNetInitWithConf(myConf->confDebug);
orbisNfsInitWithConf(myConf->confNfs);
debugNetPrintf(INFO,"[ORBISGL] raylib sample for Playstation 4 Retail fucking yeah!!!\n");
sleep(1);
const int screenWidth = ATTR_ORBISGL_WIDTH;
const int screenHeight = ATTR_ORBISGL_HEIGHT;
//init liborbis libraries
flag=initApp();
if(flag)
{
//wrapper third value is ignored
InitWindow(screenWidth, screenHeight, "raylib [models] example - cubesmap loading and drawing");
}
// Define the camera to look into our 3d world
Camera3D camera = { { 16.0f, 14.0f, 16.0f }, { 0.0f, 0.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }, 45.0f, 0 };
Image image = LoadImage("resources/cubicmap.png"); // Load cubicmap image (RAM)
Texture2D cubicmap = LoadTextureFromImage(image); // Convert image to texture to display (VRAM)
Mesh mesh = GenMeshCubicmap(image, (Vector3){ 1.0f, 1.0f, 1.0f });
Model model = LoadModelFromMesh(mesh);
// NOTE: By default each cube is mapped to one part of texture atlas
Texture2D texture = LoadTexture("resources/cubicmap_atlas.png"); // Load map texture
model.materials[0].maps[MAP_DIFFUSE].texture = texture; // Set map diffuse texture
Vector3 mapPosition = { -16.0f, 0.0f, -8.0f }; // Set model position
UnloadImage(image); // Unload cubesmap image from RAM, already uploaded to VRAM
SetCameraMode(camera, CAMERA_ORBITAL); // Set an orbital camera mode
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
//--------------------------------------------------------------------------------------
while(flag)
{
updateController();
// Update
//----------------------------------------------------------------------------------
UpdateCamera(&camera); // Update camera
//----------------------------------------------------------------------------------
// Draw
//----------------------------------------------------------------------------------
BeginDrawing();
ClearBackground(RAYWHITE);
BeginMode3D(camera);
DrawModel(model, mapPosition, 1.0f, WHITE);
EndMode3D();
DrawTextureEx(cubicmap, (Vector2){ screenWidth - cubicmap.width*4 - 20, 20 }, 0.0f, 4.0f, WHITE);
DrawRectangleLines(screenWidth - cubicmap.width*4 - 20, 20, cubicmap.width*4, cubicmap.height*4, GREEN);
DrawText("cubicmap image used to", screenWidth - cubicmap.width*4-18, 90, 10, GRAY);
DrawText("generate map 3d model", screenWidth - cubicmap.width*4-18, 104, 10, GRAY);
DrawFPS(10, 10);
EndDrawing();
//----------------------------------------------------------------------------------
}
CloseWindow();
finishApp();
sleep(3);
exit(EXIT_SUCCESS);
}