repo_name
stringlengths 6
97
| path
stringlengths 3
341
| text
stringlengths 8
1.02M
|
---|---|---|
twostraws/Markdown | Sources/discount/discount.h | <filename>Sources/discount/discount.h
#include <mkdio.h>
|
chemabc/ofx2dPlot | src/ofx2dPlot.h | #pragma once
#include "ofMain.h"
#include <utility>
#define ETC_2DPLOT_MAX_WIDTH 1024
#define ETC_2DPLOT_MAX_HEIGHT 768
class ofx2dPlot {
public:
ofx2dPlot(int x, int y, int w = ETC_2DPLOT_MAX_WIDTH, int h=ETC_2DPLOT_MAX_HEIGHT,
int xData = 0, int yData = 0, int wData = ETC_2DPLOT_MAX_WIDTH, int hData = ETC_2DPLOT_MAX_HEIGHT,
string title = "",string unitsX = "", string unitsY = "", int skipUnits = 2,
int xNumDivisions = 10,
float yMin = 0.0, float yMax = 1.0, int yNumDivisions = 10);
~ofx2dPlot();
void setup();
void update();
void draw();
void setDebug(bool b);
bool getDebug();
/**************************
META DATA
**************************/
void setTitle(string s);
void setTitlePos(int x, int y);
void setUnitsName(string sX, string sY);
/**************************
STYLE
**************************/
void setColorTitle(ofColor c);
void setColorMetaData(ofColor c);
void setColorData(ofColor c);
void setColorGrid(ofColor c);
void setColorFrame(ofColor c);
void setFont(string sFont, int iSize);
void setFont2(string sFont, int iSize);
/**************************
FRAME & GRID
**************************/
void setGridSkipUnits(int skipX=1, int skipY=1);
void setOffset(int xD = 0, int yD = 0);
void setZoom(float fx = 1.0, float fy = 1.0);
void setNumDivisions(int xNumDiv = 10, int yNumDiv = 10);
void setShowAxisValues(bool showAxisValuesX= true, bool showAxisValuesY = true);
/**************************
VALUES
**************************/
// void addValueXY(ofPoint ptVal);
// void addValueXY(float x, float y);
void addValueXY(string x, float y);
void setFixedMinAndMaxYGridValues(bool fixedMin=false, bool fixedMax= false);
void setValueLimits(float downLimit, float upLimit);
void setUseValueLimits(bool b);
private:
bool b_debug;
/**************************
META DATA
**************************/
string s_title;
ofPoint pt_titlePos;
string s_unitsX, s_unitsY;
/**************************
STYLE
**************************/
//ofTrueType font;
ofColor col_title, col_metaData, col_data, col_axis, col_grid, col_frame;
string s_font;
int i_fontSize;
ofTrueTypeFont font;
int i_fontSize2;
string s_font2;
ofTrueTypeFont font2;
/**************************
FRAME & GRID
**************************/
int i_x, i_y, i_w, i_h;
int i_xData, i_yData, i_wData, i_hData;
//This values work inside the main frame
float f_zoomX, f_zoomY;
bool b_newGrid;
int i_pixStepX, i_pixStepY;
int i_xNumDivisions, i_yNumDivisions;
int i_skipUnitsX, i_skipUnitsY;
bool b_showAxisValuesX, b_showAxisValuesY;
ofVboMesh mesh_grid;
vector <string> vec_xValues;
vector <string> vec_yValues;
void setupGrid();
void updateGrid();
void drawGrid();
/**************************
VALUES
**************************/
float f_yMin, f_yMax, f_yStep;
bool b_fixedMinGridY, b_fixedMaxGridY;
float f_yUpLimit, f_yDownLimit;
bool b_useLimits;
/**************************
LINE AND SHAPES
**************************/
void setupValues();
void updateValues();
void drawValues();
bool b_newValue;
//deque <ofPoint> dq_values;
deque <string> dq_valuesX;
deque <float> dq_valuesY;
ofPolyline poly_values;
};
|
SOFTowaha/astroCV | galaxy_detection/data/darknet/examples/attention.c | <gh_stars>10-100
#include "darknet.h"
#include <sys/time.h>
#include <assert.h>
void train_attention(char *datacfg, char *cfgfile, char *weightfile, char *cfgfile2, char *weightfile2, int *gpus, int ngpus, int clear)
{
int i;
float avg_loss = -1;
char *base = basecfg(cfgfile);
printf("%s\n", base);
printf("%d\n", ngpus);
network **attnets = calloc(ngpus, sizeof(network*));
network **clsnets = calloc(ngpus, sizeof(network*));
srand(time(0));
int seed = rand();
for(i = 0; i < ngpus; ++i){
srand(seed);
#ifdef GPU
cuda_set_device(gpus[i]);
#endif
attnets[i] = load_network(cfgfile, weightfile, clear);
attnets[i]->learning_rate *= ngpus;
clsnets[i] = load_network(cfgfile2, weightfile2, clear);
clsnets[i]->learning_rate *= ngpus;
}
srand(time(0));
network *net = attnets[0];
//network *clsnet = clsnets[0];
int imgs = net->batch * net->subdivisions * ngpus;
printf("Learning Rate: %g, Momentum: %g, Decay: %g\n", net->learning_rate, net->momentum, net->decay);
list *options = read_data_cfg(datacfg);
char *backup_directory = option_find_str(options, "backup", "/backup/");
char *label_list = option_find_str(options, "labels", "data/labels.list");
char *train_list = option_find_str(options, "train", "data/train.list");
int classes = option_find_int(options, "classes", 2);
char **labels = get_labels(label_list);
list *plist = get_paths(train_list);
char **paths = (char **)list_to_array(plist);
printf("%d\n", plist->size);
int N = plist->size;
double time;
load_args args = {0};
args.w = 4*net->w;
args.h = 4*net->h;
args.size = 4*net->w;
args.threads = 32;
args.hierarchy = net->hierarchy;
args.min = net->min_ratio*net->w;
args.max = net->max_ratio*net->w;
args.angle = net->angle;
args.aspect = net->aspect;
args.exposure = net->exposure;
args.saturation = net->saturation;
args.hue = net->hue;
args.paths = paths;
args.classes = classes;
args.n = imgs;
args.m = N;
args.labels = labels;
args.type = CLASSIFICATION_DATA;
data train;
data buffer;
pthread_t load_thread;
args.d = &buffer;
load_thread = load_data(args);
int epoch = (*net->seen)/N;
while(get_current_batch(net) < net->max_batches || net->max_batches == 0){
time = what_time_is_it_now();
pthread_join(load_thread, 0);
train = buffer;
load_thread = load_data(args);
data resized = resize_data(train, net->w, net->h);
printf("Loaded: %lf seconds\n", what_time_is_it_now()-time);
time = what_time_is_it_now();
float loss = 0;
#ifdef GPU
if(ngpus == 1){
loss = train_network(net, train);
} else {
loss = train_networks(attnets, ngpus, train, 4);
}
#else
loss = train_network(net, train);
#endif
free_data(resized);
if(avg_loss == -1) avg_loss = loss;
avg_loss = avg_loss*.9 + loss*.1;
printf("%ld, %.3f: %f, %f avg, %f rate, %lf seconds, %ld images\n", get_current_batch(net), (float)(*net->seen)/N, loss, avg_loss, get_current_rate(net), what_time_is_it_now()-time, *net->seen);
free_data(train);
if(*net->seen/N > epoch){
epoch = *net->seen/N;
char buff[256];
sprintf(buff, "%s/%s_%d.weights",backup_directory,base, epoch);
save_weights(net, buff);
}
if(get_current_batch(net)%1000 == 0){
char buff[256];
sprintf(buff, "%s/%s.backup",backup_directory,base);
save_weights(net, buff);
}
}
char buff[256];
sprintf(buff, "%s/%s.weights", backup_directory, base);
save_weights(net, buff);
pthread_join(load_thread, 0);
free_network(net);
free_ptrs((void**)labels, classes);
free_ptrs((void**)paths, plist->size);
free_list(plist);
free(base);
}
void validate_attention_single(char *datacfg, char *filename, char *weightfile)
{
int i, j;
network *net = load_network(filename, weightfile, 0);
set_batch_network(net, 1);
srand(time(0));
list *options = read_data_cfg(datacfg);
char *label_list = option_find_str(options, "labels", "data/labels.list");
char *leaf_list = option_find_str(options, "leaves", 0);
if(leaf_list) change_leaves(net->hierarchy, leaf_list);
char *valid_list = option_find_str(options, "valid", "data/train.list");
int classes = option_find_int(options, "classes", 2);
int topk = option_find_int(options, "top", 1);
char **labels = get_labels(label_list);
list *plist = get_paths(valid_list);
char **paths = (char **)list_to_array(plist);
int m = plist->size;
free_list(plist);
float avg_acc = 0;
float avg_topk = 0;
int *indexes = calloc(topk, sizeof(int));
for(i = 0; i < m; ++i){
int class = -1;
char *path = paths[i];
for(j = 0; j < classes; ++j){
if(strstr(path, labels[j])){
class = j;
break;
}
}
image im = load_image_color(paths[i], 0, 0);
image resized = resize_min(im, net->w);
image crop = crop_image(resized, (resized.w - net->w)/2, (resized.h - net->h)/2, net->w, net->h);
//show_image(im, "orig");
//show_image(crop, "cropped");
//cvWaitKey(0);
float *pred = network_predict(net, crop.data);
if(net->hierarchy) hierarchy_predictions(pred, net->outputs, net->hierarchy, 1, 1);
if(resized.data != im.data) free_image(resized);
free_image(im);
free_image(crop);
top_k(pred, classes, topk, indexes);
if(indexes[0] == class) avg_acc += 1;
for(j = 0; j < topk; ++j){
if(indexes[j] == class) avg_topk += 1;
}
printf("%d: top 1: %f, top %d: %f\n", i, avg_acc/(i+1), topk, avg_topk/(i+1));
}
}
void validate_attention_multi(char *datacfg, char *filename, char *weightfile)
{
int i, j;
network *net = load_network(filename, weightfile, 0);
set_batch_network(net, 1);
srand(time(0));
list *options = read_data_cfg(datacfg);
char *label_list = option_find_str(options, "labels", "data/labels.list");
char *valid_list = option_find_str(options, "valid", "data/train.list");
int classes = option_find_int(options, "classes", 2);
int topk = option_find_int(options, "top", 1);
char **labels = get_labels(label_list);
list *plist = get_paths(valid_list);
int scales[] = {224, 288, 320, 352, 384};
int nscales = sizeof(scales)/sizeof(scales[0]);
char **paths = (char **)list_to_array(plist);
int m = plist->size;
free_list(plist);
float avg_acc = 0;
float avg_topk = 0;
int *indexes = calloc(topk, sizeof(int));
for(i = 0; i < m; ++i){
int class = -1;
char *path = paths[i];
for(j = 0; j < classes; ++j){
if(strstr(path, labels[j])){
class = j;
break;
}
}
float *pred = calloc(classes, sizeof(float));
image im = load_image_color(paths[i], 0, 0);
for(j = 0; j < nscales; ++j){
image r = resize_min(im, scales[j]);
resize_network(net, r.w, r.h);
float *p = network_predict(net, r.data);
if(net->hierarchy) hierarchy_predictions(p, net->outputs, net->hierarchy, 1 , 1);
axpy_cpu(classes, 1, p, 1, pred, 1);
flip_image(r);
p = network_predict(net, r.data);
axpy_cpu(classes, 1, p, 1, pred, 1);
if(r.data != im.data) free_image(r);
}
free_image(im);
top_k(pred, classes, topk, indexes);
free(pred);
if(indexes[0] == class) avg_acc += 1;
for(j = 0; j < topk; ++j){
if(indexes[j] == class) avg_topk += 1;
}
printf("%d: top 1: %f, top %d: %f\n", i, avg_acc/(i+1), topk, avg_topk/(i+1));
}
}
void predict_attention(char *datacfg, char *cfgfile, char *weightfile, char *filename, int top)
{
network *net = load_network(cfgfile, weightfile, 0);
set_batch_network(net, 1);
srand(2222222);
list *options = read_data_cfg(datacfg);
char *name_list = option_find_str(options, "names", 0);
if(!name_list) name_list = option_find_str(options, "labels", "data/labels.list");
if(top == 0) top = option_find_int(options, "top", 1);
int i = 0;
char **names = get_labels(name_list);
clock_t time;
int *indexes = calloc(top, sizeof(int));
char buff[256];
char *input = buff;
while(1){
if(filename){
strncpy(input, filename, 256);
}else{
printf("Enter Image Path: ");
fflush(stdout);
input = fgets(input, 256, stdin);
if(!input) return;
strtok(input, "\n");
}
image im = load_image_color(input, 0, 0);
image r = letterbox_image(im, net->w, net->h);
//resize_network(&net, r.w, r.h);
//printf("%d %d\n", r.w, r.h);
float *X = r.data;
time=clock();
float *predictions = network_predict(net, X);
if(net->hierarchy) hierarchy_predictions(predictions, net->outputs, net->hierarchy, 1, 1);
top_k(predictions, net->outputs, top, indexes);
fprintf(stderr, "%s: Predicted in %f seconds.\n", input, sec(clock()-time));
for(i = 0; i < top; ++i){
int index = indexes[i];
//if(net->hierarchy) printf("%d, %s: %f, parent: %s \n",index, names[index], predictions[index], (net->hierarchy->parent[index] >= 0) ? names[net->hierarchy->parent[index]] : "Root");
//else printf("%s: %f\n",names[index], predictions[index]);
printf("%5.2f%%: %s\n", predictions[index]*100, names[index]);
}
if(r.data != im.data) free_image(r);
free_image(im);
if (filename) break;
}
}
void run_attention(int argc, char **argv)
{
if(argc < 4){
fprintf(stderr, "usage: %s %s [train/test/valid] [cfg] [weights (optional)]\n", argv[0], argv[1]);
return;
}
char *gpu_list = find_char_arg(argc, argv, "-gpus", 0);
int ngpus;
int *gpus = read_intlist(gpu_list, &ngpus, gpu_index);
int top = find_int_arg(argc, argv, "-t", 0);
int clear = find_arg(argc, argv, "-clear");
char *data = argv[3];
char *cfg = argv[4];
char *weights = (argc > 5) ? argv[5] : 0;
char *filename = (argc > 6) ? argv[6]: 0;
char *layer_s = (argc > 7) ? argv[7]: 0;
if(0==strcmp(argv[2], "predict")) predict_attention(data, cfg, weights, filename, top);
else if(0==strcmp(argv[2], "train")) train_attention(data, cfg, weights, filename, layer_s, gpus, ngpus, clear);
else if(0==strcmp(argv[2], "valid")) validate_attention_single(data, cfg, weights);
else if(0==strcmp(argv[2], "validmulti")) validate_attention_multi(data, cfg, weights);
}
|
dias-wagner/tableau | formula.h | <gh_stars>0
/*
* formula.h
*
* Class declarations for formulas.
*
*/
#ifndef __FORMULA_H__
#define __FORMULA_H__
#include <string>
#include <vector>
#include <map>
#include <set>
using namespace std;
// Encapsulates a formula.
class Formula
{
public:
// Types of operators.
enum opType {AND, ANDN, OR, ORN, IMPLIES, NOT, ATOM};
// Constructor for opType = ANDN or ORN.
Formula(opType t, vector<Formula *>& vfml);
// Constructor for opType = AND, OR or IMPLIES.
Formula(opType t, Formula *l, Formula *r);
// Constructor for opType = NOT.
Formula(opType t, Formula *r);
// Constructor for opType = ATOM.
Formula(const string& a);
// Copy constructor.
Formula(const Formula& rhs);
// Destructor. Destroys all subformulas.
~Formula();
// Returns a string representation of the formula.
string toString() const;
// Returns the size of the formula (atom ocurrences + operator ocurrences)
unsigned int size(bool count_atoms = true) const;
// Returns the value of the formula according to a valuation. Returns:
// -1: undefined
// 0: false
// 1: true
int value(map<string, int>& valuation) const;
// Returns the polarity of the specified atom in the formula. Returns:
// -1: no ocurrences of this atom on the formula
// 0: negative polarity
// 1: positive polarity
// 2: ocurrences of both polarities
int polarity(const string& atom) const;
// Counts the number of ocurrences of atoms in the formula that are
// described in valuation.
unsigned int atomsIn(const map<string, int>& valuation) const;
// Counts the number of ocurrences of atoms in the formula that are
// not described in valuation.
unsigned int atomsOut(const map<string, int>& valuation) const;
// Counts the number of ocurrences of atoms in the formula that are
// not described in the atom set.
unsigned int atomsOut(const set<string>& atomset) const;
// Returns the distance between the formula and the set of atoms in
// the valuation. This distance is the minimum distance between an
// atom occurring in the formula and an atom described in the
// valuation.
double distanceFrom(const map<string, int>& valuation,
const map<string, int>& atom_dist) const;
// If operator == ANDN or ORN, then the elements of vector fmls must
// be not NULL, and the string atom and the pointers left and right
// have no significance.
// If operator == AND, OR or IMPLIES, then the pointers left and
// right must not be NULL, and the string atom and the vector fmls
// have no significance.
// If operator == NOT, then the pointer right must not be NULL and
// the pointer left, the string atom and the vector fmls have no
// significance.
// If operator == ATOM, then the string atom must not be empty and
// the pointers left and right and the vector fmls have no
// significance.
// Type of operator.
opType op;
// Atom.
string atom;
// Left formula.
Formula *left;
// Right formula.
Formula *right;
// Vector of formulas for operators ANDN and ORN.
vector<Formula *> fmls;
};
// Utility functions
// Parse a formula from a string. The formula (and its subformulas
// except atoms) must be enclosed in parenthesis. Returns a newly
// allocated pointer to the formula represented by the string or a
// null pointer if the string is not a valid formula.
Formula *parse(const string& s);
#endif
|
dias-wagner/tableau | ke.h | /*****************************************************************************
* ke.h
*
* Class declarations for tableau KE.
*****************************************************************************/
#ifndef __KE_H__
#define __KE_H__
#include <string>
#include <vector>
#include "formula.h"
// alpha rules
bool KE_alpha_E_NOT_OR(const vector<SignedFormula *>& in,
vector<SignedFormula *>& out);
bool KE_alpha_E_NOT_ORN(const vector<SignedFormula *>& in,
vector<SignedFormula *>& out);
bool KE_alpha_E_AND(const vector<SignedFormula *>& in,
vector<SignedFormula *>& out);
bool KE_alpha_E_ANDN(const vector<SignedFormula *>& in,
vector<SignedFormula *>& out);
bool KE_alpha_E_NOT_IMPLIES(const vector<SignedFormula *>& in,
vector<SignedFormula *>& out);
bool KE_alpha_E_NOT_NOT(const vector<SignedFormula *>& in,
vector<SignedFormula *>& out);
bool KE_alpha_E_NOT(const vector<SignedFormula *>& in,
vector<SignedFormula *>& out);
// beta rules.
bool KE_beta_E_OR_1(const vector<SignedFormula *>& in,
vector<SignedFormula *>& out);
bool KE_beta_E_OR_2(const vector<SignedFormula *>& in,
vector<SignedFormula *>& out);
bool KE_beta_E_ORN(const vector<SignedFormula *>& in,
vector<SignedFormula *>& out);
bool KE_beta_E_NOT_AND_1(const vector<SignedFormula *>& in,
vector<SignedFormula *>& out);
bool KE_beta_E_NOT_AND_2(const vector<SignedFormula *>& in,
vector<SignedFormula *>& out);
bool KE_beta_E_NOT_ANDN(const vector<SignedFormula *>& in,
vector<SignedFormula *>& out);
bool KE_beta_E_IMPLIES_1(const vector<SignedFormula *>& in,
vector<SignedFormula *>& out);
bool KE_beta_E_IMPLIES_2(const vector<SignedFormula *>& in,
vector<SignedFormula *>& out);
//////////////////////////////////////////////////////////////////////////////
// Encapsulates the KE tableau default strategy. It:
// - Analyses all the alphas first, top down;
// - Then, tries to analyse the first beta, top down, with a literal as
// secondary;
// - Then, applies the PB rule with the first beta non analysed.
//////////////////////////////////////////////////////////////////////////////
class KEStrategy : public TableauStrategy
{
public:
KEStrategy();
virtual ~KEStrategy();
virtual unsigned int chooseAlpha();
// Returns true (and updates the flag) if there is an applicable
// beta with a literal as secondary.
virtual bool hasApplicableBeta();
virtual unsigned int chooseBeta();
// Returns the literal that goes as secondary of the chosen beta.
virtual unsigned int chooseLit();
// Returns a pointer to a newly allocated formula on which the PB
// will be applied.
virtual Formula *choosePB();
// 0=alpha; 1=beta; 2=PB; -1=none.
virtual int nextRule();
protected:
// maps a formula to a tableau id if the formula has
// been applied in the tableau.
map<string, string> appliedPB;
bool hasAppBeta;
unsigned int indexAppBeta;
unsigned int indexAppLit;
unsigned int indexAppPB;
};
//////////////////////////////////////////////////////////////////////////////
// Encapsulates a KE tableau strategy that:
// - Analyses all the alphas first, top down;
// - Then, tries to analyse the first beta, top down, with a literal as
// secondary;
// - Then, applies the PB rule with the first beta non analysed with value=*
// with respect to the valuation given by the literals in the branch.
//////////////////////////////////////////////////////////////////////////////
class KEValuationStrategy : public KEStrategy
{
public:
KEValuationStrategy();
virtual ~KEValuationStrategy();
virtual Formula *choosePB();
};
//////////////////////////////////////////////////////////////////////////////
// Encapsulates a KE tableau strategy that:
// - Analyses all the alphas first, top down;
// - Then, tries to analyse the first beta, top down, with a literal as
// secondary;
// - Then, applies the PB rule with a subformula of the first beta non
// analysed with the properties:
// 1. must have value=* with respect to the valuation given by the literals
// in the branch, and
// 2. for some atom A, must have an occurrence of A with the inverse
// polarity of the literal where A occurs in the branch.
//////////////////////////////////////////////////////////////////////////////
class KEPolarityStrategy : public KEStrategy
{
public:
KEPolarityStrategy();
virtual ~KEPolarityStrategy();
virtual Formula *choosePB();
};
//////////////////////////////////////////////////////////////////////////////
// Encapsulates a KE tableau.
//////////////////////////////////////////////////////////////////////////////
class KETableau : public Tableau
{
public:
KETableau(const string& id, SignedFormula *fml,
KETableau *parent = NULL);
KETableau(const string& id, const vector<SignedFormula *>& fmls,
KETableau *parent = NULL);
~KETableau() { }
virtual void setStrategy(KEStrategy *strategy);
virtual bool close();
protected:
enum enumRule {A_E_NOT_OR=0, A_E_NOT_ORN=1,
A_E_AND=2, A_E_ANDN=3,
A_E_NOT_IMPLIES=4, A_E_NOT_NOT=5, A_E_NOT=6,
B_E_OR_1=7, B_E_OR_2=8, B_E_ORN=9,
B_E_NOT_AND_1=10, B_E_NOT_AND_2=11, B_E_NOT_ANDN=12,
B_E_IMPLIES_1=13, B_E_IMPLIES_2=14};
virtual bool applyRule(enumRule r,
vector<SignedFormula *>& in,
vector<SignedFormula *>& out);
// Performs pre-close operations.
virtual void preClose() { }
// Performs post-close operations.
virtual void postClose() { }
// Create a child tableau.
virtual void createChild(const string& id, SignedFormula *fml);
// Auxiliary vectors containing the alpha, the beta formulas and the
// literals in vector _items.
vector<SignedFormula *> _alphas, _betas, _lits;
// Indicates if the tableau is closed
bool _closed;
private:
// Strategy object
KEStrategy *_strategy;
};
#endif
|
dias-wagner/tableau | analytic.h | /*****************************************************************************
* analytic.h
*
* Class declarations for analytic tableau.
*****************************************************************************/
#ifndef __ANALYTIC_H__
#define __ANALYTIC_H__
#include <vector>
#include "formula.h"
#include "tableau.h"
// alpha rules
bool alpha_E_NOT_OR(const vector<SignedFormula *>& in,
vector<SignedFormula *>& out);
bool alpha_E_NOT_ORN(const vector<SignedFormula *>& in,
vector<SignedFormula *>& out);
bool alpha_E_AND(const vector<SignedFormula *>& in,
vector<SignedFormula *>& out);
bool alpha_E_ANDN(const vector<SignedFormula *>& in,
vector<SignedFormula *>& out);
bool alpha_E_NOT_IMPLIES(const vector<SignedFormula *>& in,
vector<SignedFormula *>& out);
bool alpha_E_NOT_NOT(const vector<SignedFormula *>& in,
vector<SignedFormula *>& out);
bool alpha_E_NOT(const vector<SignedFormula *>& in,
vector<SignedFormula *>& out);
// beta rules
bool beta_E_OR(const vector<SignedFormula *>& in,
vector<SignedFormula *>& out);
bool beta_E_ORN(const vector<SignedFormula *>& in,
vector<SignedFormula *>& out);
bool beta_E_NOT_AND(const vector<SignedFormula *>& in,
vector<SignedFormula *>& out);
bool beta_E_NOT_ANDN(const vector<SignedFormula *>& in,
vector<SignedFormula *>& out);
bool beta_E_IMPLIES(const vector<SignedFormula *>& in,
vector<SignedFormula *>& out);
//////////////////////////////////////////////////////////////////////////////
// Encapsulates the analytic tableau default strategy. It:
// - Analyses all the alphas first, top down;
// - Then, analyses the first beta, top down.
//////////////////////////////////////////////////////////////////////////////
class AnalyticStrategy : public TableauStrategy
{
public:
AnalyticStrategy();
~AnalyticStrategy();
virtual unsigned int chooseAlpha();
virtual unsigned int chooseBeta();
virtual int nextRule();
};
//////////////////////////////////////////////////////////////////////////////
// Encapsulates an analytic tableau strategy that:
// - Analyses all the alphas first, bottom up;
// - Then, analyses the first beta, bottom up.
//////////////////////////////////////////////////////////////////////////////
class AnalyticBottomUpStrategy : public AnalyticStrategy
{
public:
AnalyticBottomUpStrategy();
~AnalyticBottomUpStrategy();
virtual unsigned int chooseAlpha();
virtual unsigned int chooseBeta();
};
//////////////////////////////////////////////////////////////////////////////
// Encapsulates an analytic tableau.
//////////////////////////////////////////////////////////////////////////////
class AnalyticTableau : public Tableau
{
public:
AnalyticTableau(const string& id, SignedFormula *fml,
AnalyticTableau *parent = NULL);
AnalyticTableau(const string& id, const vector<SignedFormula *>& fmls,
AnalyticTableau *parent = NULL);
~AnalyticTableau() { }
// Sets the strategy object.
virtual void setStrategy(AnalyticStrategy *strategy);
bool close();
protected:
enum enumRule {A_E_NOT_OR=0, A_E_NOT_ORN,
A_E_AND, A_E_ANDN,
A_E_NOT_IMPLIES, A_E_NOT_NOT, A_E_NOT,
B_E_OR, B_E_ORN,
B_E_NOT_AND, B_E_NOT_ANDN,
B_E_IMPLIES};
bool applyRule(AnalyticTableau::enumRule r,
vector<SignedFormula *>& in, vector<SignedFormula *>& out);
// Create a child tableau
virtual void createChild(const string& id, SignedFormula *fml);
// Auxiliary vectors containing the alpha, the beta formulas and the
// literals in vector _items.
vector<SignedFormula *> _alphas, _betas, _lits;
// Indicates if the tableau is closed
bool _closed;
private:
// Strategy object
AnalyticStrategy *_strategy;
};
#endif
|
dias-wagner/tableau | tableau.h | /*****************************************************************************
* tableau.h
*
* Class declarations for the generic tableau.
*****************************************************************************/
#ifndef __TABLEAU_H__
#define __TABLEAU_H__
#include <string>
#include <vector>
#include "formula.h"
//////////////////////////////////////////////////////////////////////////////
// Encapsulates a signed formula.
//////////////////////////////////////////////////////////////////////////////
class SignedFormula
{
public:
enum Sign {S_F, S_T};
SignedFormula(Sign s, Formula *fml);
// Formula types.
enum fmlType {ALPHA, BETA, LITERAL};
// Returns the type of the formula.
fmlType type() const;
// Returns a string representation of the formula.
string toString() const;
// Returns the value of the formula according to a valuation. Returns:
// -1: undefined
// 0: false
// 1: true
int value(map<string, int>& valuation) const;
// Returns the polarity of the specified atom in the formula. Returns:
// -1: no ocurrences of this atom on the formula
// 0: negative polarity
// 1: positive polarity
// 2: ocurrences of both polarities
int polarity(const string& atom) const;
// Counts the number of ocurrences of atoms in the formula that are
// described in valuation.
unsigned int atomsIn(const map<string, int>& valuation) const;
// Counts the number of ocurrences of atoms in the formula that are
// not described in valuation.
unsigned int atomsOut(const map<string, int>& valuation) const;
// Counts the number of ocurrences of atoms in the formula that are
// not described in the atom set.
unsigned int atomsOut(const set<string>& atomset) const;
// Returns the distance between the formula and the set of atoms in
// the valuation. This distance is the minimum distance between an
// atom occurring in the formula and an atom described in the
// valuation.
double distanceFrom(const map<string, int>& valuation,
const map<string, int>& atom_dist) const;
Sign sign;
Formula *formula;
fmlType ty;
};
//////////////////////////////////////////////////////////////////////////////
// A rule is a pointer to a function returning bool and having the
// input and output formulas as parameters.
//////////////////////////////////////////////////////////////////////////////
typedef bool (*Rule)(const vector<SignedFormula *>&, vector<SignedFormula *>&);
//////////////////////////////////////////////////////////////////////////////
// Encapsulates a generic tableau strategy.
//////////////////////////////////////////////////////////////////////////////
class TableauStrategy
{
public:
TableauStrategy();
virtual ~TableauStrategy();
// initializes the object with the items of a tableau. Returns true
// if the tableau is already close. This method also uses the
// Floyd-Warshall algorithm to calculate the minimum distance
// between each pair of atoms.
bool init(const string& tableau_id,
vector<SignedFormula *> *items,
vector<SignedFormula *> *alphas,
vector<SignedFormula *> *betas,
vector<SignedFormula *> *lits);
// classifies the formulas in the vector items. Puts them into the
// corresponding vector: alphas, betas or lits. Returns true if the
// tableau is closed.
bool classify(unsigned int& index);
// choose the next alpha formula to be analysed. Returns the index
// of the formula in the vector alphas.
virtual unsigned int chooseAlpha();
// choose the next beta formula to be analysed.
virtual unsigned int chooseBeta();
// chooses the next rule to be applied (-1=none; 0=alpha; 1=beta).
virtual int nextRule() = 0;
protected:
// Initializes M and atom2node, which will be used in the F-W algorithm.
void init_floyd_warshall(Formula *fml, int nt, int nf,
int **M, map<string, set<int> >& atom2node,
int parent, int *next_node, int level);
// the id of the tableau associated to this strategy object.
string id;
vector<SignedFormula *> *_items;
vector<SignedFormula *> *_alphas;
vector<SignedFormula *> *_betas;
vector<SignedFormula *> *_lits;
// if _mlits[str] = 1, we have F str
// if _mlits[str] = 2, we have T str
// if _mlits[str] = 3, we have both
map<string, int> _mlits;
// Map of distances between connective nodes, calculated by the
// Floyd-Warshall algorithm in the first call to the init()
// method. For a pair of atoms a and b, the key is "a,b".
map<string, int> _atom_dist;
// Maximum atom distance.
int _max_atom_dist;
// indicates if the F-W algorithm was already run in this object.
bool _fw_done;
};
//////////////////////////////////////////////////////////////////////////////
// Encapsulates a generic tableau.
//////////////////////////////////////////////////////////////////////////////
class Tableau
{
public:
Tableau(const string& id, SignedFormula *fml,
Tableau *parent = NULL);
Tableau(const string& id, const vector<SignedFormula *>& fmls,
Tableau *parent = NULL);
virtual ~Tableau();
// Sets the strategy object.
virtual void setStrategy(TableauStrategy *strategy);
// String representation of the tableau.
virtual string toString(int level=0) const;
// Tries to close the tableau (returns true if successful).
virtual bool close() = 0;
// Returns the total number of nodes of the tableau (including children).
unsigned int countNodes();
// Returns the total number of formulae of the tableau (including children).
unsigned int countFormulae();
protected:
// Applies the index'th rule of the tableau. Returns true if successful.
bool applyRule(unsigned int index,
const vector<SignedFormula *>& in,
vector<SignedFormula *>& out);
// Create a child tableau
virtual void createChild(const string& id, SignedFormula *fml) = 0;
// Formulae of the tableau.
vector<SignedFormula *> _items;
// Child tableaux.
vector<Tableau *> _children;
// Parent tableau node.
Tableau *_parent;
// Rules of the tableau.
vector<Rule> _rules;
// Id of the tableau.
string _id;
private:
// Strategy of the tableau.
TableauStrategy *_strategy;
};
#endif
|
dias-wagner/tableau | kes3.h | /*****************************************************************************
* kes3.h
*
* Class declarations for tableau KE-S3.
*****************************************************************************/
#ifndef __KES3_H__
#define __KES3_H__
#include <map>
#include <set>
#include <string>
#include <vector>
#include "formula.h"
#include "ke.h"
//////////////////////////////////////////////////////////////////////////////
// Encapsulates the KES3 tableau default strategy. It:
// - Analyses all the alphas first, top down;
// - Then, tries to analyse the first beta, top down, with a literal as
// secondary;
// - Then, applies the PB rule with a subformula of the first beta non
// analysed with the properties:
// 1. must have value=* with respect to the valuation given by the literals
// in the branch, and
// 2. for some atom A, must have an occurrence of A with the inverse
// polarity of the literal where A occurs in the branch.
//////////////////////////////////////////////////////////////////////////////
class KES3Strategy : public KEPolarityStrategy
{
public:
KES3Strategy();
virtual ~KES3Strategy();
void setTableau(Tableau *tableau) { tab = tableau; };
virtual Formula *choosePB();
protected:
Tableau *tab;
};
//////////////////////////////////////////////////////////////////////////////
// Encapsulates a KE tableau strategy that:
// - Analyses all the alphas first, top down, *EXCEPT* the A_E_NOT rule;
// - Then, tries to analyse the first beta, top down, with a literal as
// secondary;
// - Then, applies the PB rule with a subformula of the first beta non
// analysed with the properties:
// 1. must have value=* with respect to the valuation given by the literals
// in the branch, and
// 2. for some atom A, must have an occurrence of A with the inverse
// polarity of the literal where A occurs in the branch.
// 3. give preference to formulas containing less atoms outside S.
// - Then, applies the alpha rule A_E_NOT, giving preference to formulas
// containing less atoms outside S.
//
//////////////////////////////////////////////////////////////////////////////
class KES3AENOTLastStrategy : public KES3Strategy
{
public:
KES3AENOTLastStrategy();
virtual ~KES3AENOTLastStrategy();
virtual bool hasApplicableSimpleAlpha();
virtual bool hasApplicableAENOT();
virtual unsigned int chooseAlpha();
virtual Formula *choosePB();
virtual int nextRule();
protected:
bool hasAppSimpleAlpha;
bool hasAppAENOT;
unsigned int indexAppAlpha;
};
//////////////////////////////////////////////////////////////////////////////
// Encapsulates a KE tableau.
//////////////////////////////////////////////////////////////////////////////
class KES3Tableau : public KETableau
{
friend class KES3Strategy;
friend class KES3AENOTLastStrategy;
public:
KES3Tableau(const string& id, SignedFormula *fml,
KES3Tableau *parent = NULL);
KES3Tableau(const string& id, const vector<SignedFormula *>& fmls,
KES3Tableau *parent = NULL);
~KES3Tableau() { }
virtual void setStrategy(KES3Strategy *strategy);
virtual bool close();
// Returns a string representation of the formula.
string toString(int level=0) const;
// Returns the current state of the context set S.
set<string> S() const;
// THIS SHOULD BE PROTECTED. It is being acessed in the call of the
// constructor of the AENOTLast strategy. (Is this a case to use
// friend classes?)
// The context set of atoms
// S.
set<string> _S;
protected:
virtual bool applyRule(KETableau::enumRule r,
vector<SignedFormula *>& in,
vector<SignedFormula *>& out);
// Performs pre-close operations.
virtual void preClose();
// Performs post-close operations.
virtual void postClose();
// Inserts the atoms of formula f into the context set _S
void InsertAtoms(Formula *f);
// Create a child tableau.
virtual void createChild(const string& id, SignedFormula *fml);
// Associates each index of formula (generated by the T_NOT alpha
// rule) with the state of S generated by the rule.
map<unsigned int, set<string> > mS;
private:
// The strategy object.
KES3Strategy *_strategy;
};
#endif
|
tyshchenko/gui-kit | SectionsTableView/SectionsTableView/SectionsTableView.h | <gh_stars>1-10
#import <UIKit/UIKit.h>
FOUNDATION_EXPORT double SectionsTableViewVersionNumber;
FOUNDATION_EXPORT const unsigned char SectionsTableViewVersionString[];
|
tyshchenko/gui-kit | ActionSheet/ActionSheet/ActionSheet.h | #import <UIKit/UIKit.h>
FOUNDATION_EXPORT double ActionSheetVersionNumber;
FOUNDATION_EXPORT const unsigned char ActionSheetVersionString[];
|
tyshchenko/gui-kit | HUD/HUD/HUD.h | #import <UIKit/UIKit.h>
FOUNDATION_EXPORT double HUDVersionNumber;
FOUNDATION_EXPORT const unsigned char HUDVersionString[];
|
tyshchenko/gui-kit | UIExtensions/UIExtensions/UIExtensions.h | #import <UIKit/UIKit.h>
FOUNDATION_EXPORT double UIExtensionsVersionNumber;
FOUNDATION_EXPORT const unsigned char UIExtensionsVersionString[];
|
jipr311/39bf4357ed29-QAESEncryption | qaesencryption.h | #ifndef QAESENCRYPTION_H
#define QAESENCRYPTION_H
#include <QObject>
#include <QByteArray>
class QAESEncryption : public QObject
{
Q_OBJECT
public:
enum Aes {
AES_128,
AES_192,
AES_256
};
enum Mode {
ECB,
CBC,
CFB,
OFB
};
enum Padding {
ZERO,
PKCS7,
ISO
};
static QByteArray Crypt(QAESEncryption::Aes level, QAESEncryption::Mode mode, const QByteArray &rawText, const QByteArray &key,
const QByteArray &iv = NULL, QAESEncryption::Padding padding = QAESEncryption::ISO);
static QByteArray Decrypt(QAESEncryption::Aes level, QAESEncryption::Mode mode, const QByteArray &rawText, const QByteArray &key,
const QByteArray &iv = NULL, QAESEncryption::Padding padding = QAESEncryption::ISO);
static QByteArray ExpandKey(QAESEncryption::Aes level, QAESEncryption::Mode mode, const QByteArray &key);
static QByteArray RemovePadding(const QByteArray &rawText, QAESEncryption::Padding padding);
QAESEncryption(QAESEncryption::Aes level, QAESEncryption::Mode mode,
QAESEncryption::Padding padding = QAESEncryption::ISO);
QByteArray encode(const QByteArray &rawText, const QByteArray &key, const QByteArray &iv = NULL);
QByteArray decode(const QByteArray &rawText, const QByteArray &key, const QByteArray &iv = NULL);
QByteArray removePadding(const QByteArray &rawText);
QByteArray expandKey(const QByteArray &key);
signals:
public slots:
private:
int m_nb;
int m_blocklen;
int m_level;
int m_mode;
int m_nk;
int m_keyLen;
int m_nr;
int m_expandedKey;
int m_padding;
QByteArray* m_state;
struct AES256{
int nk = 8;
int keylen = 32;
int nr = 14;
int expandedKey = 240;
};
struct AES192{
int nk = 6;
int keylen = 24;
int nr = 12;
int expandedKey = 209;
};
struct AES128{
int nk = 4;
int keylen = 16;
int nr = 10;
int expandedKey = 176;
};
quint8 getSBoxValue(quint8 num){return sbox[num];}
quint8 getSBoxInvert(quint8 num){return rsbox[num];}
void addRoundKey(const quint8 round, const QByteArray expKey);
void subBytes();
void shiftRows();
void mixColumns();
void invMixColumns();
void invSubBytes();
void invShiftRows();
QByteArray getPadding(int currSize, int alignment);
QByteArray cipher(const QByteArray &expKey, const QByteArray &plainText);
QByteArray invCipher(const QByteArray &expKey, const QByteArray &plainText);
QByteArray byteXor(const QByteArray &in, const QByteArray &iv);
static const quint8 sbox[256];
static const quint8 rsbox[256];
// The round constant word array, Rcon[i], contains the values given by
// x to th e power (i-1) being powers of x (x is denoted as {02}) in the field GF(2^8)
// Only the first 14 elements are needed
static const quint8 Rcon[256];
};
#endif // QAESENCRYPTION_H
|
vanhoutk/Real-Time-Physics-A1 | A1/A1/Particle.h | <gh_stars>0
#pragma once
#include <GL/glew.h>
#include "Antons_maths_funcs.h"
class Particle{
public:
vec3 position;
vec3 velocity;
GLfloat mass;
GLfloat life;
vec3 force;
vec4 colour;
Particle();
Particle(vec3 position, vec3 velocity, GLfloat mass, GLfloat life, vec3 force, vec4 colour);
};
Particle::Particle()
{
this->position = vec3(0.0f, 0.0f, 0.0f);
this->velocity = vec3(0.0f, 0.0f, 0.0f);
this->mass = 1.0f;
this->life = 0.0f;
this->force = vec3(0.0f, 0.0f, 0.0f);
}
Particle::Particle(vec3 position, vec3 velocity, GLfloat mass, GLfloat life, vec3 force, vec4 colour)
{
this->position = position;
this->velocity = velocity;
this->mass = mass;
this->life = life;
this->force = force;
this->colour = colour;
} |
msunde137/particles | src/particlesystem.h | #ifndef ParticleSystem_H_
#define ParticleSystem_H_
#include "AGL.h"
#include "image.h"
#include "renderer.h"
#include <vector>
namespace agl {
struct Particle {
// initial values
glm::mat4 itransform;
glm::vec3 ivelocity;
glm::vec3 iacceleration;
glm::vec4 icolor;
float lifetime;
// current values
glm::mat4 transform;
glm::vec3 velocity;
glm::vec3 acceleration;
glm::vec4 color;
glm::vec3 scale, position;
float mass;
float age;
Particle(glm::vec3 pos = glm::vec3(0), glm::vec3 scl = glm::vec3(1),
glm::vec3 vel = glm::vec3(0), glm::vec3 acc = glm::vec3(0),
glm::vec4 col = glm::vec4(1), float life = 0, float mass = 1)
: position{ pos }, scale{ scl }, ivelocity{ vel },
iacceleration{ acc }, icolor{ col }, lifetime{ life }, mass{ mass }
{
itransform = glm::translate(glm::mat4(1), pos) * glm::scale(glm::mat4(1), scale);
transform = itransform;
velocity = vel;
acceleration = acc;
color = col;
age = 0.0f;
}
};
class ParticleSystem {
public:
ParticleSystem();
virtual ~ParticleSystem();
void init(std::shared_ptr<Renderer> renderer, int size);
virtual void update(float dt) = 0;
virtual void draw();
protected:
virtual void createParticles(int size) = 0;
protected:
std::vector<Particle> mParticles;
GLuint mTexture;
BlendMode mBlendMode;
std::shared_ptr<Renderer> mRenderer;
};
}
#endif |
msunde137/particles | src/AGLM.h | // <NAME>, 2020
// Convenience header for utilities and common includes
#pragma once
#include <iostream>
#include <stdio.h>
#include <glm/gtc/matrix_transform.hpp>
#include <glm/gtx/norm.hpp>
#include <glm/gtc/epsilon.hpp>
#include <limits>
#include <memory>
#include <random>
#include <cmath>
extern std::ostream& operator<<(std::ostream& o, const glm::mat4& m);
extern std::ostream& operator<<(std::ostream& o, const glm::mat3& m);
extern std::ostream& operator<<(std::ostream& o, const glm::vec3& v);
extern std::ostream& operator<<(std::ostream& o, const glm::vec4& v);
extern std::ostream& operator<<(std::ostream& o, const glm::vec2& v);
inline bool operator<(const glm::vec3& a, const glm::vec3& b) { return a.x < b.x || a.y < b.y || a.z < b.z; }
inline bool operator>=(const glm::vec3& a, const glm::vec3& b) { return !(a < b); }
inline bool operator>(const glm::vec3& a, const glm::vec3& b) { return a.x > b.x || a.y > b.y || a.z > b.z; }
inline bool operator<=(const glm::vec3& a, const glm::vec3& b) { return !(a > b); }
namespace glm
{
using point3 = glm::vec3;
using color = glm::vec3;
}
const float pi = glm::pi<float>();
const float infinity = std::numeric_limits<float>::infinity();
float random_float();
float random_float(float min, float max);
inline glm::vec3 random_vec3()
{
float x = random_float();
float y = random_float();
float z = random_float();
return glm::vec3(x, y, z);
}
inline glm::vec3 random_vec3(const glm::vec3& min, const glm::vec3& max)
{
float x = random_float(min.x, max.x);
float y = random_float(min.y, max.y);
float z = random_float(min.z, max.z);
return glm::vec3(x, y, z);
}
inline glm::vec4 random_vec4()
{
return glm::vec4(random_vec3(), random_float());
}
inline glm::vec4 random_vec3(const glm::vec4& min, const glm::vec4& max)
{
return glm::vec4(random_vec3((glm::vec3)min, (glm::vec3)max), random_float(min.w, max.w));
}
inline glm::vec3 random_unit_cube()
{
return random_vec3(glm::vec3(-.5, -.5, -.5), glm::vec3(.5, .5, .5));
}
//inline glm::vec3 random_unit_cube()
//{
// float x = random_float(-0.5,0.5);
// float y = random_float(-0.5,0.5);
// float z = random_float(-0.5,0.5);
// return glm::vec3(x, y, z);
//}
inline glm::vec3 random_unit_square()
{
float x = random_float(-0.5,0.5);
float y = random_float(-0.5,0.5);
return glm::vec3(x, y, 0);
}
inline glm::vec3 random_unit_sphere()
{
glm::mat4 quat = glm::rotate(glm::mat4(1), random_float(0, 2.0f * 3.142f), glm::vec3(1, 0, 0));
quat = glm::rotate(quat, random_float(0, 2.0f * 3.142f), glm::vec3(0, 1, 0));
quat = glm::rotate(quat, random_float(0, 2.0f * 3.142f), glm::vec3(0, 0, 1));
return glm::vec3(quat * glm::vec4(0, 1, 0, 1));
}
inline glm::vec3 random_unit_ball()
{
glm::mat4 quat = glm::rotate(glm::mat4(1), random_float(0, 2.0f * 3.142f), glm::vec3(1, 0, 0));
quat = glm::rotate(quat, random_float(0, 2.0f * 3.142f), glm::vec3(0, 1, 0));
quat = glm::rotate(quat, random_float(0, 2.0f * 3.142f), glm::vec3(0, 0, 1));
return glm::vec3(quat * glm::vec4(1, 0, 0, 1)) * random_float(0.0f,1.0f);
}
inline glm::vec3 random_unit_disk()
{
glm::vec3 p = random_unit_square();
while (glm::length(p) >= 1.0f)
{
p = random_unit_square();
}
return p;
}
// Generate random direction in hemisphere around normal
// from https://raytracing.github.io/books/RayTracingInOneWeekend.html (<NAME>)
inline glm::vec3 random_hemisphere(const glm::vec3& normal)
{
glm::vec3 in_unit_sphere = random_unit_sphere();
if (glm::dot(in_unit_sphere, normal) > 0.0f) // In the same hemisphere as the normal
{
return in_unit_sphere;
}
else
{
return -in_unit_sphere;
}
}
// Generate random unit vector
// from https://raytracing.github.io/books/RayTracingInOneWeekend.html (<NAME>)
inline glm::vec3 random_unit_vector()
{
return glm::normalize(random_unit_sphere());
}
// test for vec3 close to zero (avoid numerical instability)
// from https://raytracing.github.io/books/RayTracingInOneWeekend.html (<NAME>)
inline bool near_zero(const glm::vec3& e)
{
// Return true if the vector is close to zero in all dimensions.
const auto s = 1e-8;
return (fabs(e[0]) < s) && (fabs(e[1]) < s) && (fabs(e[2]) < s);
}
inline bool near_zero(const glm::vec4& e)
{
// Return true if the vector is close to zero in all dimensions.
const auto s = 1e-8;
return (fabs(e[0]) < s) && (fabs(e[1]) < s) && (fabs(e[2]) < s) && (fabs(e[3]) < s);
}
inline bool near_zero(const float& e)
{
// Return true if the vector is close to zero in all dimensions.
const auto s = 1e-8;
return fabs(e) < s;
}
|
dolovnyak/ray-marching-render | include/rt_raycast.h | /* ************************************************************************** */
/* */
/* ::: :::::::: */
/* rt_raycast.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: sbecker <<EMAIL>> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/07/23 17:50:06 by sbecker #+# #+# */
/* Updated: 2019/07/23 17:50:07 by sbecker ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef RT_RAYCAST_H
# define RT_RAYCAST_H
# include "rt.h"
# include "rt_object.h"
# include "rt_raycast_hit.h"
# define DEFAULT_LAYER (1 << 0)
# define IGNORE_RAYCAST_LAYER (1 << 1)
cl_float3 f3cross(cl_float3 v1, cl_float3 v2);
float f3len(cl_float3 v);
float f3dot(cl_float3 v1, cl_float3 v2);
cl_float3 f3norm(cl_float3 v);
float sdf_sphere(cl_float3 pos, float radius);
float sdf_box(cl_float3 pos, cl_float3 bounds);
float sdf_round_box(cl_float3 pos, cl_float3 bounds, float r);
float sdf_capped_torus(cl_float3 pos, cl_float2 sc, float ra, float rb);
float sdf_link(cl_float3 pos, float le, float r1, float r2);
float sdf_cylinder(cl_float3 pos, cl_float3 c);
float sdf_cone(cl_float3 pos, cl_float2 c);
float sdf_plane(cl_float3 pos, cl_float3 n, float d);
float sdf_torus(cl_float3 pos, cl_float radius, cl_float inner_radius);
int rt_raycast(t_ui_main *ui, void *a);
#endif
|
dolovnyak/ray-marching-render | libui/src/ui_sdl/ui_sdl_set_texture_mode.c | /* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ui_sdl_set_texture_mode.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: sbecker <<EMAIL>> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/07/15 12:23:37 by sbecker #+# #+# */
/* Updated: 2019/07/15 12:23:40 by sbecker ### ########.fr */
/* */
/* ************************************************************************** */
#include "libui.h"
void ui_sdl_set_texture_color_mode(SDL_Texture *t, Uint8 r, Uint8 g, Uint8 b)
{
SDL_SetTextureColorMod(t, r, g, b);
}
void ui_sdl_set_texture_alpha_mode(SDL_Texture *t, Uint8 a)
{
SDL_SetTextureAlphaMod(t, a);
}
|
dolovnyak/ray-marching-render | libui/src/ui_main/ui_main_get_surface_by_id.c | <reponame>dolovnyak/ray-marching-render<filename>libui/src/ui_main/ui_main_get_surface_by_id.c
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ui_main_get_surface_by_id.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: sbednar <<EMAIL>> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/04/30 20:13:13 by sbednar #+# #+# */
/* Updated: 2019/07/15 11:53:32 by sbecker ### ########.fr */
/* */
/* ************************************************************************** */
#include "libui.h"
SDL_Surface *ui_main_get_surface_by_id(t_ui_main *m, const char *sur_id)
{
SDL_Surface *res;
t_list *tmp;
int hash;
res = NULL;
tmp = m->sdl_surfaces;
hash = ft_strhash(sur_id);
while (tmp && !res)
{
if (tmp->content_size == (size_t)hash)
res = (SDL_Surface *)tmp->content;
tmp = tmp->next;
}
return (res);
}
|
dolovnyak/ray-marching-render | src/rt_physics_system.c | <filename>src/rt_physics_system.c
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* rt_physics_system.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: sbednar <<EMAIL>> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/04/11 03:01:47 by sbecker #+# #+# */
/* Updated: 2019/07/03 19:48:39 by sbecker ### ########.fr */
/* */
/* ************************************************************************** */
#include "rt_physics_system.h"
static int ps_move(t_physics_system *ps, const int i)
{
t_rb *rbs;
rbs = (t_rb *)ps->rbs.storage;
if (fabs(rbs[i].move.vel.x - rbs[i].move.raw_vel.x) > RM_FLT_EPSILON)
rbs[i].move.vel.x = ft_lerp(
rbs[i].move.vel.x,
rbs[i].move.raw_vel.x,
rbs[i].move.acc);
if (fabs(rbs[i].move.vel.y - rbs[i].move.raw_vel.y) > RM_FLT_EPSILON)
rbs[i].move.vel.y = ft_lerp(
rbs[i].move.vel.y,
rbs[i].move.raw_vel.y,
rbs[i].move.acc);
if (fabs(rbs[i].move.vel.z - rbs[i].move.raw_vel.z) > RM_FLT_EPSILON)
rbs[i].move.vel.z = ft_lerp(
rbs[i].move.vel.z,
rbs[i].move.raw_vel.z,
rbs[i].move.acc);
if (fabs(rbs[i].move.vel.x) > RM_FLT_EPSILON)
rbs[i].transform->pos.v4 += rbs[i].transform->right.v4 * rbs[i].move.vel.x *
rbs[i].move.speed * ps->system.delta_time;
if (fabs(rbs[i].move.vel.y) > RM_FLT_EPSILON)
rbs[i].transform->pos.v4 += rbs[i].transform->up.v4 * rbs[i].move.vel.y *
rbs[i].move.speed * ps->system.delta_time;
if (fabs(rbs[i].move.vel.z) > RM_FLT_EPSILON)
rbs[i].transform->pos.v4 += rbs[i].transform->forward.v4 * rbs[i].move.vel.z *
rbs[i].move.speed * ps->system.delta_time;
return (fabs(rbs[i].move.vel.x) > RM_FLT_EPSILON ||
fabs(rbs[i].move.vel.y) > RM_FLT_EPSILON ||
fabs(rbs[i].move.vel.z) > RM_FLT_EPSILON);
}
static int ps_rot(t_physics_system *ps, const int i)
{
t_rb *rbs;
rbs = (t_rb *)ps->rbs.storage;
if (fabs(rbs[i].rot.vel.x - rbs[i].rot.raw_vel.x) > RM_FLT_EPSILON)
rbs[i].rot.vel.x = ft_lerp(
rbs[i].rot.vel.x,
rbs[i].rot.raw_vel.x,
rbs[i].rot.acc);
if (fabs(rbs[i].rot.vel.y - rbs[i].rot.raw_vel.y) > RM_FLT_EPSILON)
rbs[i].rot.vel.y = ft_lerp(
rbs[i].rot.vel.y,
rbs[i].rot.raw_vel.y,
rbs[i].rot.acc);
// float rot_matrix[9];
if (fabs(rbs[i].rot.vel.x) > RM_FLT_EPSILON)
{
rotate_transform_around_axis(rbs[i].transform, rbs[i].transform->right, rbs[i].rot.vel.x * rbs[i].rot.speed * ps->system.delta_time);
// fill_rotation_matrix(&rot_matrix[0], rbs[i].transform->right, rbs[i].rot.vel.x * rbs[i].rot.speed * ps->system.delta_time);
// mult(&rot_matrix[0], &rbs[i].transform->right);
// mult(&rot_matrix[0], &rbs[i].transform->up);
// mult(&rot_matrix[0], &rbs[i].transform->forward);
}
if (fabs(rbs[i].rot.vel.y) > RM_FLT_EPSILON)
{
rotate_transform_around_axis(rbs[i].transform, (cl_float3){{0, 1, 0}}, rbs[i].rot.vel.y * rbs[i].rot.speed * ps->system.delta_time);
// fill_rotation_matrix(&rot_matrix[0], (cl_float3){{0, 1, 0}}, rbs[i].rot.vel.y * rbs[i].rot.speed * ps->system.delta_time);
// mult(&rot_matrix[0], &rbs[i].transform->right);
// mult(&rot_matrix[0], &rbs[i].transform->up);
// mult(&rot_matrix[0], &rbs[i].transform->forward);
}
return (fabs(rbs[i].rot.vel.x) > RM_FLT_EPSILON ||
fabs(rbs[i].rot.vel.y) > RM_FLT_EPSILON ||
fabs(rbs[i].rot.vel.z) > RM_FLT_EPSILON);
}
int ps_func(void *psv)
{
t_physics_system *ps;
size_t i;
SDL_SetThreadPriority(SDL_THREAD_PRIORITY_HIGH);
ps = (t_physics_system *)psv;
ps->system.now = SDL_GetPerformanceCounter();
ps->system.last = ps->system.now;
while (ps->rbs.storage)
{
ps->change_indicator = 0;
i = -1;
ps->system.delta_time = (double)(ps->system.now - ps->system.last) / SDL_GetPerformanceFrequency() / 1000;
while (++i < ps->rbs.size)
{
ps->change_indicator |= ps_move(ps, i);
ps->change_indicator |= ps_rot(ps, i);
}
SDL_Delay(ps->system.delay);
ps->system.last = ps->system.now;
ps->system.now = SDL_GetPerformanceCounter();
}
return (0);
}
|
dolovnyak/ray-marching-render | src/rt_jtoc/rt_jtoc_ps_setup.c | #include "rt.h"
#include "rt_jtoc.h"
static int rt_jtoc_get_move_params(t_move_params *p, t_jnode *n)
{
t_jnode *tmp;
if (!(tmp = jtoc_node_get_by_path(n, "vel")) || tmp->type != object)
return (rt_jtoc_sdl_log_error("VEL MISSING OR TYPE ERROR", -1));
if (rt_jtoc_get_float3(&p->vel, tmp))
return (rt_jtoc_sdl_log_error("VEL ERROR", -1));
if (!(tmp = jtoc_node_get_by_path(n, "raw_vel")) || tmp->type != object)
return (rt_jtoc_sdl_log_error("RAW_VEL MISSING OR TYPE ERROR", -1));
if (rt_jtoc_get_float3(&p->raw_vel, tmp))
return (rt_jtoc_sdl_log_error("RAW_VEL ERROR", -1));
if (!(tmp = jtoc_node_get_by_path(n, "acc")) || tmp->type != fractional)
return (rt_jtoc_sdl_log_error("ACC MISSING OR TYPE ERROR", -1));
p->acc = jtoc_get_float(tmp);
if (p->acc < 0)
return (rt_jtoc_sdl_log_error("ACC ERROR", -1));
if (!(tmp = jtoc_node_get_by_path(n, "speed")) || tmp->type != fractional)
return (rt_jtoc_sdl_log_error("SPEED MISSING OR TYPE ERROR", -1));
p->speed = jtoc_get_float(tmp);
if (p->speed < 0)
return (rt_jtoc_sdl_log_error("SPEED ERROR", -1));
if (!(tmp = jtoc_node_get_by_path(n, "speed_mult")) || tmp->type != fractional)
return (rt_jtoc_sdl_log_error("SPEED_MULT MISSING OR TYPE ERROR", -1));
p->speed_mult = jtoc_get_float(tmp);
if (p->speed_mult < 0)
return (rt_jtoc_sdl_log_error("SPED MULT ERROR", -1));
return (FUNCTION_SUCCESS);
}
static int rt_jtoc_get_rb(t_scene *scene, t_physics_system *ps, t_jnode *n)
{
t_transform *t;
t_jnode *tmp;
t_rb rb;
ft_bzero(&rb, sizeof(t_rb));
if (!(tmp = jtoc_node_get_by_path(n, "id")) || tmp->type != integer)
return (rt_jtoc_sdl_log_error("ID MISSING OR TYPE ERROR", -1));
if (!(t = rt_find_transform_by_id(scene, jtoc_get_int(tmp))))
return (rt_jtoc_sdl_log_error("THAT ID DOESN'T EXISTS", -1));
rb.transform = t;
if (!(tmp = jtoc_node_get_by_path(n, "move")) || tmp->type != object)
return (rt_jtoc_sdl_log_error("MOVE MISSING OR TYPE ERROR", t->id));
if (rt_jtoc_get_move_params(&rb.move, tmp))
return (FUNCTION_FAILURE);
if (!(tmp = jtoc_node_get_by_path(n, "rot")) || tmp->type != object)
return (rt_jtoc_sdl_log_error("ROT MISSING OR TYPE ERROR", t->id));
if (rt_jtoc_get_move_params(&rb.rot, tmp))
return (FUNCTION_FAILURE);
vec_push_back(&ps->rbs, &rb);
return (FUNCTION_SUCCESS);
}
static int rt_jtoc_get_rbs(t_scene *scene, t_physics_system *ps, t_jnode *n)
{
t_jnode *tmp;
if (!(tmp = jtoc_node_get_by_path(n, "rbs")) || tmp->type != array)
return (rt_jtoc_sdl_log_error("RBS MISSING OR TYPE ERROR", -1));
tmp = tmp->down;
while (tmp)
{
if (rt_jtoc_get_rb(scene, ps, tmp))
return (FUNCTION_FAILURE);
tmp = tmp->right;
}
return (FUNCTION_SUCCESS);
}
int rt_jtoc_ps_setup(t_scene *scene, t_physics_system *ps, const char *path)
{
t_jnode *n;
int res;
if (!(n = jtoc_read(path)))
return (rt_jtoc_sdl_log_error("PHYSICS SYSTEM ERROR", -1));
ps->system.parent = ps;
if (vec_setup(&ps->rbs, 1, sizeof(t_rb)))
return (FUNCTION_FAILURE);
res = rt_jtoc_get_rbs(scene, ps, n);
jtoc_node_clear(n);
return (res);
} |
dolovnyak/ray-marching-render | libui/src/ui_main/ui_main_handle_continious_event.c | <filename>libui/src/ui_main/ui_main_handle_continious_event.c
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ui_main_handle_continious_event.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: sbecker <<EMAIL>> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/04/15 00:45:47 by sbednar #+# #+# */
/* Updated: 2019/07/15 15:07:55 by sbecker ### ########.fr */
/* */
/* ************************************************************************** */
#include "libui.h"
static int ui_get_mouse_el_pos_x(t_ui_main *m)
{
if (m->raycaster->selected == NULL)
return (-1);
return (m->ptr_pos.x - m->raycaster->selected->rect.x);
}
static int ui_get_mouse_el_pos_y(t_ui_main *m)
{
if (m->raycaster->selected == NULL)
return (-1);
return (m->ptr_pos.y - m->raycaster->selected->rect.y);
}
void ui_main_handle_continious_event(t_ui_main *m, t_ui_el *el)
{
if (el == NULL)
return ;
if (el->params & EL_IS_PTR_INSIDE)
ui_event_invoke(el->events->on_pointer_stay, m, el);
if (m->params & MAIN_LMB_HOLD)
ui_event_invoke(el->events->on_pointer_left_button_hold, m, el);
if (m->params & MAIN_RMB_HOLD)
ui_event_invoke(el->events->on_pointer_right_button_hold, m, el);
el->ptr_rel_pos.x = ui_get_mouse_el_pos_x(m);
el->ptr_rel_pos.y = ui_get_mouse_el_pos_y(m);
}
|
dolovnyak/ray-marching-render | libui/src/ui_el/ui_el_add_texture.c | <reponame>dolovnyak/ray-marching-render
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ui_el_add_texture.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: edraugr- <<EMAIL>> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/04/10 04:27:11 by edraugr- #+# #+# */
/* Updated: 2019/07/15 07:28:58 by sbecker ### ########.fr */
/* */
/* ************************************************************************** */
#include "libui.h"
int ui_el_add_empty_texture(t_ui_el *el, int w, int h, const char *tid)
{
t_list_texture *tmp_lst;
SDL_Texture *tmp;
int hash;
hash = ft_strhash(tid);
tmp_lst = NULL;
tmp = NULL;
if (ctid(el->sdl_textures, hash) || !(tmp_lst = ft_lstnew(NULL, 0)))
ui_sdl_deinit(228);
if ((tmp = SDL_CreateTexture(el->sdl_renderer, SDL_PIXELFORMAT_RGBA8888,
SDL_TEXTUREACCESS_TARGET, w, h)) == NULL)
ui_sdl_deinit(228);
SDL_SetRenderTarget(el->sdl_renderer, tmp);
SDL_SetRenderDrawBlendMode(el->sdl_renderer, SDL_BLENDMODE_NONE);
SDL_SetRenderDrawColor(el->sdl_renderer, 255, 255, 255, 0);
SDL_SetTextureBlendMode(tmp, SDL_BLENDMODE_BLEND);
SDL_RenderFillRect(el->sdl_renderer, NULL);
SDL_SetRenderDrawBlendMode(el->sdl_renderer, SDL_BLENDMODE_BLEND);
SDL_SetRenderTarget(el->sdl_renderer, NULL);
SDL_SetRenderDrawColor(el->sdl_renderer, 0, 0, 0, 255);
tmp_lst->content_size = hash;
tmp_lst->content = (void *)tmp;
ft_lstadd(&(el->sdl_textures), tmp_lst);
return (FUNCTION_SUCCESS);
}
int ui_el_add_white_texture(t_ui_el *el, int w, int h, const char *tid)
{
t_list_texture *tmp_lst;
SDL_Texture *tmp;
int hash;
hash = ft_strhash(tid);
tmp_lst = NULL;
tmp = NULL;
if (ctid(el->sdl_textures, hash) || !(tmp_lst = ft_lstnew(NULL, 0)))
ui_sdl_deinit(228);
if ((tmp = SDL_CreateTexture(el->sdl_renderer, SDL_PIXELFORMAT_RGBA8888,
SDL_TEXTUREACCESS_TARGET, w, h)) == NULL)
ui_sdl_deinit(228);
SDL_SetRenderTarget(el->sdl_renderer, tmp);
SDL_SetRenderDrawBlendMode(el->sdl_renderer, SDL_BLENDMODE_NONE);
SDL_SetRenderDrawColor(el->sdl_renderer, 255, 255, 255, 255);
SDL_SetTextureBlendMode(tmp, SDL_BLENDMODE_BLEND);
SDL_RenderFillRect(el->sdl_renderer, NULL);
SDL_SetRenderDrawBlendMode(el->sdl_renderer, SDL_BLENDMODE_BLEND);
SDL_SetRenderTarget(el->sdl_renderer, NULL);
SDL_SetRenderDrawColor(el->sdl_renderer, 0, 0, 0, 255);
tmp_lst->content_size = hash;
tmp_lst->content = (void *)tmp;
ft_lstadd(&(el->sdl_textures), tmp_lst);
return (FUNCTION_SUCCESS);
}
static void draw_line(t_vec2 wh, int color, t_ui_el *el)
{
int i;
i = -1;
while (++i < wh.x)
{
SDL_SetRenderDrawColor(el->sdl_renderer, ((color & 0xFF0000) >> 16)
* ((float)i / (float)wh.x), ((color & 0x00FF00) >> 8) * ((float)i
/ (float)wh.x), (color & 0x0000FF) * ((float)i / (float)wh.x), 255);
SDL_RenderDrawLine(el->sdl_renderer, i, 0, i, wh.y);
}
}
int ui_el_add_gradient_texture(t_ui_el *el, t_vec2 wh, int color,
const char *tid)
{
t_list_texture *tmp_lst;
SDL_Texture *tmp;
int hash;
hash = ft_strhash(tid);
tmp_lst = NULL;
tmp = NULL;
if (ctid(el->sdl_textures, hash) || !(tmp_lst = ft_lstnew(NULL, 0)) ||
(tmp = SDL_CreateTexture(el->sdl_renderer, SDL_PIXELFORMAT_RGBA8888,
SDL_TEXTUREACCESS_TARGET, wh.x, wh.y)) == NULL)
ui_sdl_deinit(228);
SDL_SetRenderTarget(el->sdl_renderer, tmp);
draw_line(wh, color, el);
SDL_SetRenderTarget(el->sdl_renderer, NULL);
SDL_SetRenderDrawColor(el->sdl_renderer, 0, 0, 0, 255);
tmp_lst->content_size = hash;
tmp_lst->content = (void *)tmp;
ft_lstadd(&(el->sdl_textures), tmp_lst);
return (FUNCTION_SUCCESS);
}
int ui_el_add_color_texture(t_ui_el *el, t_vec2 wh, int color,
const char *tid)
{
t_list_texture *tmp_lst;
SDL_Texture *tmp;
int hash;
hash = ft_strhash(tid);
tmp_lst = NULL;
tmp = NULL;
if (ctid(el->sdl_textures, hash) || !(tmp_lst = ft_lstnew(NULL, 0)))
ui_sdl_deinit(228);
if ((tmp = SDL_CreateTexture(el->sdl_renderer, SDL_PIXELFORMAT_RGBA8888,
SDL_TEXTUREACCESS_TARGET, wh.x, wh.y)) == NULL)
ui_sdl_deinit(228);
SDL_SetRenderTarget(el->sdl_renderer, tmp);
SDL_SetRenderDrawColor(el->sdl_renderer, (Uint8)((color & 0xFF0000) >> 16),
(Uint8)((color & 0x00FF00) >> 8), (Uint8)(color & 0x0000FF), 255);
SDL_RenderFillRect(el->sdl_renderer, NULL);
SDL_SetRenderTarget(el->sdl_renderer, NULL);
tmp_lst->content_size = hash;
tmp_lst->content = (void *)tmp;
ft_lstadd(&(el->sdl_textures), tmp_lst);
return (FUNCTION_SUCCESS);
}
|
dolovnyak/ray-marching-render | libui/src/ui_sdl/ui_sdl_texture.c | /* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ui_sdl_texture.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: sbecker <<EMAIL>> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/07/15 12:24:03 by sbecker #+# #+# */
/* Updated: 2019/07/15 12:24:07 by sbecker ### ########.fr */
/* */
/* ************************************************************************** */
#include "libui.h"
void ui_sdl_destroy_texture(SDL_Texture *t)
{
SDL_DestroyTexture(t);
}
SDL_Texture *ui_sdl_create_texture(SDL_Renderer *r, Uint32 f, int a, t_vec2 *s)
{
return (SDL_CreateTexture(r, f, a, s->x, s->y));
}
SDL_Texture *ui_sdl_create_texture_from_surface(SDL_Renderer *r, SDL_Surface *s)
{
return (SDL_CreateTextureFromSurface(r, s));
}
|
dolovnyak/ray-marching-render | include/rt_utilities.h | /* ************************************************************************** */
/* */
/* ::: :::::::: */
/* rt_rotations.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: sbecker <<EMAIL>> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/04/10 05:13:21 by sbecker #+# #+# */
/* Updated: 2019/07/03 20:16:18 by sbecker ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef RT_UTILITIES_H
# define RT_UTILITIES_H
# ifndef OPENCL___
# ifdef APPLE___
# include <OpenCL/opencl.h>
# else
# include <opencl.h>
# endif
# include "math.h"
# include "rt_rotations.h"
# include "transform.h"
# endif
void rotate_transform_around_axis(t_transform *t, cl_float3 a, float d);
#endif
|
dolovnyak/ray-marching-render | src/cl/pp/pp_blur_y.c | #include "rt_cl.h"
__kernel void pp_blur_y(
const __global int *input_data,
__global int *output_data,
int2 screen)
{
int tx = get_global_id(0);
int ty = get_global_id(1);
int index = ty * screen.x + tx;
float3 color;
int a = 3 * 2;
float sum = 0;
int coef;
color = (float3) 0;
for (int j = -a; j <= a; j++)
{
if (ty + j >= 0 && ty + j < screen.y)
{
coef = gauss_coeff_x(j, 2);
color += int_color(input_data[screen.x * (ty + j) + tx]) * coef;
sum += coef;
}
}
output_data[index] = get_color(color / sum);
}
|
dolovnyak/ray-marching-render | src/interface/button_selector.c | <reponame>dolovnyak/ray-marching-render
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* button_selector.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: edraugr- <<EMAIL>> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/09/26 14:15:06 by edraugr- #+# #+# */
/* Updated: 2019/09/26 14:15:43 by edraugr- ### ########.fr */
/* */
/* ************************************************************************** */
#include "interface.h"
int rt_uix_on_button_enter(t_ui_main *main, void *el_v)
{
t_ui_el *el;
(void)main;
el = (t_ui_el *)el_v;
if (el->current_texture != (size_t)ft_strhash(SELECTED_BUT_STATE))
ui_el_set_current_texture_by_id(el, HIGHLIGHTED_BUT_STATE);
return (1);
}
int rt_uix_on_button_exit(t_ui_main *main, void *el_v)
{
t_ui_el *el;
(void)main;
el = (t_ui_el *)el_v;
if (el->current_texture == (size_t)ft_strhash(HIGHLIGHTED_BUT_STATE))
ui_el_set_current_texture_by_id(el, DEFAULT_BUT_STATE);
return (1);
}
int rt_uix_button_choose(t_ui_main *main, void *el_v)
{
t_ui_el *el;
t_ui_el *tmp;
t_list *l;
(void)main;
el = (t_ui_el *)el_v;
l = el->parent->children;
if (el->current_texture == (size_t)ft_strhash(SELECTED_BUT_STATE))
return (1);
while (l)
{
tmp = (t_ui_el *)l->content;
if (tmp != el)
ui_el_set_current_texture_by_id(tmp, DEFAULT_BUT_STATE);
else
ui_el_set_current_texture_by_id(tmp, SELECTED_BUT_STATE);
l = l->next;
}
return (1);
}
int rt_uix_button_select(t_ui_main *main, void *el_v)
{
t_ui_el *el;
(void)main;
el = (t_ui_el *)el_v;
if (el->current_texture == (size_t)ft_strhash(SELECTED_BUT_STATE))
ui_el_set_current_texture_by_id(el, HIGHLIGHTED_BUT_STATE);
else
ui_el_set_current_texture_by_id(el, SELECTED_BUT_STATE);
return (1);
} |
dolovnyak/ray-marching-render | libui/src/ui_el/ui_el_utils_from_default_draw.c | <filename>libui/src/ui_el/ui_el_utils_from_default_draw.c<gh_stars>1-10
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ui_el_utils_from_default_draw.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: sbecker <<EMAIL>> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/07/15 07:40:42 by sbecker #+# #+# */
/* Updated: 2019/07/15 08:20:43 by sbecker ### ########.fr */
/* */
/* ************************************************************************** */
#include "libui.h"
void ui_el_texture_x_w(t_ui_el *e, t_rect *srect, t_rect *tmp_rect, int w)
{
if (e->rect.x < e->parent->crect.x && e->rect.x +
e->rect.w > e->parent->crect.x + e->parent->crect.w)
{
srect->x = roundf((float)(e->parent->crect.x - e->rect.x)
* ((float)w / e->rect.w));
srect->w = roundf((float)e->parent->crect.w * ((float)w / e->rect.w));
tmp_rect->x = e->parent->crect.x;
tmp_rect->w = e->parent->crect.w;
}
else if (e->rect.x < e->parent->crect.x)
{
tmp_rect->x = e->parent->crect.x;
tmp_rect->w = e->rect.w - (e->parent->crect.x - e->rect.x);
srect->x = roundf((float)(e->parent->crect.x - e->rect.x) *
((float)w / (float)e->rect.w));
srect->w = roundf((float)tmp_rect->w * ((float)w / (float)e->rect.w));
}
else if (e->rect.x + e->rect.w > e->parent->crect.x + e->parent->crect.w)
{
srect->x = 0;
tmp_rect->w = e->parent->crect.x + e->parent->crect.w - e->rect.x;
srect->w = roundf((float)tmp_rect->w * ((float)w / (float)e->rect.w));
tmp_rect->x = e->rect.x;
}
}
void ui_el_texture_y_h(t_ui_el *e, t_rect *srect, t_rect *tmp_rect, int h)
{
if (e->rect.y < e->parent->crect.y &&
e->rect.y + e->rect.h > e->parent->crect.y + e->parent->crect.h)
{
srect->y = roundf((float)(e->parent->crect.y - e->rect.y)
* ((float)h / (float)e->rect.h));
srect->h = roundf((float)e->parent->crect.h
* ((float)h / (float)e->rect.h));
tmp_rect->y = e->parent->crect.y;
tmp_rect->h = e->parent->crect.h;
}
else if (e->rect.y < e->parent->crect.y)
{
tmp_rect->y = e->parent->crect.y;
tmp_rect->h = e->rect.h - (e->parent->crect.y - e->rect.y);
srect->y = roundf((float)(e->parent->crect.y - e->rect.y)
* ((float)h / (float)e->rect.h));
srect->h = roundf((float)tmp_rect->h * ((float)h / (float)e->rect.h));
}
else if (e->rect.y + e->rect.h > e->parent->crect.y + e->parent->crect.h)
{
srect->y = 0;
tmp_rect->h = e->parent->crect.y + e->parent->crect.h - e->rect.y;
srect->h = roundf((float)tmp_rect->h * ((float)h / (float)e->rect.h));
tmp_rect->y = e->rect.y;
}
}
|
dolovnyak/ray-marching-render | src/rt_jtoc/rt_jtoc_get_textures.c | #include "rt.h"
#include "rt_jtoc.h"
static int rt_jtoc_get_texture_path(char **textures, t_jnode *n, int i)
{
t_jnode *tmp;
char *str;
if (!(tmp = jtoc_node_get_by_path(n, "path")) || tmp->type != string)
return (rt_jtoc_sdl_log_error("PATH ERROR OR PATH IS MISSING", -1));
str = jtoc_get_string(tmp);
textures[i] = ft_x_memalloc(ft_strlen(str) + 1);
ft_strcat(textures[i], str);
return (FUNCTION_SUCCESS);
}
int rt_jtoc_get_textures_by_path(t_obj_texture *texture, t_jnode *n)
{
t_jnode *tmp;
char **textures;
int i;
texture->textures_count = 0;
if (rt_jtoc_get_objects_num_in_arr(&texture->textures_count, n))
return (FUNCTION_FAILURE);
if (!(textures = (char **)ft_x_memalloc(sizeof(char*) * texture->textures_count)))
return (FUNCTION_FAILURE);
tmp = n->down;
i = 0;
while (tmp)
{
if (tmp->type != object)
return (rt_jtoc_sdl_log_error("STRING TYPE ERROR", i));
if (rt_jtoc_get_texture_path(textures, tmp, i))
return (FUNCTION_FAILURE);
i++;
tmp = tmp->right;
}
texture->textures_path = textures;
return (FUNCTION_SUCCESS);
}
int rt_jtoc_get_textures(const char *path, t_obj_texture *texture)
{
t_jnode *root;
t_jnode *tmp;
if (!(root = jtoc_read(path)))
return (rt_jtoc_sdl_log_error("JSON PATH ERROR", -1));
if (!(tmp = jtoc_node_get_by_path(root, "textures")) || tmp->type != array)
return (rt_jtoc_sdl_log_error("TEXTURE TYPE ERROR OR TEXTURE IS MISSING", -1));
if (rt_jtoc_get_textures_by_path(texture, tmp))
return (rt_jtoc_sdl_log_error("SYKA ERROR", -1));
jtoc_node_clear(root);
return (FUNCTION_SUCCESS);
}
int rt_jtoc_textures_setup(t_rt_main *rt, const char *json)
{
int i;
t_obj_texture *texture;
if (!(texture = (t_obj_texture *)ft_x_memalloc(sizeof(t_obj_texture))))
return (FUNCTION_FAILURE);
i = -1;
if (rt_jtoc_get_textures(json, texture))
{
rt_jtoc_sdl_log_error("TEXTURE ERROR", i);
exit(-1);
}
rt->texture = texture;
return (FUNCTION_SUCCESS);
} |
dolovnyak/ray-marching-render | libui/src/ui_jtoc/ui_jtoc_el_pref_modal_win.c | /* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ui_jtoc_el_pref_modal_win.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: sbecker <<EMAIL>> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/07/12 06:56:23 by sbecker #+# #+# */
/* Updated: 2019/07/15 14:36:08 by sbecker ### ########.fr */
/* */
/* ************************************************************************** */
#include "libui.h"
static int get_win_params(t_ui_win *w, t_jnode *n)
{
int type;
t_jnode *tmp;
if ((tmp = jtoc_node_get_by_path(n, "modal_win.type")) &&
tmp->type == string)
{
type = ft_strcmp(jtoc_get_string(tmp), "OK") ? 0 : 1;
type = ft_strcmp(jtoc_get_string(tmp), "OK_CANCEL") ? type : 2;
}
if ((tmp = jtoc_node_get_by_path(n, "modal_win.win_id"))
&& ui_jtoc_isnum(tmp->type))
w->id = jtoc_get_int(tmp);
else
return (0);
if ((tmp = jtoc_node_get_by_path(n, "modal_win.title")) &&
tmp->type == string)
w->title = ft_strdup(jtoc_get_string(tmp));
else
return (0);
w->pos.x = SDL_WINDOWPOS_CENTERED;
w->pos.y = SDL_WINDOWPOS_CENTERED;
return (type);
}
int ui_jtoc_el_pref_modal_win(t_ui_main *m, t_ui_el *e, t_jnode *n)
{
int type;
t_jnode *tmp;
t_ui_win *w;
t_ui_text ui_text;
(void)m;
if ((tmp = jtoc_node_get_by_path(n, "modal_win")))
{
w = ui_win_init();
if ((type = get_win_params(w, n)) == 0)
return (FUNCTION_FAILURE);
if (ui_jtoc_pref_text_modal_win(m, tmp, &ui_text) == FUNCTION_FAILURE)
return (FUNCTION_FAILURE);
if (type == 1)
ui_jtoc_create_modal_ok(m, w, &ui_text);
else if (type == 2)
ui_jtoc_create_modal_ok_cancel(m, w, &ui_text);
e->modal_win = w;
ui_event_add_listener(e->events->on_pointer_left_button_pressed,
ui_el_event_show_window);
}
return (FUNCTION_SUCCESS);
}
|
dolovnyak/ray-marching-render | src/rt_setup.c | #include "rt.h"
#include "rt_jtoc.h"
#include "rt_pp.h"
static void fill_constant_screen_gpu_mem(t_rt_main *rt, cl_int2 screen_size)
{
rt->gpu_mem = (t_s_gpu_mem *)ft_x_memalloc(sizeof(t_s_gpu_mem));
rt->gpu_mem->cl_image = clCreateBuffer(*rt->cl->context,
CL_MEM_READ_WRITE, sizeof(int) * screen_size.x * screen_size.y,
NULL, NULL);
rt->gpu_mem->cl_aux = clCreateBuffer(*rt->cl->context,
CL_MEM_READ_WRITE, sizeof(int) * screen_size.x * screen_size.y,
NULL, NULL);
find_textures_size(rt, rt->texture->textures_path, rt->texture->textures_count);
if (!(rt->texture->texture = (int *)ft_memalloc(sizeof(int) * rt->texture->texture_size)))
return ;
get_textures(rt, rt->texture->textures_path, rt->texture->textures_count);
rt->gpu_mem->cl_texture = clCreateBuffer(*rt->cl->context,
CL_MEM_READ_ONLY, 4 * rt->texture->texture_size,
NULL, NULL);
rt->gpu_mem->cl_pt_color_buf = clCreateBuffer(*rt->cl->context,
CL_MEM_READ_WRITE, sizeof(cl_float3) * screen_size.x * screen_size.y,
NULL, NULL);
clEnqueueWriteBuffer(*rt->cl->queue, rt->gpu_mem->cl_texture, CL_TRUE, 0,
4 * rt->texture->texture_size,
rt->texture->texture, 0, NULL, NULL);
rt->gpu_mem->cl_texture_w = clCreateBuffer(*rt->cl->context,
CL_MEM_READ_ONLY, sizeof(int) * 100, NULL, NULL);
clEnqueueWriteBuffer(*rt->cl->queue, rt->gpu_mem->cl_texture_w, CL_TRUE, 0,
sizeof(int) * 100, &rt->texture->texture_w, 0, NULL, NULL);
rt->gpu_mem->cl_texture_h = clCreateBuffer(*rt->cl->context,
CL_MEM_READ_ONLY, sizeof(int) * 100, NULL, NULL);
clEnqueueWriteBuffer(*rt->cl->queue, rt->gpu_mem->cl_texture_h, CL_TRUE, 0,
sizeof(int) * 100, &rt->texture->texture_h, 0, NULL, NULL);
rt->gpu_mem->cl_prev_texture_size = clCreateBuffer(*rt->cl->context,
CL_MEM_READ_ONLY, sizeof(int) * 100, NULL, NULL);
clEnqueueWriteBuffer(*rt->cl->queue, rt->gpu_mem->cl_prev_texture_size, CL_TRUE, 0,
sizeof(int) * 100, &rt->texture->prev_texture_size, 0, NULL, NULL);
}
t_rt_main *rt_setup(cl_int2 screen_size,
const char *textures_path,
const char *scene_path)
{
t_rt_main *rt;
rt = (t_rt_main *)ft_memalloc(sizeof(t_rt_main));
rt->screen_size = screen_size;
rt->cl = cl_setup((char *[]){
"src/cl/render.cl",
"src/cl/raymarch.cl",
"src/cl/sdf.cl",
"src/cl/get_lighting.cl",
"src/cl/get_cam_ray_direction.cl",
"src/cl/uv_mapping.cl",
NULL},
(char *[]){"ray_march_render", NULL}, NULL);
cl_setup((char *[]){
"src/cl/pp/pp_monochrome.c",
"src/cl/pp/pp_anaglyph.c",
"src/cl/pp/pp_utilities.c",
"src/cl/pp/pp_blur_x.c",
"src/cl/pp/pp_blur_y.c",
"src/cl/pp/pp_dithering.c",
NULL},
(char *[]){
"pp_anaglyph", "pp_monochrome", "pp_dithering", "pp_blur_x", "pp_blur_y",
NULL}, rt->cl);
rt->pp = vec_init(10, sizeof(t_ppnode));
// vec_push_back(rt->pp, cl_get_kernel_by_name(rt->cl, "pp_monochrome"));
// vec_push_back(rt->pp, cl_get_kernel_by_name(rt->cl, "pp_dithering"));
// vec_push_back(rt->pp, cl_get_kernel_by_name(rt->cl, "pp_anaglyph"));
// vec_push_back(rt->pp, cl_get_kernel_by_name(rt->cl, "pp_blur_x"));
// vec_push_back(rt->pp, cl_get_kernel_by_name(rt->cl, "pp_blur_y"));
rt_jtoc_textures_setup(rt, textures_path);
rt_jtoc_scene_setup(rt, scene_path);
fill_constant_screen_gpu_mem(rt, screen_size);
return (rt);
}
|
dolovnyak/ray-marching-render | libui/src/ui_el/ui_el_update_text.c | <reponame>dolovnyak/ray-marching-render
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ui_el_update_text.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: edraugr- <<EMAIL>> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/05/23 05:38:20 by sbednar #+# #+# */
/* Updated: 2019/07/15 08:16:24 by sbecker ### ########.fr */
/* */
/* ************************************************************************** */
#include "libui.h"
static int get_surface_from_text(t_ui_el *el)
{
if (el->sdl_surface != NULL)
{
SDL_FreeSurface(el->sdl_surface);
el->sdl_surface = NULL;
}
if (el->text_area->render_param & TEXT_IS_SOLID)
{
if (!(el->sdl_surface = TTF_RenderText_Solid(el->text_area->font,
el->text_area->text, el->text_area->text_color)))
return (FUNCTION_FAILURE);
}
else if ((el->text_area->render_param & TEXT_IS_BLENDED)
|| el->text_area->render_param == 0)
{
if (!(el->sdl_surface = TTF_RenderText_Blended(el->text_area->font,
el->text_area->text, el->text_area->text_color)))
return (FUNCTION_FAILURE);
}
else if (!(el->sdl_surface = TTF_RenderText_Shaded(el->text_area->font,
el->text_area->text, el->text_area->text_color,
el->text_area->bg_color)))
return (FUNCTION_FAILURE);
return (FUNCTION_SUCCESS);
}
static void clear_el_text(t_ui_el *el)
{
if (el->text_area->text != NULL)
free(el->text_area->text);
el->text_area->text = NULL;
}
static void get_texture(t_ui_el *el)
{
SDL_Rect rect;
t_list *n;
ui_el_remove_texture_by_id(el, "default");
if (get_surface_from_text(el))
ui_el_add_empty_texture(el, el->rect.w, el->rect.h, "default");
else
{
SDL_GetClipRect(el->sdl_surface, &rect);
if (rect.w > 16384 || rect.h > 4000)
return ;
if (!(n = ft_lstnew(NULL, 0)))
ui_sdl_deinit(228);
n->content = ui_el_create_texture(el);
n->content_size = ft_strhash("default");
ft_lstadd(&(el->sdl_textures), n);
}
}
int ui_el_update_text(t_ui_el *el, const char *text)
{
size_t len;
if (text == NULL)
return (FUNCTION_SUCCESS);
len = ft_strlen(text);
if (el->text_area->string_len == 0 || len <= el->text_area->string_len)
{
clear_el_text(el);
el->text_area->text = ft_strdup(text);
}
else
{
if (el->text_area->text != NULL)
return (FUNCTION_SUCCESS);
else
{
clear_el_text(el);
el->text_area->text = ft_strsub(text, 0, el->text_area->string_len);
}
}
get_texture(el);
return (FUNCTION_SUCCESS);
}
|
dolovnyak/ray-marching-render | src/interface/rt_uix_update_inspector.c | /* ************************************************************************** */
/* */
/* ::: :::::::: */
/* rt_uix_update_inspector.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: edraugr- <<EMAIL>> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/10/05 15:28:07 by edraugr- #+# #+# */
/* Updated: 2019/10/05 15:28:10 by edraugr- ### ########.fr */
/* */
/* ************************************************************************** */
#include "interface.h"
static void update_transform_pos(t_object *obj, t_ui_win *win)
{
t_ui_el *tmp;
char *new_val;
new_val = malloc(8);
tmp = ui_win_find_el_by_id(win, 42120);
sprintf(new_val, "%03.3f", obj->transform.pos.x);
ui_el_update_text(tmp, new_val);
tmp = ui_win_find_el_by_id(win, 42220);
sprintf(new_val, "%03.3f", obj->transform.pos.y);
ui_el_update_text(tmp, new_val);
tmp = ui_win_find_el_by_id(win, 42320);
sprintf(new_val, "%03.3f", obj->transform.pos.z);
ui_el_update_text(tmp, new_val);
free(new_val);
}
void rt_uix_update_inspector_values(t_ui_main *m)
{
t_object *obj;
t_ui_win *win;
win = ui_main_find_window_by_id(m, 1);
t_ui_el *el = ui_win_find_el_by_id(win, INSPECTOR_EL_ID);
obj = (t_object *)(el->data);
if (!obj)
return ;
update_transform_pos(obj, win);
} |
dolovnyak/ray-marching-render | libui/src/ui_el/ui_el_setup_default_scroll_menu.c | <gh_stars>1-10
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ui_el_setup_default_scroll_menu.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: sbecker <<EMAIL>> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/05/20 01:15:33 by sbecker #+# #+# */
/* Updated: 2019/07/15 14:48:12 by sbecker ### ########.fr */
/* */
/* ************************************************************************** */
#include "libui.h"
static void ui_el_setup_default_scroll_menu_logs(t_ui_el *el)
{
ui_event_add_listener(el->events->on_scroll_down, ui_log_el_scroll_down);
ui_event_add_listener(el->events->on_scroll_up, ui_log_el_scroll_up);
}
void ui_el_setup_default_scroll_menu(t_ui_el *el)
{
el->params |= EL_IS_SCROLLABLE;
ui_event_add_listener(el->events->on_scroll_up, ui_el_event_scroll_menu_up);
ui_event_add_listener(el->events->on_scroll_down,
ui_el_event_scroll_menu_down);
if (DEBUG_STATUS == 1)
ui_el_setup_default_scroll_menu_logs(el);
}
|
dolovnyak/ray-marching-render | libui/src/ui_jtoc/ui_jtoc_create_modal_ok.c | /* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ui_jtoc_create_modal_ok.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: sbecker <<EMAIL>> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/07/14 08:43:03 by sbecker #+# #+# */
/* Updated: 2019/07/15 15:11:50 by sbecker ### ########.fr */
/* */
/* ************************************************************************** */
#include "libui.h"
static void create_ok_button(t_ui_el *p, t_ui_text *ui_text, t_ui_win *w)
{
t_ui_el *el;
t_ui_el *el_text;
el = ui_el_init();
el->id = 2;
ui_el_add_child(p, el);
ui_el_set_pos(el, PIXEL, (t_fvec2){0.5 * p->rect.w - 100, p->rect.h - 90});
ui_el_set_size(el, PIXEL, (t_fvec2){200, 65});
ui_el_add_color_texture(el, (t_vec2){el->rect.w, el->rect.h},
ft_atoi_base("AAAAAA", 16), "default");
ui_el_setup_default(el);
el->modal_win = w;
ui_event_add_listener(el->events->on_pointer_left_button_pressed,
ui_el_event_close_window);
el_text = ui_el_init();
el_text->id = 3;
ui_el_add_child(el, el_text);
ui_el_set_pos(el_text, 0, (t_fvec2){0.3, 0});
ui_el_set_size(el_text, 0, (t_fvec2){0.4, 1});
ui_el_set_text(el_text, ui_text->font, (t_text_params){(SDL_Color)
{0, 0, 0, 0}, (SDL_Color){0, 0, 0, 0}, 0, 0, TEXT_IS_BLENDED});
ui_el_update_text(el_text, "OK");
ui_el_setup_default(el_text);
el_text->params |= EL_IGNOR_RAYCAST;
}
static void fill_modal_ok(t_ui_text *ui_text, t_ui_el *p,
char **text, t_ui_win *w)
{
t_ui_el *el;
int i;
float y;
i = 0;
y = 10;
create_ok_button(p, ui_text, w);
while (text[i])
{
el = ui_el_init();
el->id = i + 5;
el->params |= EL_IS_DEPENDENT;
ui_el_add_child(p, el);
ui_el_set_pos(el, PIXEL, (t_fvec2){150, y});
ui_el_set_size(el, PIXEL, (t_fvec2){p->rect.w - 150, 40});
y += 45;
ui_el_set_text(el, ui_text->font,
(t_text_params){(SDL_Color){0, 0, 0, 0}, (SDL_Color){170, 170,
170, 0}, 0, TEXT_IS_REGULAR | ui_text->params, TEXT_IS_SOLID});
ui_el_update_text(el, text[i]);
ui_el_setup_default(el);
free(text[i++]);
}
free(text);
}
void ui_jtoc_create_modal_ok(t_ui_main *m, t_ui_win *w,
t_ui_text *ui_text)
{
char **text;
size_t num_strs;
t_ui_el *win_el;
text = ft_strsplit_on_size(ui_text->text, ui_text->string_len, &num_strs);
w->size.x = 300 + ui_text->string_len * 16;
w->size.y = num_strs * 45 + 120;
free(ui_text->text);
ui_event_add_listener(w->events->on_close, ui_main_event_close_window);
ui_event_add_listener(w->events->on_key_down[SDL_SCANCODE_ESCAPE],
ui_main_event_close_window);
ui_win_setup_default(w);
ui_win_create(w, SDL_WINDOW_SHOWN);
w->params |= WIN_IS_HIDDEN;
win_el = ui_el_init();
win_el->id = 1;
ui_el_setup_default(win_el);
ui_el_add_child(w->canvas, win_el);
ui_el_set_pos(win_el, 0, (t_fvec2){0, 0});
ui_el_set_size(win_el, 0, (t_fvec2){1, 1});
ui_el_add_color_texture(win_el, (t_vec2){win_el->rect.w, win_el->rect.h},
ft_atoi_base("757575", 16), "default");
fill_modal_ok(ui_text, win_el, text, w);
ui_main_add_window(m, w);
}
|
dolovnyak/ray-marching-render | src/rt_sdf.c | <filename>src/rt_sdf.c
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* rt_sdf.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: sbecker <<EMAIL>> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/04/10 05:13:21 by sbecker #+# #+# */
/* Updated: 2019/07/03 20:16:18 by sbecker ### ########.fr */
/* */
/* ************************************************************************** */
#include "rt_raycast.h"
static cl_float3 f3abs(cl_float3 v)
{
return (cl_float3){{fabs(v.x), fabs(v.y), fabs(v.z)}};
}
static cl_float3 f3max(cl_float3 v1, cl_float3 v2)
{
return (cl_float3){{fmax(v1.x, v2.x), fmax(v1.y, v2.y), fmax(v1.z, v2.z)}};
}
//static cl_float3 f3min(cl_float3 v1, cl_float3 v2)
//{
// return (cl_float3){{fmin(v1.x, v2.x), fmin(v1.y, v2.y), fmin(v1.z, v2.z)}};
//}
static float f2dot(cl_float2 v1, cl_float2 v2)
{
return v1.x * v2.x + v1.y * v2.y;
}
float f3dot(cl_float3 v1, cl_float3 v2)
{
return v1.x * v2.x + v1.y * v2.y + v1.z * v2.z;
}
static float f2len(cl_float2 v)
{
return sqrt(v.x * v.x + v.y * v.y);
}
float f3len(cl_float3 v)
{
return sqrt(v.x * v.x + v.y * v.y + v.z * v.z);
}
cl_float3 f3cross(cl_float3 v1, cl_float3 v2)
{
return (cl_float3){{v1.z * v2.y - v1.y * v2.z, v1.x * v2.z - v1.z * v2.x, v1.x * v2.y - v1.y * v2.x}};
}
static cl_float2 f2norm(cl_float2 v)
{
float n = f2len(v);
return (cl_float2){{v.x / n, v.y / n}};
}
cl_float3 f3norm(cl_float3 v)
{
float len;
len = f3len(v);
if (len > RM_FLT_EPSILON)
v.v4 /= f3len(v);
return v;
}
float sdf_sphere(cl_float3 pos, float radius)
{
return f3len(pos) - radius;
}
float sdf_box(cl_float3 pos, cl_float3 bounds)
{
cl_float3 d = f3abs(pos);
d.v4 -= bounds.v4;
return f3len(f3max(d, (cl_float3){{0, 0, 0}})) + fmin(fmax(d.x, fmax(d.y, d.z)), 0);
}
float sdf_round_box(cl_float3 pos, cl_float3 bounds, float r)
{
cl_float3 d = f3abs(pos);
d.v4 -= bounds.v4;
return f3len(f3max(d, (cl_float3){{0, 0, 0}})) - r + fmin(fmax(d.x, fmax(d.y, d.z)), 0);
}
float sdf_torus(cl_float3 pos, cl_float radius, cl_float inner_radius)
{
cl_float2 q = (cl_float2){{f2len((cl_float2){{pos.x, pos.z}}) - radius, pos.y}};
return f2len(q) - inner_radius;
}
float sdf_capped_torus(cl_float3 pos, cl_float2 sc, float ra, float rb)
{
pos.x = fabs(pos.x);
float k = (sc.y * pos.x > sc.x * pos.y) ? f2dot((cl_float2){{pos.x, pos.y}}, sc) : f2len((cl_float2){{pos.x, pos.y}});
return sqrt(f3dot(pos, pos) + ra * ra - 2.0f * ra * k) - rb;
}
float sdf_link(cl_float3 pos, float le, float r1, float r2)
{
cl_float3 q = (cl_float3){{pos.x, fmax(fabs(pos.y) - le, 0.0f), pos.z}};
return f2len((cl_float2){{f2len((cl_float2){{q.x, q.y}}) - r1, q.z}}) - r2;
}
float sdf_cylinder(cl_float3 pos, cl_float3 c)
{
return f2len((cl_float2){{pos.x - c.x, pos.y - c.y}}) - c.z;
}
float sdf_cone(cl_float3 pos, cl_float2 c)
{
float q = f2len((cl_float2){{pos.x, pos.y}});
return f2dot(f2norm(c), (cl_float2){{q, pos.z}});
}
float sdf_plane(cl_float3 pos, cl_float3 n, float d)
{
return f3dot(pos, n) + d;
} |
dolovnyak/ray-marching-render | src/rt_render.c | <filename>src/rt_render.c<gh_stars>1-10
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* rt_render.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: sbecker <<EMAIL>> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/07/23 17:50:06 by sbecker #+# #+# */
/* Updated: 2019/07/23 17:50:07 by sbecker ### ########.fr */
/* */
/* ************************************************************************** */
#include "rt.h"
int rt_render(t_ui_main *ui, void *el_v)
{
t_rt_main *rt;
t_ui_el *el;
void *pixels;
int pitch;
size_t global_size[2];
static int start_flag;
static cl_int path_trace_count = 1;
el = (t_ui_el *)el_v;
SDL_Log("count: %d", path_trace_count);
rt = ui->data;
if (!(rt->scene->params & RT_PATH_TRACE))
{
// if (!((t_physics_system *) rt->systems[1])->change_indicator && start_flag != 0)
// return (1);
}
else if (!((t_physics_system *) rt->systems[1])->change_indicator && start_flag != 0)
path_trace_count++;
else
{
path_trace_count = 1;
}
start_flag = 1;
rt->screen_size.x = el->rect.w;
rt->screen_size.y = el->rect.h;
global_size[0] = rt->screen_size.x;
global_size[1] = rt->screen_size.y;
render_processing(rt, global_size, path_trace_count);
post_processing(rt);
SDL_LockTexture(el->sdl_textures->content, NULL, &pixels, &pitch);
if (rt->pp)
clEnqueueReadBuffer(*rt->cl->queue,
rt->pp->size % 2 ? rt->gpu_mem->cl_aux : rt->gpu_mem->cl_image,
CL_TRUE, 0, el->rect.h * pitch, pixels, 0, NULL, NULL);
else
clEnqueueReadBuffer(*rt->cl->queue, rt->gpu_mem->cl_image, CL_TRUE, 0,
el->rect.h * pitch, pixels, 0, NULL, NULL);
SDL_UnlockTexture(el->sdl_textures->content);
SDL_RenderCopy(el->sdl_renderer, el->sdl_textures->content, NULL, NULL);
return (1);
}
int rt_render_update(t_ui_main *ui, void *el_v)
{
t_rt_main *rt;
t_ui_el *el;
void *pixels;
int pitch;
size_t global_size[2];
static int start_flag;
static cl_int path_trace_count = 1;
el = (t_ui_el *)el_v;
rt = ui->data;
if (!(rt->scene->params & RT_PATH_TRACE))
{
}
else if (!((t_physics_system *) rt->systems[1])->change_indicator && start_flag != 0)
path_trace_count++;
else
{
path_trace_count = 1;
}
start_flag = 1;
rt->screen_size.x = el->rect.w;
rt->screen_size.y = el->rect.h;
global_size[0] = rt->screen_size.x;
global_size[1] = rt->screen_size.y;
render_processing(rt, global_size, path_trace_count);
post_processing(rt);
SDL_LockTexture(el->sdl_textures->content, NULL, &pixels, &pitch);
if (rt->pp)
clEnqueueReadBuffer(*rt->cl->queue,
rt->pp->size % 2 ? rt->gpu_mem->cl_aux : rt->gpu_mem->cl_image,
CL_TRUE, 0, el->rect.h * pitch, pixels, 0, NULL, NULL);
else
clEnqueueReadBuffer(*rt->cl->queue, rt->gpu_mem->cl_image, CL_TRUE, 0,
el->rect.h * pitch, pixels, 0, NULL, NULL);
SDL_UnlockTexture(el->sdl_textures->content);
SDL_RenderCopy(el->sdl_renderer, el->sdl_textures->content, NULL, NULL);
return (1);
}
|
dolovnyak/ray-marching-render | include/rt_camera.h | /* ************************************************************************** */
/* */
/* ::: :::::::: */
/* rt_camera.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: sbecker <<EMAIL>> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/04/10 05:13:21 by sbecker #+# #+# */
/* Updated: 2019/07/03 20:16:18 by sbecker ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef RT_CAMERA_H
# define RT_CAMERA_H
# ifndef OPENCL___
# ifdef APPLE___
# include <OpenCL/opencl.h>
# else
# include <opencl.h>
# endif
# include "libui.h"
# include "rt_physics_system.h"
# endif
# include "transform.h"
# define CAMERA_ID 1
typedef struct s_clipping
{
# ifndef OPENCL___
cl_float near;
cl_float far;
#else
float near;
float far;
#endif
} t_clipping;
typedef struct s_camera
{
t_transform transform;
t_clipping clipping_planes;
# ifndef OPENCL___
cl_float fov;
# else
float fov;
# endif
} t_camera;
#endif
|
dolovnyak/ray-marching-render | include/rt_input_system.h | /* ************************************************************************** */
/* */
/* ::: :::::::: */
/* rt_input.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: sbecker <<EMAIL>> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/04/10 05:13:21 by sbecker #+# #+# */
/* Updated: 2019/07/03 20:16:18 by sbecker ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef RT_INPUT_H
# define RT_INPUT_H
# include "rt.h"
typedef struct s_input_system
{
t_system system;
const Uint8 *state;
t_rb *active;
t_transform *selected;
} t_input_system;
void move_active(t_input_system *s);
void rotate_active(t_input_system *s);
void change_selected(t_input_system *s, t_object *o);
int is_func(void *isv);
#endif
|
dolovnyak/ray-marching-render | libui/src/ui_jtoc/ui_jtoc_efj_helper2.c | /* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ui_jtoc_efj_helper2.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: sbecker <<EMAIL>> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/07/15 07:23:40 by edraugr- #+# #+# */
/* Updated: 2019/07/15 15:13:47 by sbecker ### ########.fr */
/* */
/* ************************************************************************** */
#include "libui.h"
static int ui_el_from_json_texture2(t_ui_el *e, t_jnode *n, t_jnode *t)
{
if (t->type != string ||
(!ft_strcmp(jtoc_get_string(t), "empty") &&
ui_el_from_json_empty_texture(e, n)) || (!ft_strcmp(
jtoc_get_string(t), "white") && ui_el_from_json_white_texture(
e, n)) || (!ft_strcmp(jtoc_get_string(t), "color") &&
ui_el_from_json_color_texture(e, n)) || (!ft_strcmp(
jtoc_get_string(t), "gradient") &&
ui_el_from_json_gradient_texture(e, n)))
return (ui_jtoc_sdl_log_error("NODE EL (TEXTURE TYPE)", e->id));
return (FUNCTION_SUCCESS);
}
int ui_el_from_json_texture(t_ui_main *m, t_ui_el *e, t_jnode *n)
{
t_jnode *t;
char *mi;
char *ei;
if ((t = jtoc_node_get_by_path(n, "type")))
{
if (ui_el_from_json_texture2(e, n, t))
return (FUNCTION_FAILURE);
}
else
{
if (!(t = jtoc_node_get_by_path(n, "main_id")) ||
!(mi = jtoc_get_string(t)) || t->type != string ||
!(t = jtoc_node_get_by_path(n, "el_id")) || t->type != string ||
!(ei = jtoc_get_string(t)))
return (ui_jtoc_sdl_log_error("NODE EL (TEXTURE)", e->id));
ui_el_add_texture_from_main_by_id(m, e, mi, ei);
}
return (FUNCTION_SUCCESS);
}
t_ui_event *ui_jtoc_el_from_json_get_event_by_name(t_ui_el *e, const char *n)
{
int h;
t_ui_event *r;
h = ft_strhash(n);
r = NULL;
r = (h == ft_strhash("onPointerEnter") ? e->events->on_pointer_enter : r);
r = (h == ft_strhash("onPointerStay") ? e->events->on_pointer_stay : r);
r = (h == ft_strhash("onPointerExit") ? e->events->on_pointer_exit : r);
r = (h == ft_strhash("onPointerLeftButtonPressed") ?
e->events->on_pointer_left_button_pressed : r);
r = (h == ft_strhash("onPointerLeftButtonHold") ?
e->events->on_pointer_left_button_hold : r);
r = (h == ft_strhash("onPointerLeftButtonReleased") ?
e->events->on_pointer_left_button_released : r);
r = (h == ft_strhash("onPointerRightButtonPressed") ?
e->events->on_pointer_right_button_pressed : r);
r = (h == ft_strhash("onPointerRightButtonHold") ?
e->events->on_pointer_right_button_hold : r);
r = (h == ft_strhash("onPointerRightButtonReleased") ?
e->events->on_pointer_right_button_released : r);
r = (h == ft_strhash("onScrollUp") ? e->events->on_scroll_up : r);
r = (h == ft_strhash("onScrollDown") ? e->events->on_scroll_down : r);
r = (h == ft_strhash("onRender") ? e->events->on_render : r);
r = (h == ft_strhash("onResize") ? e->events->on_resize : r);
return (r);
}
int ui_el_from_json_event(t_ui_main *m, t_ui_el *e, t_jnode *n)
{
char *event_name;
char *f_n;
t_ui_event *ev;
t_pred_ptr_event f;
t_jnode *tmp;
if (n->type != object ||
!(tmp = jtoc_node_get_by_path(n, "event_name")) ||
tmp->type != string || !(event_name = jtoc_get_string(tmp)) ||
!(ev = ui_jtoc_el_from_json_get_event_by_name(e, event_name)) ||
!(tmp = jtoc_node_get_by_path(n, "func_name")) || tmp->type != string ||
!(f_n = jtoc_get_string(tmp)) ||
(ft_strcmp(f_n, "clear") && !(f = ui_main_get_function_by_id(m, f_n))))
return (ui_jtoc_sdl_log_error("NODE EL (EVENT)", e->id));
if (!ft_strcmp(f_n, "clear"))
ui_event_clear(ev);
else
ui_event_add_listener(ev, f);
return (FUNCTION_SUCCESS);
}
int ui_el_from_json_events(t_ui_main *m, t_ui_el *e, t_jnode *n)
{
t_jnode *tmp;
if ((tmp = jtoc_node_get_by_path(n, "events")))
{
tmp = tmp->down;
while (tmp)
{
if (tmp->type != object || ui_el_from_json_event(m, e, tmp))
ui_sdl_deinit(228);
tmp = tmp->right;
}
}
return (ui_el_from_json_cursor(m, e, n));
}
|
dolovnyak/ray-marching-render | src/interface/uix_function_list.c | <gh_stars>1-10
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ui_function_list.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: edraugr- <<EMAIL>> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/09/26 14:34:17 by edraugr- #+# #+# */
/* Updated: 2019/09/26 14:34:20 by edraugr- ### ########.fr */
/* */
/* ************************************************************************** */
#include "interface.h"
void rt_uix_add_functions(t_ui_main *m)
{
ui_main_add_function_by_id(m, rt_uix_on_button_enter, "on_button_enter");
ui_main_add_function_by_id(m, rt_uix_on_button_exit, "on_button_exit");
ui_main_add_function_by_id(m, rt_uix_button_choose, "button_choose");
ui_main_add_function_by_id(m, rt_uix_button_select, "button_select");
ui_main_add_function_by_id(m, rt_uix_choose_none, "choose_none");
ui_main_add_function_by_id(m, rt_uix_choose_path_trace, "choose_path_trace");
ui_main_add_function_by_id(m, rt_uix_choose_pong, "choose_pong");
ui_main_add_function_by_id(m, rt_uix_show_menu, "show_menu");
ui_main_add_function_by_id(m, rt_uix_inspector_pos_button, "change_obj_pos");
ui_main_add_function_by_id(m, rt_uix_inspector_rot_button, "change_obj_rot");
ui_main_add_function_by_id(m, rt_uix_switch_blur, "pp_blur");
ui_main_add_function_by_id(m, rt_uix_switch_monochrome, "pp_monochrome");
ui_main_add_function_by_id(m, rt_uix_switch_anaglyph, "pp_anaglyph");
ui_main_add_function_by_id(m, rt_uix_switch_dithering, "pp_dithering");
ui_main_add_function_by_id(m, rt_uix_clear_pp, "pp_clear");
}
|
dolovnyak/ray-marching-render | libui/src/ui_main/ui_main_event_close_window.c | <filename>libui/src/ui_main/ui_main_event_close_window.c
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ui_main_event_closing_windows.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: sbecker <<EMAIL>> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/07/12 05:12:51 by sbecker #+# #+# */
/* Updated: 2019/07/15 11:55:22 by sbecker ### ########.fr */
/* */
/* ************************************************************************** */
#include "libui.h"
int ui_main_event_close_window(t_ui_main *m, void *a)
{
t_ui_win *w;
t_ui_win *cur_w;
t_list *cur;
t_list *prev;
w = (t_ui_win *)a;
prev = NULL;
cur = m->windows;
while (cur)
{
cur_w = (t_ui_win *)(cur->content);
if (w->id == cur_w->id)
{
SDL_HideWindow(w->sdl_window);
return (1);
}
prev = cur;
cur = cur->next;
}
return (1);
}
int ui_main_event_close_program(t_ui_main *m, void *a)
{
(void)a;
m->params |= MAIN_ON_QUIT;
ui_sdl_deinit(EXIT_SUCCESS);
return (0);
}
|
dolovnyak/ray-marching-render | libft/src/ft_strsplit_on_size.c | <gh_stars>1-10
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strsplit_on_size.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: sbecker <<EMAIL>> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/07/09 01:35:42 by sbecker #+# #+# */
/* Updated: 2019/07/10 15:28:18 by sbednar ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
#include <stdio.h>
static size_t *get_lens_arr(const char *s, size_t num_words)
{
size_t *len_arr;
size_t i;
size_t j;
len_arr = (size_t *)ft_memalloc(sizeof(size_t) * num_words);
i = -1;
j = -1;
while (s[++i])
{
if (s[i] != ' ')
{
len_arr[++j] = ft_wordlen(&s[i], ' ');
i += len_arr[j];
}
if (!s[i])
break ;
}
return (len_arr);
}
static size_t *num_join_free(size_t *arr, size_t num, size_t size)
{
size_t *tmp_arr;
size_t i;
if (size == 1)
{
arr = (size_t *)malloc(sizeof(size_t));
arr[0] = num;
return (arr);
}
i = -1;
tmp_arr = arr;
arr = (size_t *)malloc(sizeof(size_t) * size);
while (++i < size - 1)
arr[i] = tmp_arr[i];
arr[i] = num;
if (tmp_arr)
free(tmp_arr);
return (arr);
}
static size_t *get_nwiss(size_t *len_arr,
size_t num_word, size_t s_len, size_t *num_strs)
{
size_t *nwiss;
size_t i;
size_t len;
size_t nwis;
i = -1;
len = 0;
nwis = 0;
nwiss = NULL;
while (++i < num_word)
if ((len += len_arr[i] + 1) <= s_len + 1)
((++nwis && i + 1 == num_word) ?
nwiss = num_join_free(nwiss, nwis, ++(*num_strs)) : 0);
else
{
len = 0;
if (++(*num_strs) && nwis == 0)
nwiss = num_join_free(nwiss, 1, *num_strs);
else if (--i || 1)
{
nwiss = num_join_free(nwiss, nwis, *num_strs);
nwis = 0;
}
}
return (nwiss);
}
char **ft_strsplit_on_size(const char *s, size_t sl, size_t *nss)
{
size_t *arr_lens;
size_t *nwiss;
size_t num_word;
if (!s)
return (NULL);
num_word = ft_wordscnt(s, ' ');
arr_lens = get_lens_arr(s, num_word);
*nss = 0;
nwiss = get_nwiss(arr_lens, num_word, sl, nss);
free(arr_lens);
return (get_strs(s, nss, nwiss));
}
|
dolovnyak/ray-marching-render | libui/src/ui_event/ui_event_init.c | <filename>libui/src/ui_event/ui_event_init.c
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ui_event_init.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: sbecker <<EMAIL>> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/03/27 17:13:44 by sbednar #+# #+# */
/* Updated: 2019/07/15 14:56:56 by sbecker ### ########.fr */
/* */
/* ************************************************************************** */
#include "libui.h"
t_ui_event *ui_event_init(void)
{
t_ui_event *e;
if (!(e = (t_ui_event *)malloc(sizeof(t_ui_event))))
ui_sdl_deinit(228);
ft_bzero(e, sizeof(t_ui_event));
return (e);
}
static inline void init_el_keyboard_events(t_ui_el_events *e)
{
int i;
i = KEYS_COUNT;
if (!(e->on_key_up = (t_ui_event **)malloc(KEYS_COUNT *
sizeof(t_ui_event *))) ||
!(e->on_key_down = (t_ui_event **)malloc(KEYS_COUNT *
sizeof(t_ui_event *))))
ui_sdl_deinit(228);
while (--i >= 0)
{
if (!(e->on_key_down[i] = ui_event_init()) ||
!(e->on_key_up[i] = ui_event_init()))
ui_sdl_deinit(228);
}
}
t_ui_el_events *ui_event_el_events_init(void)
{
t_ui_el_events *e;
if (!(e = (t_ui_el_events *)malloc(sizeof(t_ui_el_events))))
ui_sdl_deinit(228);
ft_bzero(e, sizeof(t_ui_el_events));
if (!(e->on_pointer_enter = ui_event_init()) ||
!(e->on_pointer_stay = ui_event_init()) ||
!(e->on_pointer_exit = ui_event_init()) ||
!(e->on_pointer_left_button_pressed = ui_event_init()) ||
!(e->on_pointer_left_button_hold = ui_event_init()) ||
!(e->on_pointer_left_button_released = ui_event_init()) ||
!(e->on_pointer_right_button_pressed = ui_event_init()) ||
!(e->on_pointer_right_button_hold = ui_event_init()) ||
!(e->on_pointer_right_button_released = ui_event_init()) ||
!(e->on_scroll_up = ui_event_init()) ||
!(e->on_scroll_down = ui_event_init()) ||
!(e->on_render = ui_event_init()) ||
!(e->on_resize = ui_event_init()))
ui_sdl_deinit(228);
init_el_keyboard_events(e);
return (e);
}
static inline void init_win_keyboard_events(t_ui_win_events *w)
{
int i;
i = KEYS_COUNT;
if (!(w->on_key_up = (t_ui_event **)malloc(KEYS_COUNT *
sizeof(t_ui_event *))) ||
!(w->on_key_down = (t_ui_event **)malloc(KEYS_COUNT *
sizeof(t_ui_event *))))
ui_sdl_deinit(228);
while (--i >= 0)
{
if (!(w->on_key_down[i] = ui_event_init()) ||
!(w->on_key_up[i] = ui_event_init()))
ui_sdl_deinit(228);
}
}
t_ui_win_events *ui_event_win_events_init(void)
{
t_ui_win_events *w;
if (!(w = (t_ui_win_events *)malloc(sizeof(t_ui_win_events))))
ui_sdl_deinit(228);
ft_bzero(w, sizeof(t_ui_win_events));
if (!(w->on_pointer_moved = ui_event_init()) ||
!(w->on_pointer_enter = ui_event_init()) ||
!(w->on_pointer_exit = ui_event_init()) ||
!(w->on_pointer_left_button_pressed = ui_event_init()) ||
!(w->on_pointer_left_button_released = ui_event_init()) ||
!(w->on_pointer_right_button_pressed = ui_event_init()) ||
!(w->on_pointer_right_button_released = ui_event_init()) ||
!(w->on_scroll_up = ui_event_init()) ||
!(w->on_scroll_down = ui_event_init()) ||
!(w->on_focus_gained = ui_event_init()) ||
!(w->on_focus_lost = ui_event_init()) ||
!(w->on_resize = ui_event_init()) ||
!(w->on_close = ui_event_init()) ||
!(w->on_moved = ui_event_init()))
ui_sdl_deinit(228);
init_win_keyboard_events(w);
return (w);
}
|
dolovnyak/ray-marching-render | libui/src/ui_main/ui_main_handle_mouse_event.c | /* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ui_main_handle_mouse_event.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: sbecker <<EMAIL>> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/04/04 00:47:51 by sbednar #+# #+# */
/* Updated: 2019/07/15 17:50:57 by sbecker ### ########.fr */
/* */
/* ************************************************************************** */
#include "libui.h"
static t_ui_event *check_mousewheel(t_ui_main *m, t_ui_win *win)
{
t_ui_event *event;
event = NULL;
if (m->sdl_event->wheel.y < 0)
event = win->events->on_scroll_up;
else if (m->sdl_event->wheel.y > 0)
event = win->events->on_scroll_down;
return (event);
}
void ui_main_handle_mouse_event(t_ui_main *m)
{
t_ui_win *win;
t_ui_event *event;
if ((win = ui_main_find_window_by_sdl_id(m,
m->sdl_event->window.windowID)) == NULL)
return ;
event = NULL;
if (m->sdl_event->type == SDL_MOUSEMOTION)
event = win->events->on_pointer_moved;
else if (m->sdl_event->type == SDL_MOUSEBUTTONDOWN &&
m->sdl_event->button.button == SDL_BUTTON_LEFT)
event = win->events->on_pointer_left_button_pressed;
else if (m->sdl_event->type == SDL_MOUSEBUTTONDOWN &&
m->sdl_event->button.button == SDL_BUTTON_RIGHT)
event = win->events->on_pointer_right_button_pressed;
else if (m->sdl_event->type == SDL_MOUSEBUTTONUP &&
m->sdl_event->button.button == SDL_BUTTON_LEFT)
event = win->events->on_pointer_left_button_released;
else if (m->sdl_event->type == SDL_MOUSEBUTTONUP &&
m->sdl_event->button.button == SDL_BUTTON_RIGHT)
event = win->events->on_pointer_right_button_released;
else if (m->sdl_event->type == SDL_MOUSEWHEEL)
event = check_mousewheel(m, win);
if (event != NULL)
ui_event_invoke(event, m, win);
}
|
dolovnyak/ray-marching-render | src/interface/uix_inspector_change_pos_button.c | <gh_stars>1-10
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* uix_inspector_change_pos_button.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: edraugr- <<EMAIL>> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/10/05 16:45:24 by edraugr- #+# #+# */
/* Updated: 2019/10/05 16:45:26 by edraugr- ### ########.fr */
/* */
/* ************************************************************************** */
#include "interface.h"
int rt_uix_inspector_pos_button(t_ui_main *main, void *el_v)
{
t_ui_el *el;
t_object *obj;
int dir;
el = ui_win_find_el_by_id(
ui_main_find_window_by_id(main, 1), INSPECTOR_EL_ID);
obj = (t_object *)el->data;
if (!obj)
return 1;
el = (t_ui_el *)el_v;
dir = (el->id % 10 == 1) ? -1 : 1;
if ((el->id / 10) % 10 == 1)
obj->transform.pos.x += (float)dir * CHANGE_POS_SPEED;
else if ((el->id / 10) % 10 == 2)
obj->transform.pos.y += (float)dir * CHANGE_POS_SPEED;
else if ((el->id / 10) % 10 == 3)
obj->transform.pos.z += (float)dir * CHANGE_POS_SPEED;
rt_uix_update_inspector_values(main);
rt_render_update(main,
ui_win_find_el_by_id(ui_main_find_window_by_id(main, 0), 1));
return 1;
}
int rt_uix_inspector_rot_button(t_ui_main *main, void *el_v)
{
t_ui_el *el;
t_object *obj;
int dir;
el = ui_win_find_el_by_id(
ui_main_find_window_by_id(main, 1), INSPECTOR_EL_ID);
obj = (t_object *)el->data;
if (!obj)
return 1;
el = (t_ui_el *)el_v;
dir = (el->id % 10 == 1) ? -1 : 1;
if ((el->id / 10) % 10 == 1)
rotate_transform_around_axis(&obj->transform, (cl_float3){{1, 0, 0}}, (float)dir * CHANGE_ROT_SPEED);
else if ((el->id / 10) % 10 == 2)
rotate_transform_around_axis(&obj->transform, (cl_float3){{0, 1, 0}}, (float)dir * CHANGE_ROT_SPEED);
else if ((el->id / 10) % 10 == 3)
rotate_transform_around_axis(&obj->transform, (cl_float3){{0, 0, 1}}, (float)dir * CHANGE_ROT_SPEED);
rt_uix_update_inspector_values(main);
rt_render_update(main,
ui_win_find_el_by_id(ui_main_find_window_by_id(main, 0), 1));
return 1;
}
|
dolovnyak/ray-marching-render | libui/src/bfs/bfs_for_resize.c | /* ************************************************************************** */
/* */
/* ::: :::::::: */
/* bfs_for_resize.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: sbecker <<EMAIL>> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/07/13 02:49:00 by sbecker #+# #+# */
/* Updated: 2019/07/15 14:46:29 by sbecker ### ########.fr */
/* */
/* ************************************************************************** */
#include "libui.h"
static void bfs_resize_iter(const t_list *root, t_ui_main *m)
{
t_queue *q;
void *tmp;
q = NULL;
q_push(&q, (t_list *)root);
while (q)
{
tmp = q_pop(&q);
q_push(&q, CAST_X_TO_Y(tmp, t_ui_el *)->children);
ui_event_invoke(((t_ui_el *)tmp)->events->on_resize, m, tmp);
}
}
void bfs_for_resize(const t_ui_el *root, t_ui_main *m)
{
t_list *lst;
lst = ft_lstnew(NULL, 0);
lst->content = CAST_X_TO_Y(root, void *);
bfs_resize_iter((const t_list *)lst, m);
free(lst);
}
|
dolovnyak/ray-marching-render | include/rt_raycast_hit.h | <reponame>dolovnyak/ray-marching-render
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* rt_raycast_hit.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: sbecker <<EMAIL>> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/04/10 05:13:21 by sbecker #+# #+# */
/* Updated: 2019/07/03 20:16:18 by sbecker ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef RT_RAYCAST_HIT_H
# define RT_RAYCAST_HIT_H
# include "rt_object.h"
typedef struct s_raycast_hit
{
# ifndef OPENCL___
cl_float3 normal;
cl_float3 point;
cl_float3 local_point;
cl_float distance;
t_object *hit;
# else
float3 normal;
float3 point;
float3 local_point;
float distance;
__global t_object *hit;
# endif
} t_raycast_hit;
#endif
|
dolovnyak/ray-marching-render | libui/src/ui_sdl/ui_sdl_render.c | <reponame>dolovnyak/ray-marching-render<gh_stars>1-10
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ui_sdl_render.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: sbecker <<EMAIL>> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/07/15 12:22:49 by sbecker #+# #+# */
/* Updated: 2019/07/15 12:23:23 by sbecker ### ########.fr */
/* */
/* ************************************************************************** */
#include "libui.h"
void ui_sdl_render_copy(SDL_Renderer *r, SDL_Texture *t, SDL_Rect *r1,
SDL_Rect *r2)
{
SDL_RenderCopy(r, t, r1, r2);
}
void ui_sdl_render_clear(SDL_Renderer *r)
{
SDL_RenderClear(r);
}
void ui_sdl_renderer_read_pixels(SDL_Renderer *r, Uint32 f, void *p, int ph)
{
SDL_RenderReadPixels(r, NULL, f, p, ph);
}
|
dolovnyak/ray-marching-render | src/cl/pp/pp_anaglyph.c | #include "rt_cl.h"
__kernel void pp_anaglyph(
const __global int *input_data,
__global int *output_data,
int2 screen)
{
int tx = get_global_id(0);
int ty = get_global_id(1);
int index = ty * screen.x + tx;
float3 l_color;
float3 r_color;
float3 anaglyph_color;
int sdvig = 8;
if (tx < sdvig || tx > screen.x - sdvig - 1)
{
output_data[index] = 0;
return ;
}
int i1 = ty * screen.x + (tx - sdvig);
int i2 = ty * screen.x + (tx + sdvig);
l_color = int_color(input_data[i1]);
r_color = int_color(input_data[i2]);
anaglyph_color.x = l_color.x;
anaglyph_color.y = r_color.y;
anaglyph_color.z = r_color.z;
output_data[index] = get_color(anaglyph_color);
}
|
dolovnyak/ray-marching-render | include/color.h | #ifndef COLOR_H
# define COLOR_H
//# ifndef OPENCL___
# define COLOR(r, g, b) ((((int)r & 0xFF) << 16) | (((int)g & 0xFF) << 8) | ((int)b & 0xFF))
# define RED(c) (((int)c >> 16) & 0xFF)
# define GREEN(c) (((int)c >> 8) & 0xFF)
# define BLUE(c) ((int)c & 0xFF)
//# else
//# define COLOR(r, g, b) bit_insert(bit_insert((int)r, 8, 0, (int)g, 0, 0), 0, 8, (int)b, 0, 0)
//# define RED(c) bit_extract((int)c, 16, 0xFF)
//# define GREEN(c) bit_extract((int)c, 8, 0xFF)
//# define BLUE(c) bit_extract((int)c, 0, 0xFF)
//# endif
//
#endif
|
dolovnyak/ray-marching-render | include/interface.h | <reponame>dolovnyak/ray-marching-render<gh_stars>1-10
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* interface.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: edraugr- <<EMAIL>> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/09/26 14:19:35 by edraugr- #+# #+# */
/* Updated: 2019/09/26 14:19:39 by edraugr- ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef RT_INTERFACE_H
# define RT_INTERFACE_H
# include "rt.h"
# include "libui.h"
# define DEFAULT_BUT_STATE "default"
# define HIGHLIGHTED_BUT_STATE "highlighted"
# define SELECTED_BUT_STATE "selected"
# define ACTIVE_MENU 1
# define UNACTIVE_MENU 0
# define INSPECTOR_EL_ID 210
# define CHANGE_POS_SPEED 0.05f
# define CHANGE_ROT_SPEED 1
int rt_uix_on_button_exit(t_ui_main *main, void *el_v);
int rt_uix_on_button_enter(t_ui_main *main, void *el_v);
int rt_uix_button_choose(t_ui_main *main, void *el_v);
int rt_uix_button_select(t_ui_main *main, void *el_v);
int rt_uix_choose_path_trace(t_ui_main *main, void *el_v);
int rt_uix_choose_none(t_ui_main *main, void *el_v);
int rt_uix_choose_pong(t_ui_main *main, void *el_v);
int rt_uix_show_menu(t_ui_main *main, void *el_v);
int rt_uix_choose_obj_from_scene(t_ui_main *main, void *el_v);
int rt_uix_inspector_pos_button(t_ui_main *main, void *el_v);
int rt_uix_inspector_rot_button(t_ui_main *main, void *el_v);
int rt_uix_switch_blur(t_ui_main *main, void *el_v);
int rt_uix_switch_monochrome(t_ui_main *main, void *el_v);
int rt_uix_switch_anaglyph(t_ui_main *main, void *el_v);
int rt_uix_switch_dithering(t_ui_main *main, void *el_v);
int rt_uix_clear_pp(t_ui_main *main, void *el_v);
void rt_uix_add_functions(t_ui_main *m);
void rt_uix_update_inspector_values(t_ui_main *ui);
void fill_scene(t_ui_main *ui, t_ui_el *obj_menu);
void rt_uix_scene_setup(t_ui_main *ui);
void rt_uix_interface_setup(t_ui_main *ui, const char *json_path);
void rt_uix_fill_default_images(t_ui_main *ui);
#endif
|
dolovnyak/ray-marching-render | libui/src/ui_el/ui_el_event_default_resize.c | <reponame>dolovnyak/ray-marching-render
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ui_el_event_default_resize.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: sbecker <<EMAIL>> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/07/12 10:03:56 by sbecker #+# #+# */
/* Updated: 2019/07/13 09:17:11 by sbecker ### ########.fr */
/* */
/* ************************************************************************** */
#include "libui.h"
int ui_el_event_default_resize(t_ui_main *m, void *a)
{
t_ui_el *el;
el = (t_ui_el *)a;
(void)m;
el->rect.x = roundf(el->parent->rect.x + (float)el->parent->rect.w *
el->rrect.x);
el->rect.y = roundf(el->parent->rect.y + (float)el->parent->rect.h *
el->rrect.y);
el->rect.w = roundf((float)el->parent->rect.w * el->rrect.w);
el->rect.h = roundf((float)el->parent->rect.h * el->rrect.h);
el->crect = el->rect;
return (1);
}
|
dolovnyak/ray-marching-render | libui/src/ui_raycast/ui_raycast.c | <reponame>dolovnyak/ray-marching-render
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ui_raycast.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: sbednar <<EMAIL>> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/04/04 04:30:10 by sbednar #+# #+# */
/* Updated: 2019/07/13 06:04:29 by sbecker ### ########.fr */
/* */
/* ************************************************************************** */
#include "libui.h"
static int ui_raycast_is_pointer_inside_el(void *a1, void *a2)
{
t_ui_main *m;
t_ui_el *el;
Sint32 x;
Sint32 y;
m = (t_ui_main *)a1;
el = (t_ui_el *)a2;
x = m->ptr_pos.x;
y = m->ptr_pos.y;
if (el->params & EL_IS_DEPENDENT)
if (!((el->parent->crect.x <= x && el->parent->crect.y <= y) &&
(x <= (el->parent->crect.x + el->parent->crect.w)
&& y <= (el->parent->crect.y + el->parent->crect.h))))
return (0);
return ((el->rect.x <= x && el->rect.y <= y) &&
(x <= (el->rect.x + el->rect.w) && y <= (el->rect.y + el->rect.h)));
}
t_ui_el *ui_raycast(t_ui_main *m, t_ui_win *w)
{
t_ui_el *res;
if (w != NULL)
{
res = bfs_for_raycast(m, w->canvas, ui_raycast_is_pointer_inside_el);
return (res);
}
return (NULL);
}
|
dolovnyak/ray-marching-render | include/rt_cl.h | <reponame>dolovnyak/ray-marching-render<gh_stars>1-10
#ifndef CONFIG_CL_H
# define CONFIG_CL_H
# define CL_SILENCE_DEPRECATION
# define F_EPS 0.001f
# define PI 3.14159265f
# define TWO_PI 6.28318530f
# include "rt.h"
# include "color.h"
float sdf(float3 origin, float3 direction, __global t_object *obj, float3 *lp, int scene_params);
void normalize_coord_for_texture(t_raycast_hit rh, float2 uv, float3 *color,
__global int *texture, __global int *texture_w, __global int *texture_h,
__global int *prev_texture_size);
int choose_texture_for_object(t_raycast_hit rh, __global int *texture,
float3 *color, __global int *texture_w, __global int *texture_h,
__global int *prev_texture_size);
int raymarch(float3 origin, float3 direction, float distance, __global t_scene *scene, t_raycast_hit *rh);
void get_cam_ray_direction(float3 *ray_direction, int2 coord, int2 screen, float fov, t_transform transform);
float3 get_lighting(__global t_scene *scene, float3 color, t_raycast_hit ray_hit);
float gauss_coeff_x(int x, float sigma);
float3 int_color(int col);
int get_light(int start, int end, float percentage);
int get_color(float3 v);
#endif
|
dolovnyak/ray-marching-render | libft/src/cut_str_by_num_words.c | <reponame>dolovnyak/ray-marching-render
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* cut_str_by_num_words.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: edraugr- <<EMAIL>> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/07/09 01:35:42 by sbecker #+# #+# */
/* Updated: 2019/07/14 20:58:18 by edraugr- ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *csbnw2(const char *s, size_t new_len_str, size_t num_words)
{
char *res;
int i;
int j;
int k;
res = (char *)ft_memalloc(new_len_str + 2);
i = -1;
j = 0;
k = -1;
while (s[++i] && (size_t)j < num_words)
{
if (s[i] != ' ')
{
while (s[i] != ' ' && s[i])
res[++k] = s[i++];
++j;
res[++k] = ' ';
}
}
res[k] = '\0';
return (res);
}
char *cut_str_by_num_words(const char *s, size_t num_words)
{
size_t i;
size_t j;
size_t new_len_str;
i = -1;
j = 0;
new_len_str = 0;
while (s[++i] && j < num_words)
{
if (s[i] != ' ')
{
++j;
while (s[i] != ' ' && s[i])
{
++new_len_str;
++i;
}
++new_len_str;
--i;
}
}
return (csbnw2(s, new_len_str, num_words));
}
|
dolovnyak/ray-marching-render | libui/src/ui_el/ui_el_destroy.c | <gh_stars>1-10
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ui_el_destroy.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: sbednar <<EMAIL>> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/07/09 21:14:50 by sbednar #+# #+# */
/* Updated: 2019/07/14 09:36:42 by sbecker ### ########.fr */
/* */
/* ************************************************************************** */
#include "libui.h"
static void ui_el_text_destroy(t_ui_text *t)
{
free(t->text);
free(t);
}
void ui_el_destroy(t_ui_el *e)
{
t_list *tmp;
if (e->sdl_surface)
SDL_FreeSurface(e->sdl_surface);
tmp = e->sdl_textures;
while (e->sdl_textures)
{
SDL_DestroyTexture((SDL_Texture *)e->sdl_textures->content);
e->sdl_textures = e->sdl_textures->next;
free(tmp);
tmp = e->sdl_textures;
}
ui_el_destroy_children(e->children);
if (e->text_area)
ui_el_text_destroy(e->text_area);
ui_event_el_events_destroy(e->events);
free(e);
}
|
dolovnyak/ray-marching-render | libui/src/ui_el/ui_el_setup_default_scroll_menu_elem.c | /* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ui_el_setup_default_scroll_menu_elem.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: sbecker <<EMAIL>> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/05/20 21:40:00 by sbecker #+# #+# */
/* Updated: 2019/07/15 15:25:29 by sbecker ### ########.fr */
/* */
/* ************************************************************************** */
#include "libui.h"
void ui_el_setup_default_scroll_menu_elem(t_ui_el *el)
{
el->params |= EL_IS_SCROLLABLE;
el->params |= EL_IS_DEPENDENT;
ui_event_add_listener(el->events->on_scroll_up,
ui_el_event_scroll_child_menu_up);
ui_event_add_listener(el->events->on_scroll_down,
ui_el_event_scroll_child_menu_down);
if (DEBUG_STATUS == 1)
{
ui_event_add_listener(el->events->on_scroll_up, ui_log_el_scroll_up);
ui_event_add_listener(el->events->on_scroll_down,
ui_log_el_scroll_down);
}
}
|
dolovnyak/ray-marching-render | libui/src/ui_cursor/ui_cursor_from.c | /* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ui_cursor_from.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: sbednar <<EMAIL>> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/06/22 20:09:20 by sbednar #+# #+# */
/* Updated: 2019/06/25 20:55:27 by sbednar ### ########.fr */
/* */
/* ************************************************************************** */
#include "libui.h"
void ui_cursor_from(t_cursor *c)
{
SDL_Cursor *current_cursor;
SDL_Cursor *new_cursor;
if ((current_cursor = SDL_GetCursor()))
SDL_FreeCursor(current_cursor);
if (!(new_cursor = SDL_CreateColorCursor(c->s, c->hot_x, c->hot_y)))
return ;
SDL_SetCursor(new_cursor);
}
|
dolovnyak/ray-marching-render | src/interface/uix_popup_menu.c | /* ************************************************************************** */
/* */
/* ::: :::::::: */
/* uix_popup_menu.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: edraugr- <<EMAIL>> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/09/28 17:15:32 by edraugr- #+# #+# */
/* Updated: 2019/09/28 17:15:35 by edraugr- ### ########.fr */
/* */
/* ************************************************************************** */
#include "interface.h"
static int rt_uix_hide_local_menu(t_ui_el *el)
{
t_list *tmp;
Uint32 p_id;
tmp = el->children;
p_id = el->id;
el->data = (void *)UNACTIVE_MENU;
while (tmp)
{
el = (t_ui_el *)tmp->content;
if (el->id != p_id * 10)
el->params |= EL_IS_HIDDEN;
tmp = tmp->next;
}
return (1);
}
static int rt_uix_hide_menu(t_ui_el *el)
{
t_list *tmp;
tmp = el->parent->children;
while (tmp)
{
el = (t_ui_el *)tmp->content;
rt_uix_hide_local_menu(el);
tmp = tmp->next;
}
return (1);
}
int rt_uix_show_menu(t_ui_main *main, void *el_v)
{
t_ui_el *el;
t_list *tmp;
Uint32 p_id;
(void)main;
el = (t_ui_el *)el_v;
tmp = el->children;
p_id = el->id;
if ((int)el->data == ACTIVE_MENU)
return (1);
rt_uix_hide_menu(el);
el->data = (void *)ACTIVE_MENU;
while (tmp)
{
el = (t_ui_el *)tmp->content;
if (el->id != p_id * 10)
el->params ^= EL_IS_HIDDEN;
tmp = tmp->next;
}
return (1);
} |
dolovnyak/ray-marching-render | libui/src/ui_win/ui_win_event_update_size.c | <gh_stars>1-10
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ui_win_event_update_size.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: sbecker <<EMAIL>> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/07/12 05:57:22 by sbecker #+# #+# */
/* Updated: 2019/07/15 10:55:59 by sbecker ### ########.fr */
/* */
/* ************************************************************************** */
#include "libui.h"
int ui_win_event_update_size(t_ui_main *m, void *a)
{
t_ui_win *w;
(void)m;
w = (t_ui_win *)a;
if (w != NULL)
{
SDL_GetRendererOutputSize(w->sdl_renderer, &(w->size.x), &(w->size.y));
if (w->size.x < 800 || w->size.y < 376)
{
SDL_SetWindowSize(w->sdl_window, 800, 376);
w->size.x = 800;
w->size.y = 376;
}
else
{
w->size.y = (int)sqrt(w->size.x * w->size.y / 2.13f);
w->size.x = 2.13f * w->size.y;
SDL_SetWindowSize(w->sdl_window, w->size.x, w->size.y);
}
w->canvas->rect.w = w->size.x;
w->canvas->rect.h = w->size.y;
w->canvas->crect = w->canvas->rect;
bfs_for_resize(w->canvas, m);
}
return (1);
}
|
dolovnyak/ray-marching-render | libui/src/bfs/bfs_for_find_el_by_id.c | /* ************************************************************************** */
/* */
/* ::: :::::::: */
/* bfs_for_find_el_by_id.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: sbecker <<EMAIL>> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/07/13 03:01:35 by sbecker #+# #+# */
/* Updated: 2019/07/13 05:49:57 by sbecker ### ########.fr */
/* */
/* ************************************************************************** */
#include "libui.h"
static int ui_win_check_el_by_id(void *el_v, Uint32 id)
{
t_ui_el *el;
el = (t_ui_el *)el_v;
if (el->id == id)
return (1);
return (0);
}
static void *bfs_find_el_by_id(const t_list *root, Uint32 id)
{
t_queue *q;
void *tmp;
void *res;
q = NULL;
res = NULL;
q_push(&q, (t_list *)root);
while (q)
{
tmp = q_pop(&q);
q_push(&q, CAST_X_TO_Y(tmp, t_ui_el *)->children);
if (ui_win_check_el_by_id(tmp, id))
{
while (q)
q_pop(&q);
return (tmp);
}
}
return (NULL);
}
t_ui_el *bfs_for_find_el_by_id(const t_ui_el *root, Uint32 id)
{
t_list *lst;
t_ui_el *res;
lst = ft_lstnew(NULL, 0);
lst->content = CAST_X_TO_Y(root, void *);
res = CAST_X_TO_Y(bfs_find_el_by_id((const t_list *)lst, id), t_ui_el*);
free(lst);
return (res);
}
|
dolovnyak/ray-marching-render | libui/src/ui_main/ui_main_fill_default_functions.c | <gh_stars>1-10
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ui_main_fill_default_functions.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: sbecker <<EMAIL>> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/07/24 22:43:25 by sbecker #+# #+# */
/* Updated: 2019/07/24 22:44:38 by sbecker ### ########.fr */
/* */
/* ************************************************************************** */
#include "libui.h"
void ui_main_fill_default_functions(t_ui_main *m)
{
ui_main_add_function_by_id(m, ui_win_event_update_size,
"ui_win_event_update_size");
ui_main_add_function_by_id(m, ui_main_event_close_program,
"ui_main_event_close_program");
ui_main_add_function_by_id(m, ui_main_event_close_window,
"ui_main_event_close_window");
}
|
dolovnyak/ray-marching-render | libui/src/ui_el/ui_el_event_close_window.c | /* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ui_el_event_close_window.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: sbecker <<EMAIL>> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/07/12 05:12:51 by sbecker #+# #+# */
/* Updated: 2019/07/14 16:46:43 by sbecker ### ########.fr */
/* */
/* ************************************************************************** */
#include "libui.h"
int ui_el_event_close_window(t_ui_main *m, void *a)
{
t_ui_el *el;
t_ui_win *cur_w;
t_list *cur;
t_list *prev;
el = (t_ui_el *)a;
prev = NULL;
cur = m->windows;
while (cur)
{
cur_w = (t_ui_win *)(cur->content);
if (el->modal_win == cur_w)
{
cur_w->params |= WIN_IS_HIDDEN;
return (1);
}
prev = cur;
cur = cur->next;
}
return (1);
}
|
dolovnyak/ray-marching-render | libui/src/ui_main/ui_main_save_texture.c | /* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ui_main_save_texture.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: sbednar <<EMAIL>> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/07/05 16:09:46 by sbednar #+# #+# */
/* Updated: 2019/07/15 11:59:36 by sbecker ### ########.fr */
/* */
/* ************************************************************************** */
#include "libui.h"
void ui_main_save_texture(t_ui_win *win,
SDL_Texture *t, const char *path, int type)
{
SDL_Texture *p;
SDL_Surface *s;
p = SDL_GetRenderTarget(win->sdl_renderer);
s = SDL_CreateRGBSurface(0, win->size.x, win->size.y,
32, 0, 0, 0, 0);
SDL_SetRenderTarget(win->sdl_renderer, t);
SDL_RenderReadPixels(win->sdl_renderer, NULL, s->format->format,
s->pixels, s->pitch);
if (type == IMG_TYPE_PNG)
IMG_SavePNG(s, path);
else if (type == IMG_TYPE_JPG)
IMG_SaveJPG(s, path, 100);
SDL_SetRenderTarget(win->sdl_renderer, p);
SDL_FreeSurface(s);
}
|
dolovnyak/ray-marching-render | src/rt_get_texture.c |
#include "rt.h"
#define STB_IMAGE_IMPLEMENTATION
# include "stb_image.h"
static int sdl_log_error(const char *p, const int id)
{
SDL_Log("%s ----> ERROR <---- %s", KRED, KNRM);
SDL_Log("INCORRECT: %s%s%s%s%s",
p,
id < 0 ? "" : " IN ID = ",
KGRN,
id < 0 ? "" : ft_itoa(id),
KNRM);
return (FUNCTION_FAILURE);
}
void find_textures_size(t_rt_main *rt, char **texture_file, int number_of_texture)
{
unsigned char *tex_data;
int bpp;
int texture_w;
int texture_h;
int i;
i = -1;
rt->texture->texture_size = 0;
while (++i < number_of_texture)
{
if (!(tex_data = stbi_load(texture_file[i], &texture_w,
&texture_h, &bpp, 4)))
{
sdl_log_error("TEXTURE ERROR OR TEXTURE PATH NOT FOUND", i);
exit(-1);
}
rt->texture->texture_w[i] = texture_w;
rt->texture->texture_h[i] = texture_h - 1;
rt->texture->texture_size += (texture_w * texture_h);
free(tex_data);
}
}
void get_textures(t_rt_main *rt, char **texture_file, int number_of_texture)
{
unsigned char *tex_data;
int x;
int y;
int total_texture_size;
int i;
i = -1;
total_texture_size = 0;
rt->texture->prev_texture_size[0] = 0;
while (++i < number_of_texture)
{
if (!(tex_data = stbi_load(texture_file[i], &rt->texture->w,
&rt->texture->h, &rt->texture->bpp, 4)))
{
sdl_log_error("TEXTURE ERROR OR TEXTURE PATH NOT FOUND", i);
exit(-1);
}
y = -1;
while (++y < rt->texture->h)
{
x = -1;
while (++x < rt->texture->w)
{
rt->texture->texture[(x + (y * rt->texture->w)) + total_texture_size] =
*((int *) tex_data + x + y * rt->texture->w);
}
}
rt->texture->prev_texture_size[i] = total_texture_size;
total_texture_size += rt->texture->w * (rt->texture->h - 1);
free(tex_data);
}
}
|
dolovnyak/ray-marching-render | src/interface/uix_fill_scene.c | <reponame>dolovnyak/ray-marching-render<gh_stars>1-10
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* uix_fill_scene.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: edraugr- <<EMAIL>> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/09/28 18:49:42 by edraugr- #+# #+# */
/* Updated: 2019/09/28 18:49:45 by edraugr- ### ########.fr */
/* */
/* ************************************************************************** */
#include "interface.h"
static t_ui_el *create_tmp_el(t_ui_win *win, t_ui_el *obj_menu, size_t l_id)
{
t_ui_el *tmp_el;
tmp_el = ui_el_init();
ui_el_setup_default(tmp_el);
ui_el_setup_default_scroll_menu_elem(tmp_el);
ui_el_add_child(obj_menu, tmp_el);
tmp_el->id = obj_menu->id * 10 + (Uint32)l_id;
ui_el_set_new_pos(tmp_el, 0, 0,
(t_fvec2){0.01, 0.01
+ 0.1f * (float)l_id});
ui_el_set_size(tmp_el, 0, (t_fvec2){0.98, 0.09});
tmp_el->sdl_renderer = win->sdl_renderer;
ui_el_add_color_texture(tmp_el, (t_vec2){350, 80},0x606060, "default");
ui_el_add_color_texture(tmp_el, (t_vec2){350, 80}, 0x450010, "selected");
ui_el_add_color_texture(tmp_el, (t_vec2){350, 80}, 0xA0A0A0, "highlighted");
ui_event_add_listener(tmp_el->events->on_pointer_left_button_pressed,
rt_uix_button_choose);
ui_event_add_listener(tmp_el->events->on_pointer_enter,
rt_uix_on_button_enter);
ui_event_add_listener(tmp_el->events->on_pointer_left_button_pressed,
rt_uix_choose_obj_from_scene);
ui_event_add_listener(tmp_el->events->on_pointer_exit,
rt_uix_on_button_exit);
return (tmp_el);
}
static void process(t_ui_el *p, t_ui_main *m)
{
t_ui_el *el;
el = ui_el_init();
ui_el_setup_default(el);
el->params |= EL_IGNOR_RAYCAST | EL_IS_DEPENDENT;
ui_el_add_child(p, el);
ui_el_set_pos(el, 0, (t_fvec2){0.0, 0.1});
ui_el_set_size(el, 0, (t_fvec2){0.2, 0.7});
el->id = p->id * 10;
ui_el_set_text(el, ui_main_get_font_by_id(m, "Diablo"),
(t_text_params){(t_color){255, 255, 255, 0}, (t_color){0, 0, 0, 0},
0, TEXT_IS_REGULAR, TEXT_IS_SOLID});
ui_el_update_text(el, ((t_object *)p->data)->local_name);
}
void fill_scene(t_ui_main *ui, t_ui_el *obj_menu)
{
t_ui_el *tmp_el;
t_ui_win *uix_w;
t_scene *scene;
size_t i;
scene = ((t_rt_main *)ui->data)->scene;
uix_w = ui_main_find_window_by_id(ui, 1);
i = -1;
while (++i < scene->objects->size)
{
tmp_el = create_tmp_el(uix_w, obj_menu, i);
tmp_el->data = (void *)(scene->objects->storage + i * scene->objects->cell_size);
process(tmp_el, ui);
}
} |
dolovnyak/ray-marching-render | libui/src/ui_jtoc/ui_jtoc_el_from_json.c | <filename>libui/src/ui_jtoc/ui_jtoc_el_from_json.c
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ui_jtoc_el_from_json.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: edraugr- <<EMAIL>> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/07/12 06:43:29 by sbecker #+# #+# */
/* Updated: 2019/07/15 08:06:06 by edraugr- ### ########.fr */
/* */
/* ************************************************************************** */
#include "libui.h"
static int ui_el_from_json_pos(t_ui_main *m, t_ui_el *e,
t_jnode *n)
{
float x;
float y;
int p;
t_jnode *tmp;
if (!(tmp = jtoc_node_get_by_path(n, "pos.x")) || !ui_jtoc_isnum(tmp->type))
return (ui_jtoc_sdl_log_error("NODE EL (POS.X)", e->id));
x = jtoc_get_float(tmp);
if (!(tmp = jtoc_node_get_by_path(n, "pos.y")) || !ui_jtoc_isnum(tmp->type))
return (ui_jtoc_sdl_log_error("NODE EL (POS.Y)", e->id));
y = jtoc_get_float(tmp);
p = 0;
if ((tmp = jtoc_node_get_by_path(n, "pos.params")))
{
tmp = tmp->down;
while (tmp)
{
if (tmp->type != string)
return (ui_jtoc_sdl_log_error("NODE EL (POS.PARAMS)", e->id));
p |= ui_jtoc_get_pos_size(jtoc_get_string(tmp));
tmp = tmp->right;
}
}
ui_el_set_pos(e, p, (t_fvec2){x, y});
return (ui_el_from_json_size(m, e, n));
}
static int ui_el_from_json_params(t_ui_main *m, t_ui_el *e,
t_jnode *n)
{
t_jnode *tmp;
e->params = 0;
if ((tmp = jtoc_node_get_by_path(n, "params")))
{
tmp = tmp->down;
while (tmp)
{
if (tmp->type != string)
return (ui_jtoc_sdl_log_error("NODE EL (PARAMS)", e->id));
e->params |= ui_jtoc_get_el_param_from_string(jtoc_get_string(tmp));
tmp = tmp->right;
}
}
if (ui_jtoc_el_setup_by_type(e, n))
ui_sdl_deinit(228);
if (ui_jtoc_el_pref_text(m, e, n))
ui_sdl_deinit(228);
if (ui_jtoc_el_pref_modal_win(m, e, n))
ui_sdl_deinit(228);
return (ui_el_from_json_pos(m, e, n));
}
int ui_jtoc_el_from_json(t_ui_main *m, t_ui_win *w, t_jnode *n)
{
t_ui_el *p;
t_ui_el *e;
t_jnode *tmp;
if (!(tmp = jtoc_node_get_by_path(n, "id")) || !ui_jtoc_isnum(tmp->type))
return (ui_jtoc_sdl_log_error("NODE EL (ID)", -1));
if (jtoc_get_int(tmp) == 0)
ui_parse_canvas(m, w->canvas, n);
else
{
if (!(e = ui_el_init()) ||
((e->id = jtoc_get_int(tmp)) == 0) ||
!(tmp = jtoc_node_get_by_path(n, "parent")) ||
!ui_jtoc_isnum(tmp->type) ||
!(p = ui_win_find_el_by_id(w, jtoc_get_int(tmp))))
return (ui_jtoc_sdl_log_error("NODE EL (INIT/NO PARENT)", e->id));
ui_el_add_child(p, e);
if (ui_el_from_json_params(m, e, n))
ui_sdl_deinit(228);
}
return (FUNCTION_SUCCESS);
}
|
dolovnyak/ray-marching-render | libui/src/ui_main/ui_main_loop.c | /* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ui_main_loop.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: sbecker <<EMAIL>> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/03/30 21:26:26 by sbednar #+# #+# */
/* Updated: 2019/07/15 11:35:08 by sbecker ### ########.fr */
/* */
/* ************************************************************************** */
#include "libui.h"
//static int ui_main_loop_draw(void *d)
//{
// t_ui_main *m;
//
// m = (t_ui_main *)d;
// while (228)
// {
// if (m->params & MAIN_ON_QUIT)
// return (1);
// SDL_LockMutex(m->mutex);
// ui_draw(m);
// SDL_UnlockMutex(m->mutex);
// }
// return (0);
//}
//static int ui_main_loop_raycast(void *d)
//{
// t_ui_main *m;
//
// m = (t_ui_main *)d;
// while (1488)
// {
// if (m->params & MAIN_ON_QUIT)
// return (1);
// SDL_LockMutex(m->mutex);
// ui_main_handle_raycast(m);
// SDL_UnlockMutex(m->mutex);
// }
// return (0);
//}
/*void ui_main_custom_events(t_ui_main *m)
{
}*/
void ui_main_loop(t_ui_main *m)
{
// SDL_Thread *thread;
m->mutex = SDL_CreateMutex();
// thread = SDL_CreateThread(ui_main_loop_draw,
// "ui_main_loop_draw", (void *)m);
// SDL_DetachThread(thread);
// thread = SDL_CreateThread(ui_main_loop_raycast,
// "ui_main_loop_raycast", (void *)m);
// SDL_DetachThread(thread);
while (1337)
{
if (SDL_PollEvent(m->sdl_event))
ui_main_handle_event(m);
ui_main_handle_raycast(m);
ui_draw(m);
// ui_main_custom_events(m);
}
}
|
dolovnyak/ray-marching-render | libui/src/ui_prefab/ui_prefab_scroll_menu.c | <filename>libui/src/ui_prefab/ui_prefab_scroll_menu.c
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ui_prefab_scroll_menu.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: sbednar <<EMAIL>> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/05/26 15:21:24 by sbecker #+# #+# */
/* Updated: 2019/06/24 21:25:33 by sbednar ### ########.fr */
/* */
/* ************************************************************************** */
#include "libui.h"
void ui_prefab_scroll_menu(t_ui_main *m, t_ui_el *canvas,
t_ui_el *scroll_menu, t_scroll_m_pref *scroll_data)
{
t_list *list;
t_ui_el *cur_el;
ui_prefab_get_pixel_pos(scroll_menu, canvas, scroll_data->type_pos,
&scroll_data->begin_pos);
ui_prefab_get_pixel_size(scroll_menu, canvas, scroll_data->type_size,
&scroll_data->size);
ui_prefab_get_pixel_size(scroll_menu, canvas, scroll_data->type_indent,
&scroll_data->indent);
list = scroll_menu->children;
while (list)
{
cur_el = (t_ui_el *)list->content;
ui_el_set_pos(cur_el, PIXEL | ABS, scroll_data->begin_pos);
ui_el_set_size(cur_el, PIXEL, scroll_data->size);
cur_el->params |= scroll_data->params;
cur_el->id = scroll_data->begin_id;
cur_el->sdl_renderer = scroll_data->sdl_renderer;
ui_el_add_texture_from_main_by_id(m, cur_el, scroll_data->texture,
"default");
++scroll_data->begin_id;
scroll_data->begin_pos.y += scroll_data->size.y + scroll_data->indent.y;
list = list->next;
}
}
|
dolovnyak/ray-marching-render | libui/src/ui_main/ui_main_add_function_by_id.c | <reponame>dolovnyak/ray-marching-render<filename>libui/src/ui_main/ui_main_add_function_by_id.c
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ui_main_add_function_by_id.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: sbednar <<EMAIL>> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/06/19 17:10:19 by sbednar #+# #+# */
/* Updated: 2019/07/15 11:59:10 by sbecker ### ########.fr */
/* */
/* ************************************************************************** */
#include "libui.h"
int ui_main_add_function_by_id(t_ui_main *m,
t_pred_ptr_event f, const char *func_id)
{
long ptr;
t_list *node;
int hash;
ptr = (long)f;
hash = ft_strhash(func_id);
if ((node = ft_lstnew((void *)&ptr, sizeof(ptr))) == NULL)
ui_sdl_deinit(228);
node->content_size = hash;
ft_lstadd(&(m->functions), node);
return (FUNCTION_SUCCESS);
}
|
dolovnyak/ray-marching-render | src/interface/uix_postprocessing_choose.c | /* ************************************************************************** */
/* */
/* ::: :::::::: */
/* uix_posprocessing_choose.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: edraugr- <<EMAIL>> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/09/26 17:28:21 by edraugr- #+# #+# */
/* Updated: 2019/09/26 17:28:23 by edraugr- ### ########.fr */
/* */
/* ************************************************************************** */
#include "interface.h"
int rt_uix_switch_blur(t_ui_main *main, void *el_v)
{
t_rt_main *rt;
rt = (t_rt_main *)main->data;
(void)el_v;
vec_push_back(rt->pp, cl_get_kernel_by_name(rt->cl, "pp_blur_x"));
vec_push_back(rt->pp, cl_get_kernel_by_name(rt->cl, "pp_blur_y"));
rt_render_update(main, ui_win_find_el_by_id(ui_main_find_window_by_id(main, 0), 1));
return (1);
}
int rt_uix_switch_monochrome(t_ui_main *main, void *el_v)
{
t_rt_main *rt;
rt = (t_rt_main *)main->data;
(void)el_v;
vec_push_back(rt->pp, cl_get_kernel_by_name(rt->cl, "pp_monochrome"));
rt_render_update(main, ui_win_find_el_by_id(ui_main_find_window_by_id(main, 0), 1));
return (1);
}
int rt_uix_switch_anaglyph(t_ui_main *main, void *el_v)
{
t_rt_main *rt;
rt = (t_rt_main *)main->data;
(void)el_v;
vec_push_back(rt->pp, cl_get_kernel_by_name(rt->cl, "pp_anaglyph"));
rt_render_update(main, ui_win_find_el_by_id(ui_main_find_window_by_id(main, 0), 1));
return (1);
}
int rt_uix_switch_dithering(t_ui_main *main, void *el_v)
{
t_rt_main *rt;
rt = (t_rt_main *)main->data;
(void)el_v;
vec_push_back(rt->pp, cl_get_kernel_by_name(rt->cl, "pp_dithering"));
rt_render_update(main, ui_win_find_el_by_id(ui_main_find_window_by_id(main, 0), 1));
return (1);
}
int rt_uix_clear_pp(t_ui_main *main, void *el_v)
{
t_rt_main *rt;
rt = (t_rt_main *)main->data;
(void)el_v;
vec_clear(rt->pp);
rt_render_update(main, ui_win_find_el_by_id(ui_main_find_window_by_id(main, 0), 1));
return (1);
}
|
dolovnyak/ray-marching-render | include/rt_pp.h | <reponame>dolovnyak/ray-marching-render
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* rt_pp.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: sbecker <<EMAIL>> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/07/23 17:50:06 by sbecker #+# #+# */
/* Updated: 2019/07/23 17:50:07 by sbecker ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef RT_PPNODE_H
# define RT_PPNODE_H
#include "rt.h"
//enum e_pp_type
//{
// pp_monohrome = 1,
// pp_anagliph,
// pp_blur,
// pp_ordered_dithering
//};
//
//union u_pp_params
//{
// t_sphere sphere;
// t_box box;
// t_round_box round_box;
// t_torus torus;
// t_capped_torus capped_torus;
// t_link link;
// t_cylinder cylinder;
// t_cone cone;
// t_plane plane;
// t_octahedron octahedron;
// t_mandelbulb mandelbulb;
// t_mandelbox mandelbox;
// t_menger_sponge menger_sponge;
//};
typedef struct s_ppnode
{
cl_kernel *kernel;
// enum e_pp_type type;
// union u_pp_oparams params;
} t_ppnode;
#endif
|
dolovnyak/ray-marching-render | libui/src/ui_el/ui_el_event_scroll_menu.c | <reponame>dolovnyak/ray-marching-render
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ui_el_event_scroll_menu.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: sbecker <<EMAIL>> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/07/12 04:41:24 by sbecker #+# #+# */
/* Updated: 2019/07/15 14:52:18 by sbecker ### ########.fr */
/* */
/* ************************************************************************** */
#include "libui.h"
int ui_el_event_scroll_child_menu_down(t_ui_main *m, void *a)
{
t_ui_el *el;
el = (t_ui_el*)a;
ui_event_invoke(el->parent->events->on_scroll_down, m, el->parent);
return (1);
}
int ui_el_event_scroll_child_menu_up(t_ui_main *m, void *a)
{
t_ui_el *el;
el = (t_ui_el*)a;
ui_event_invoke(el->parent->events->on_scroll_up, m, el->parent);
return (1);
}
int ui_el_event_scroll_menu_down(t_ui_main *m, void *a)
{
t_ui_el *el_menu;
t_ui_el *higher_el;
t_ui_el *cur_el;
t_list *list;
int tmp_scroll_speed;
(void)m;
el_menu = (t_ui_el *)a;
if (el_menu->children == 0)
return (1);
higher_el = (t_ui_el *)el_menu->children->content;
if (higher_el->rect.y >= el_menu->rect.y)
return (1);
tmp_scroll_speed = SCROLL_SPEED;
if (higher_el->rect.y + SCROLL_SPEED > el_menu->rect.y)
tmp_scroll_speed = el_menu->rect.y - higher_el->rect.y;
list = el_menu->children;
while (list)
{
cur_el = (t_ui_el*)list->content;
ui_el_change_pos(cur_el, 0, PIXEL, (t_fvec2){0, tmp_scroll_speed});
list = list->next;
}
return (1);
}
static void scroll_elems(t_list *list, int tmp_scroll_speed)
{
t_ui_el *cur_el;
while (list)
{
cur_el = (t_ui_el*)list->content;
ui_el_change_pos(cur_el, 0, PIXEL, (t_fvec2){0, -tmp_scroll_speed});
list = list->next;
}
}
int ui_el_event_scroll_menu_up(t_ui_main *m, void *a)
{
t_ui_el *el_menu;
t_ui_el *low_el;
t_list *list;
int tmp_scroll_speed;
(void)m;
el_menu = (t_ui_el*)a;
if (el_menu->children == 0)
return (1);
list = el_menu->children;
while (list->next)
list = list->next;
low_el = (t_ui_el*)list->content;
if (low_el->rect.y + low_el->rect.h <= el_menu->rect.y + el_menu->rect.h)
return (1);
tmp_scroll_speed = SCROLL_SPEED;
if (low_el->rect.y + low_el->rect.h - SCROLL_SPEED
< el_menu->rect.y + el_menu->rect.h)
tmp_scroll_speed = low_el->rect.y + low_el->rect.h
- el_menu->rect.y - el_menu->rect.h;
list = el_menu->children;
scroll_elems(list, tmp_scroll_speed);
return (1);
}
|
dolovnyak/ray-marching-render | src/rt_input_system.c | /* ************************************************************************** */
/* */
/* ::: :::::::: */
/* rt_physics_system.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: sbednar <<EMAIL>> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/04/11 03:01:47 by sbecker #+# #+# */
/* Updated: 2019/07/03 19:48:39 by sbecker ### ########.fr */
/* */
/* ************************************************************************** */
#include "rt_input_system.h"
static float get_axis(const Uint8 *state, SDL_Scancode low, SDL_Scancode high)
{
if (!(state[low] ^ state[high]))
return (0);
if (state[high])
return (1);
if (state[low])
return (-1);
return (0);
}
void rotate_active(t_input_system *s)
{
t_rb *active;
active = s->active;
/// Arrows mode
active->rot.raw_vel = (cl_float3){{
get_axis(s->state, SDL_SCANCODE_UP, SDL_SCANCODE_DOWN),
get_axis(s->state, SDL_SCANCODE_LEFT, SDL_SCANCODE_RIGHT),
0
}};
/// End of arrows mode
// /// Mouse mode
// int x, y;
// SDL_GetMouseState(&x, &y);
// if (!raw_rot_velocity.y)
// raw_rot_velocity.y = (x - cam->mx) / 1440.f * 300;
// if (!raw_rot_velocity.x)
// raw_rot_velocity.x = (y - cam->my) / 810.f * 300;
// /// End of mouse mode
// SDL_UnlockMutex(s->system.mutex);
// cam->mx = x;
// cam->my = y;
}
void move_active(t_input_system *s)
{
s->active->move.raw_vel = (cl_float3){{
get_axis(s->state, SDL_SCANCODE_A, SDL_SCANCODE_D),
get_axis(s->state, SDL_SCANCODE_Q, SDL_SCANCODE_E),
get_axis(s->state, SDL_SCANCODE_S, SDL_SCANCODE_W)
}};
if (s->state[SDL_SCANCODE_LSHIFT])
s->active->move.raw_vel.v4 *= s->active->move.speed_mult;
// ТЕСТ
if (s->active->transform->id == CAMERA_ID)
{
t_camera *cam = (t_camera *)s->active->transform;
float d = get_axis(s->state, SDL_SCANCODE_T, SDL_SCANCODE_Y);
if (d != 0)
cam->fov += d * 0.1f;
}
if (s->state[SDL_SCANCODE_M])
change_selected(s, NULL);
}
void process_selected(t_input_system *s)
{
cl_float3 raw_dir = (cl_float3){{
get_axis(s->state, SDL_SCANCODE_J, SDL_SCANCODE_L),
get_axis(s->state, SDL_SCANCODE_O, SDL_SCANCODE_U),
get_axis(s->state, SDL_SCANCODE_I, SDL_SCANCODE_K)
}};
s->selected->pos.v4 += raw_dir.v4 * 0.01f;
}
void change_selected(t_input_system *s, t_object *o)
{
t_object *obj = (t_object *)s->selected;
if (obj)
obj->material.color = (cl_float4){{0, 1, 1, 1}};
s->selected = &o->transform;
obj = (t_object *)s->selected;
if (obj)
obj->material.color = (cl_float4){{0, 0, 1, 1}};
}
int is_func(void *isv)
{
t_input_system *is;
is = (t_input_system *)isv;
is->system.now = SDL_GetPerformanceCounter();
is->system.last = 0;
while (is)
{
is->system.delta_time = (float)(is->system.now - is->system.last) / SDL_GetPerformanceFrequency();
move_active(is);
rotate_active(is);
if (is->selected)
process_selected(is);
is->system.last = is->system.now;
is->system.now = SDL_GetPerformanceCounter();
}
return (0);
} |
dolovnyak/ray-marching-render | libui/src/ui_render/ui_show_window.c | /* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ui_show_window.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: sbecker <<EMAIL>> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/04/04 06:18:39 by edraugr- #+# #+# */
/* Updated: 2019/07/14 03:12:38 by sbecker ### ########.fr */
/* */
/* ************************************************************************** */
#include "libui.h"
void ui_show_window(t_ui_win *w)
{
int check;
SDL_RendererInfo *info;
info = (SDL_RendererInfo *)malloc(sizeof(SDL_RendererInfo));
check = SDL_GetRendererInfo(w->sdl_renderer, info);
free(info);
if (check != 0)
{
SDL_Log("error: %s\n", SDL_GetError());
return ;
}
if (w && w->sdl_renderer)
SDL_RenderPresent(w->sdl_renderer);
}
|
dolovnyak/ray-marching-render | libui/src/utilits/ui_surface_pixel.c | /* ************************************************************************** */
/* */
/* ::: :::::::: */
/* filler.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: sbecker <<EMAIL>> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/07/10 15:29:55 by sbednar #+# #+# */
/* Updated: 2019/07/15 16:45:46 by sbecker ### ########.fr */
/* */
/* ************************************************************************** */
#include "libui.h"
Uint32 ui_surface_get_pixel(t_sur *surface, int x, int y)
{
int bpp;
Uint8 *p;
bpp = surface->format->BytesPerPixel;
p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp;
return (*(Uint32 *)p);
}
void ui_surface_set_pixel(t_sur *surface, int x, int y, Uint32 pixel)
{
int bpp;
Uint8 *p;
bpp = surface->format->BytesPerPixel;
p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp;
*(Uint32 *)p = pixel;
}
|
dolovnyak/ray-marching-render | include/rt_system.h | /* ************************************************************************** */
/* */
/* ::: :::::::: */
/* rt_system.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: sbecker <<EMAIL>> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/04/10 05:13:21 by sbecker #+# #+# */
/* Updated: 2019/07/03 20:16:18 by sbecker ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef RT_SYSTEM_H
# define RT_SYSTEM_H
# ifndef OPENCL___
# ifdef APPLE___
# include <OpenCL/opencl.h>
# else
# include <opencl.h>
# endif
# include <SDL.h>
# include "libft.h"
# endif
typedef struct s_system
{
SDL_Thread *thread;
size_t delay;
Uint64 last;
Uint64 now;
cl_float delta_time;
void *parent;
} t_system;
typedef int (t_system_func)(void *);
int system_setup(t_system *s, const char *n, t_system_func *f, const size_t d);
int system_start(t_system *s);
#endif
|
dolovnyak/ray-marching-render | libui/src/ui_main/ui_main_init.c | /* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ui_main_init.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: sbednar <<EMAIL>> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/03/30 21:20:31 by sbednar #+# #+# */
/* Updated: 2019/07/08 23:05:12 by sbednar ### ########.fr */
/* */
/* ************************************************************************** */
#include "libui.h"
t_ui_main *ui_main_init(void)
{
t_ui_main *m;
if (!(m = (t_ui_main *)malloc(sizeof(t_ui_main))))
ui_sdl_deinit(228);
ft_bzero(m, sizeof(t_ui_main));
if (!(m->raycaster = (t_ui_raycaster *)malloc(sizeof(t_ui_raycaster))))
ui_sdl_deinit(228);
ft_bzero(m->raycaster, sizeof(t_ui_raycaster));
if (!(m->sdl_event = (SDL_Event *)malloc(sizeof(SDL_Event))))
ui_sdl_deinit(228);
ft_bzero(m->sdl_event, sizeof(SDL_Event));
m->state = SDL_GetKeyboardState(NULL);
return (m);
}
|
dolovnyak/ray-marching-render | libui/src/ui_main/ui_main_add_surface_by_path.c | /* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ui_main_add_surface_by_path.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: edraugr- <<EMAIL>> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/04/30 19:20:16 by sbednar #+# #+# */
/* Updated: 2019/07/15 11:58:52 by sbecker ### ########.fr */
/* */
/* ************************************************************************** */
#include "libui.h"
int ui_main_add_surface_by_path(t_ui_main *m,
const char *path, const char *sur_id)
{
SDL_Surface *sur;
t_list *lst;
int hash;
lst = NULL;
if (!(sur = IMG_Load(path)) ||
!(lst = ft_lstnew(NULL, 0)))
ui_sdl_deinit(228);
hash = ft_strhash(sur_id);
lst->content = (void *)sur;
lst->content_size = hash;
ft_lstadd(&(m->sdl_surfaces), lst);
return (FUNCTION_SUCCESS);
}
|
dolovnyak/ray-marching-render | include/rt_object.h | <reponame>dolovnyak/ray-marching-render
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* rt_object.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: sbecker <<EMAIL>> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/04/10 05:13:21 by sbecker #+# #+# */
/* Updated: 2019/07/03 20:16:18 by sbecker ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef RT_OBJECT_H
# define RT_OBJECT_H
# ifndef OPENCL___
# ifdef APPLE___
# include <OpenCL/opencl.h>
# else
# include <opencl.h>
# endif
# endif
# include "transform.h"
typedef struct s_sphere
{
# ifndef OPENCL___
cl_float radius;
# else
float radius;
# endif
} t_sphere;
typedef struct s_box
{
# ifndef OPENCL___
cl_float3 bounds;
# else
float3 bounds;
# endif
} t_box;
typedef struct s_round_box
{
# ifndef OPENCL___
cl_float3 bounds;
cl_float r;
# else
float3 bounds;
float r;
# endif
} t_round_box;
typedef struct s_torus
{
# ifndef OPENCL___
cl_float radius;
cl_float inner_radius;
# else
float radius;
float inner_radius;
# endif
} t_torus;
typedef struct s_capped_torus
{
# ifndef OPENCL___
cl_float2 sc;
cl_float ra;
cl_float rb;
# else
float2 sc;
float ra;
float rb;
# endif
} t_capped_torus;
typedef struct s_link
{
# ifndef OPENCL___
cl_float le;
cl_float r1;
cl_float r2;
# else
float le;
float r1;
float r2;
# endif
} t_link;
typedef struct s_cylinder
{
# ifndef OPENCL___
cl_float3 params;
# else
float3 params;
# endif
} t_cylinder;
typedef struct s_cone
{
# ifndef OPENCL___
cl_float2 c;
# else
float2 c;
# endif
} t_cone;
typedef struct s_plane
{
# ifndef OPENCL___
cl_float distance;
# else
float distance;
# endif
} t_plane;
typedef struct s_mandelbulb
{
# ifndef OPENCL___
float power;
int iteration;
int breakout;
# else
float power;
int iteration;
int breakout;
# endif
} t_mandelbulb;
typedef struct s_mandelbox
{
# ifndef OPENCL___
cl_float3 cube_size;
float scale;
float fixedradius;
float minradius;
int iteration;
# else
float3 cube_size;
float scale;
float fixedradius;
float minradius;
int iteration;
# endif
} t_mandelbox;
typedef struct s_menger_sponge
{
# ifndef OPENCL___
cl_float3 offset;
float scale;
int iteration;
# else
float3 offset;
float scale;
int iteration;
# endif
} t_menger_sponge;
typedef struct s_octahedron
{
# ifndef OPENCL___
float bounds;
# else
float bounds;
# endif
} t_octahedron;
union u_oparams
{
t_sphere sphere;
t_box box;
t_round_box round_box;
t_torus torus;
t_capped_torus capped_torus;
t_link link;
t_cylinder cylinder;
t_cone cone;
t_plane plane;
t_octahedron octahedron;
t_mandelbulb mandelbulb;
t_mandelbox mandelbox;
t_menger_sponge menger_sponge;
};
enum e_object_type
{
o_sphere = 1,
o_box,
o_round_box,
o_torus,
o_capped_torus,
o_link,
o_cylinder,
o_cone,
o_plane,
o_octahedron,
o_mandelbulb,
o_mandelbox,
o_menger_sponge
};
typedef struct s_omaterial
{
# ifndef OPENCL___
cl_float4 color;
cl_int texture_id;
cl_float2 offset; // смещение текстуры
cl_float2 tiling; // размер текстуры
cl_float3 luminosity;
# else
float4 color;
int texture_id;
float2 offset;
float2 tiling;
float3 luminosity;
# endif
} t_omaterial;
typedef struct s_object
{
# ifndef OPENCL___
t_transform transform;
union u_oparams params;
enum e_object_type type;
t_omaterial material;
char *local_name;
int sub_mult_flag;
int obj_with_oper_id;
int layer;
# else
t_transform transform;
union u_oparams params;
enum e_object_type type;
t_omaterial material;
int2 local_name;
int sub_mult_flag;
int obj_with_oper_id;
int layer;
# endif
} t_object;
#endif
|
dolovnyak/ray-marching-render | libui/src/ui_sdl/ui_sdl_set_render.c | /* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ui_sdl_set_render.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: sbecker <<EMAIL>> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/07/15 12:22:33 by sbecker #+# #+# */
/* Updated: 2019/07/15 12:22:34 by sbecker ### ########.fr */
/* */
/* ************************************************************************** */
#include "libui.h"
void ui_sdl_set_render_target(SDL_Renderer *r, SDL_Texture *t)
{
SDL_SetRenderTarget(r, t);
}
void ui_sdl_set_render_draw_color(SDL_Renderer *r, SDL_Color *c)
{
SDL_SetRenderDrawColor(r, c->r, c->g, c->b, c->a);
}
void ui_sdl_set_render_draw_blend_mode(SDL_Renderer *r, SDL_BlendMode b)
{
SDL_SetRenderDrawBlendMode(r, b);
}
|
dolovnyak/ray-marching-render | libui/src/ui_prefab/ui_prefab_get_pixel_pos.c | <filename>libui/src/ui_prefab/ui_prefab_get_pixel_pos.c
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ui_prefab_get_pixel_pos.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: sbecker <<EMAIL>> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/06/05 23:45:08 by sbecker #+# #+# */
/* Updated: 2019/06/06 01:25:11 by sbecker ### ########.fr */
/* */
/* ************************************************************************** */
#include "libui.h"
void ui_prefab_get_pixel_pos(t_ui_el *p, t_ui_el *canvas, int type,
t_fvec2 *v)
{
if ((type & ABS) && (type & PIXEL))
{
v->x = roundf(v->x);
v->y = roundf(v->y);
}
else if ((type & ABS))
{
v->x = roundf((float)canvas->rect.w * v->x);
v->y = roundf((float)canvas->rect.h * v->y);
}
else if ((type & PIXEL))
{
v->x = roundf((float)p->rect.x + v->x);
v->y = roundf((float)p->rect.y + v->y);
}
else
{
v->x = roundf((float)p->rect.x + (float)p->rect.w * v->x);
v->y = roundf((float)p->rect.y + (float)p->rect.h * v->y);
}
}
|
dolovnyak/ray-marching-render | src/rt_jtoc/rt_jtoc_get_lights.c | <gh_stars>1-10
//
// Created by <NAME> on 2019-09-15.
//
#include "rt.h"
#include "rt_jtoc.h"
int check_lights_and_get_lights_count(unsigned int *lights_num, t_jnode *n)
{
t_jnode *tmp;
if ((!(tmp = jtoc_node_get_by_path(n, "ambient")) || tmp->type != object) &&
(!(tmp = jtoc_node_get_by_path(n, "directional_lights")) || tmp->type != array) &&
(!(tmp = jtoc_node_get_by_path(n, "point_lights")) || tmp->type != array))
return (FUNCTION_FAILURE);
if (rt_jtoc_get_objects_num_in_arr(lights_num, jtoc_node_get_by_path(n, "directional_lights")))
return (FUNCTION_FAILURE);
if (rt_jtoc_get_objects_num_in_arr(lights_num, jtoc_node_get_by_path(n, "point_lights")))
return (FUNCTION_FAILURE);
return (FUNCTION_SUCCESS);
}
int rt_jtoc_check_and_get_id_for_light(t_scene *scene, t_jnode *n, t_light *light)
{
t_jnode *tmp;
cl_uint id;
if (!(tmp = jtoc_node_get_by_path(n, "id")) || tmp->type != integer)
return (FUNCTION_SUCCESS);
id = jtoc_get_int(tmp);
if (id <= 0)
return (rt_jtoc_sdl_log_error("ID ERROR", -1));
if (scene->camera.transform.id == (cl_uint)id)
return (rt_jtoc_sdl_log_error("THAT ID ALREADY EXISTS IN CAMERA", id));
if (rt_find_light_by_id(scene->lights, id) != NULL)
return (rt_jtoc_sdl_log_error("THAT ID ALREADY EXISTS IN LIGHTS", id));
light->transform.id = (cl_uint)id;
return (FUNCTION_SUCCESS);
}
int get_directional_lights(t_scene *scene, t_jnode *n)
{
t_light light;
t_jnode *tmp;
t_jnode *tmp2;
if (n == NULL)
return (FUNCTION_SUCCESS);
tmp = n->down;
while (tmp)
{
if (tmp->type != object)
return (rt_jtoc_sdl_log_error("TYPE ERROR", -1));
ft_bzero(&light, sizeof(t_light));
light.type = directional;
if (!(tmp2 = jtoc_node_get_by_path(tmp, "color")) || tmp2->type != object)
return (rt_jtoc_sdl_log_error("COLOR TYPE ERROR OR COLOR IS MISSING", -1));
if (rt_jtoc_get_float3(&light.params.directional.color, tmp2) ||
rt_jtoc_is01_float3(&light.params.directional.color))
return (rt_jtoc_sdl_log_error("COLOR ERROR", -1));
if (rt_jtoc_get_transform(&light.transform, tmp))
return (rt_jtoc_sdl_log_error("TRANSFORM ERROR", -1));
if (rt_jtoc_check_and_get_id_for_light(scene, tmp, &light))
return (rt_jtoc_sdl_log_error("ID ERROR", -1));
vec_push_back(scene->lights, &light);
tmp = tmp->right;
}
return (FUNCTION_SUCCESS);
}
int get_point_lights(t_scene *scene, t_jnode *n)
{
t_light light;
t_jnode *tmp;
t_jnode *tmp2;
if (n == NULL)
return (FUNCTION_SUCCESS);
tmp = n->down;
while (tmp)
{
if (tmp->type != object)
return (rt_jtoc_sdl_log_error("TYPE ERROR", -1));
ft_bzero(&light, sizeof(t_light));
light.type = point;
if (!(tmp2 = jtoc_node_get_by_path(tmp, "color")) || tmp2->type != object)
return (rt_jtoc_sdl_log_error("COLOR TYPE ERROR OR COLOR IS MISSING", -1));
if (rt_jtoc_get_float3(&light.params.point.color, tmp2) ||
rt_jtoc_is01_float3(&light.params.point.color))
return (rt_jtoc_sdl_log_error("COLOR ERROR", -1));
if (rt_jtoc_get_transform(&light.transform, tmp))
return (rt_jtoc_sdl_log_error("TRANSFORM ERROR", -1));
if (!(tmp2 = jtoc_node_get_by_path(tmp, "distance")) || tmp2->type != fractional)
return (rt_jtoc_sdl_log_error("DISTANCE TYPE ERROR OR DISTANCE IS MISSING", -1));
light.params.point.distance = jtoc_get_float(tmp2);
if (light.params.point.distance <= 0)
return (rt_jtoc_sdl_log_error("DISTANCE ERROR", -1));
if (rt_jtoc_check_and_get_id_for_light(scene, tmp, &light))
return (rt_jtoc_sdl_log_error("ID ERROR", -1));
vec_push_back(scene->lights, &light);
tmp = tmp->right;
}
return (FUNCTION_SUCCESS);
}
int rt_jtoc_get_lights(t_scene *scene, t_jnode *n)
{
t_jnode *tmp;
uint c;
c = 0;
if (check_lights_and_get_lights_count(&c, n))
return (rt_jtoc_sdl_log_error("LIGHTS IS NOT SET OR LIGHT TYPE ERROR", -1));
if ((tmp = jtoc_node_get_by_path(n, "ambient")) && tmp->type == object)
if (rt_jtoc_get_float3(&(scene->ambient), tmp) || rt_jtoc_ispos_float3(&scene->ambient))
return (rt_jtoc_sdl_log_error("AMBIENT ERROR", -1));
if (!(scene->lights = vec_init(c, sizeof(t_light))))
return (FUNCTION_FAILURE);
if (scene->lights->capacity > 0)
{
if (get_directional_lights(scene, jtoc_node_get_by_path(n, "directional_lights")))
return (rt_jtoc_sdl_log_error("DIRECTIONAL LIGHTS ERROR", -1));
if (get_point_lights(scene, jtoc_node_get_by_path(n, "point_lights")))
return (rt_jtoc_sdl_log_error("POINT LIGHTS ERROR", -1));
}
return (FUNCTION_SUCCESS);
}
|
dolovnyak/ray-marching-render | libui/src/ui_el/ui_el_event_switch_radio.c | <reponame>dolovnyak/ray-marching-render
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ui_el_event_switch_radio.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: edraugr- <<EMAIL>> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/07/12 07:50:40 by sbecker #+# #+# */
/* Updated: 2019/07/15 04:01:35 by edraugr- ### ########.fr */
/* */
/* ************************************************************************** */
#include "libui.h"
int ui_el_event_switch_radio(t_ui_main *m, void *a)
{
t_ui_el *el;
(void)m;
el = (t_ui_el *)a;
if (!(((t_ui_el *)el->children->content)->params & EL_IS_HIDDEN))
((t_ui_el *)el->children->content)->params |= EL_IS_HIDDEN;
else
((t_ui_el *)el->children->content)->params &= ~EL_IS_HIDDEN;
return (1);
}
|
dolovnyak/ray-marching-render | libui/src/ui_el/ui_el_event_default_draw.c | <filename>libui/src/ui_el/ui_el_event_default_draw.c
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ui_el_event_default_draw.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: sbecker <<EMAIL>> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/07/12 04:32:52 by sbecker #+# #+# */
/* Updated: 2019/07/15 08:21:03 by sbecker ### ########.fr */
/* */
/* ************************************************************************** */
#include "libui.h"
static void get_texture_params(SDL_Texture *texture, t_rect *srect,
int *width, int *height)
{
SDL_QueryTexture(texture, NULL, NULL, width, height);
srect->x = 0;
srect->y = 0;
srect->w = *width;
srect->h = *height;
}
static void cutting_texture_and_draw(t_ui_el *el, SDL_Texture *texture)
{
t_rect tmp_rect;
t_rect srect;
int width;
int height;
tmp_rect = el->rect;
get_texture_params(texture, &srect, &width, &height);
if ((el->params & EL_IS_TEXT) && (el->text_area->params & TEXT_IS_REGULAR))
tmp_rect.w = roundf(((float)width * tmp_rect.h) / (float)height);
else if ((el->params & EL_IS_TEXT) && width < tmp_rect.w)
{
if (el->text_area->params & TEXT_IS_CENTERED)
{
tmp_rect.x = tmp_rect.x + ((tmp_rect.w - width) + 0.5) / 2;
tmp_rect.w = width;
}
else
tmp_rect.w = width;
}
ui_el_texture_x_w(el, &srect, &tmp_rect, width);
ui_el_texture_y_h(el, &srect, &tmp_rect, height);
el->crect = tmp_rect;
SDL_RenderCopy(el->sdl_renderer, texture, &srect, &tmp_rect);
}
int ui_el_event_default_draw(t_ui_main *m, void *a2)
{
t_ui_el *el;
SDL_Texture *texture;
(void)m;
el = (t_ui_el *)a2;
texture = ui_el_get_current_texture(el);
if (el->params & EL_IS_DEPENDENT)
{
cutting_texture_and_draw(el, texture);
return (1);
}
SDL_RenderCopy(el->sdl_renderer, texture, NULL, &el->rect);
return (1);
}
|
dolovnyak/ray-marching-render | libui/src/ui_main/ui_main_handle_window_event.c | /* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ui_main_handle_window_event.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: sbecker <<EMAIL>> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/03/31 02:19:12 by sbednar #+# #+# */
/* Updated: 2019/07/15 15:04:46 by sbecker ### ########.fr */
/* */
/* ************************************************************************** */
#include "libui.h"
static void invoke_event_with_lock_mutex(t_ui_event *event,
t_ui_main *m, t_ui_win *win)
{
SDL_LockMutex(m->mutex);
ui_event_invoke(event, m, win);
SDL_UnlockMutex(m->mutex);
}
void ui_main_handle_window_event(t_ui_main *m)
{
t_ui_win *win;
t_ui_event *event;
if ((win = ui_main_find_window_by_sdl_id(m,
m->sdl_event->window.windowID)) == NULL)
return ;
event = NULL;
if (m->sdl_event->window.event == SDL_WINDOWEVENT_CLOSE)
event = win->events->on_close;
else if (m->sdl_event->window.event == SDL_WINDOWEVENT_FOCUS_GAINED)
event = win->events->on_focus_gained;
else if (m->sdl_event->window.event == SDL_WINDOWEVENT_FOCUS_LOST)
event = win->events->on_focus_lost;
else if (m->sdl_event->window.event == SDL_WINDOWEVENT_ENTER)
event = win->events->on_focus_gained;
else if (m->sdl_event->window.event == SDL_WINDOWEVENT_LEAVE)
event = win->events->on_focus_lost;
else if (m->sdl_event->window.event == SDL_WINDOWEVENT_RESIZED)
event = win->events->on_resize;
else if (m->sdl_event->window.event == SDL_WINDOWEVENT_MOVED)
event = win->events->on_moved;
if (event != NULL)
invoke_event_with_lock_mutex(event, m, win);
}
|
dolovnyak/ray-marching-render | libui/src/ui_jtoc/ui_jtoc_efj_helper1.c | /* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ui_jtoc_efj_helper1.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: sbecker <<EMAIL>> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/07/15 07:23:48 by edraugr- #+# #+# */
/* Updated: 2019/07/15 15:14:23 by sbecker ### ########.fr */
/* */
/* ************************************************************************** */
#include "libui.h"
int ui_el_from_json_white_texture(t_ui_el *e, t_jnode *n)
{
t_jnode *t;
int w;
int h;
char *el_id;
if (!(t = jtoc_node_get_by_path(n, "width")) || !ui_jtoc_isnum(t->type) ||
(w = jtoc_get_int(t)) <= 0 ||
!(t = jtoc_node_get_by_path(n, "height")) || !ui_jtoc_isnum(t->type) ||
(h = jtoc_get_int(t)) <= 0 ||
!(t = jtoc_node_get_by_path(n, "el_id")) || t->type != string ||
!(el_id = jtoc_get_string(t)))
return (ui_jtoc_sdl_log_error("NODE EL (WHITE TEXTURE)", e->id));
ui_el_add_white_texture(e, w, h, el_id);
return (FUNCTION_SUCCESS);
}
int ui_el_from_json_empty_texture(t_ui_el *e, t_jnode *n)
{
t_jnode *t;
int w;
int h;
char *el_id;
if (!(t = jtoc_node_get_by_path(n, "width")) || !ui_jtoc_isnum(t->type) ||
(w = jtoc_get_int(t)) <= 0 ||
!(t = jtoc_node_get_by_path(n, "height")) || !ui_jtoc_isnum(t->type) ||
(h = jtoc_get_int(t)) <= 0 ||
!(t = jtoc_node_get_by_path(n, "el_id")) || t->type != string ||
!(el_id = jtoc_get_string(t)))
return (ui_jtoc_sdl_log_error("NODE EL (EMPTY TEXTURE)", e->id));
ui_el_add_empty_texture(e, w, h, el_id);
return (FUNCTION_SUCCESS);
}
int ui_el_from_json_color_texture(t_ui_el *e, t_jnode *n)
{
t_jnode *t;
char *color;
char *el_id;
if (!(t = jtoc_node_get_by_path(n, "color")) || t->type != string ||
!(color = jtoc_get_string(t)) ||
!(t = jtoc_node_get_by_path(n, "el_id")) || t->type != string ||
!(el_id = jtoc_get_string(t)))
return (ui_jtoc_sdl_log_error("NODE EL (COLOR TEXTURE)", e->id));
ui_el_add_color_texture(e, (t_vec2){e->rect.w, e->rect.h},
ft_atoi_base(color, 16), el_id);
return (FUNCTION_SUCCESS);
}
int ui_el_from_json_gradient_texture(t_ui_el *e, t_jnode *n)
{
t_jnode *t;
char *color;
char *el_id;
if (!(t = jtoc_node_get_by_path(n, "color")) || t->type != string ||
!(color = jtoc_get_string(t)) ||
!(t = jtoc_node_get_by_path(n, "el_id")) || t->type != string ||
!(el_id = jtoc_get_string(t)))
return (ui_jtoc_sdl_log_error("NODE EL (GRADIENT TEXTURE)", e->id));
ui_el_add_gradient_texture(e, (t_vec2){e->rect.w, e->rect.h},
ft_atoi_base(color, 16), el_id);
return (FUNCTION_SUCCESS);
}
int ui_el_from_json_cursor(t_ui_main *m, t_ui_el *e, t_jnode *n)
{
t_jnode *t;
t_cursor *c;
if ((n = jtoc_node_get_by_path(n, "cursor")))
{
if (!(c = ui_cursor_init()))
ui_sdl_deinit(228);
if (!(t = jtoc_node_get_by_path(n, "texture_id")) ||
t->type != string ||
!(c->s = ui_main_get_surface_by_id(m, jtoc_get_string(t))) ||
!(t = jtoc_node_get_by_path(n, "hot_x"))
|| !ui_jtoc_isnum(t->type) || !(c->hot_x = jtoc_get_int(t)) ||
!(t = jtoc_node_get_by_path(n, "hot_y")) ||
!ui_jtoc_isnum(t->type) ||
!(c->hot_y = jtoc_get_int(t)))
ui_sdl_deinit(228);
e->data = (void *)c;
ui_event_add_listener(e->events->on_pointer_left_button_pressed,
ui_cursor_from_el_data);
}
return (FUNCTION_SUCCESS);
}
|
dolovnyak/ray-marching-render | libui/src/ui_jtoc/ui_jtoc_pref_text_modal_win.c | <reponame>dolovnyak/ray-marching-render<filename>libui/src/ui_jtoc/ui_jtoc_pref_text_modal_win.c
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ui_jtoc_pref_text_modal_win.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: sbecker <<EMAIL>> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/07/15 13:09:43 by sbecker #+# #+# */
/* Updated: 2019/07/15 13:27:10 by sbecker ### ########.fr */
/* */
/* ************************************************************************** */
#include "libui.h"
static void get_render_param(t_ui_text *ui_text, t_jnode *tmp)
{
int hash;
hash = ft_strhash(jtoc_get_string(tmp));
ui_text->render_param |= (hash == ft_strhash("TEXT_IS_SOLID") ?
TEXT_IS_SOLID : 0);
ui_text->render_param |= (hash == ft_strhash("TEXT_IS_SHADED") ?
TEXT_IS_SHADED : 0);
ui_text->render_param |= (hash == ft_strhash("TEXT_IS_BLENDED") ?
TEXT_IS_BLENDED : 0);
}
static void get_text_param(t_ui_text *ui_text, t_jnode *tmp)
{
int hash;
hash = ft_strhash(jtoc_get_string(tmp));
ui_text->params |= (hash == ft_strhash("TEXT_IS_CENTERED") ?
TEXT_IS_CENTERED : 0);
ui_text->params |= (hash == ft_strhash("TEXT_IS_INPUTTING") ?
TEXT_IS_INPUTTING : 0);
ui_text->params |= (hash == ft_strhash("TEXT_IS_REGULAR") ?
TEXT_IS_REGULAR : 0);
}
static int get_modal_text_params(t_ui_text *ui_text, t_jnode *n)
{
t_jnode *tmp;
if ((tmp = jtoc_node_get_by_path(n, "text_area.string_len"))
&& ui_jtoc_isnum(tmp->type))
ui_text->string_len = jtoc_get_int(tmp);
if ((tmp = jtoc_node_get_by_path(n, "text_area.render_param"))
&& tmp->type == string)
get_render_param(ui_text, tmp);
else
ui_text->render_param |= TEXT_IS_BLENDED;
if ((tmp = jtoc_node_get_by_path(n, "text_area.params")))
{
tmp = tmp->down;
while (tmp)
{
if (tmp->type != string)
return (FUNCTION_FAILURE);
get_text_param(ui_text, tmp);
tmp = tmp->right;
}
}
return (FUNCTION_SUCCESS);
}
static int get_modal_font_color(t_ui_main *m, t_ui_text *ui_text, t_jnode *n)
{
t_jnode *tmp;
if ((tmp = jtoc_node_get_by_path(n, "text_area.font"))
&& tmp->type == string)
{
if (!(ui_text->font = ui_main_get_font_by_id(m, jtoc_get_string(tmp))))
return (FUNCTION_FAILURE);
}
else
return (FUNCTION_FAILURE);
if ((tmp = jtoc_node_get_by_path(n, "text_area.color"))
&& tmp->type == string)
ui_text->text_color = ui_util_get_sdl_color(
ft_atoi_base(jtoc_get_string(tmp), 16));
else
return (FUNCTION_FAILURE);
if ((tmp = jtoc_node_get_by_path(n, "text_area.bg_color"))
&& tmp->type == string)
ui_text->bg_color = ui_util_get_sdl_color(
ft_atoi_base(jtoc_get_string(tmp), 16));
return (FUNCTION_SUCCESS);
}
int ui_jtoc_pref_text_modal_win(t_ui_main *m, t_jnode *n,
t_ui_text *ui_text)
{
t_jnode *tmp;
if ((jtoc_node_get_by_path(n, "text_area")))
{
if (get_modal_font_color(m, ui_text, n) == FUNCTION_FAILURE)
return (FUNCTION_FAILURE);
if (get_modal_text_params(ui_text, n) == FUNCTION_FAILURE)
return (FUNCTION_FAILURE);
if ((tmp = jtoc_node_get_by_path(n, "text_area.text"))
&& tmp->type == string)
ui_text->text = ft_strdup(jtoc_get_string(tmp));
else
return (FUNCTION_FAILURE);
return (FUNCTION_SUCCESS);
}
return (FUNCTION_FAILURE);
}
|
dolovnyak/ray-marching-render | src/rt_jtoc/rt_jtoc_get_objects_params.c | #include "rt.h"
#include "rt_jtoc.h"
int rt_jtoc_get_sphere(t_object *obj, t_jnode *n)
{
t_jnode *tmp;
if (!(tmp = jtoc_node_get_by_path(n, "radius")) || tmp->type != fractional)
return (rt_jtoc_sdl_log_error("RADIUS TYPE ERROR OR RADIUS IS MISSING", -1));
obj->params.sphere.radius = jtoc_get_float(tmp);
if (obj->params.sphere.radius <= 0 || obj->params.sphere.radius >= 1000)
return (rt_jtoc_sdl_log_error("RADIUS ERROR", -1));
return (FUNCTION_SUCCESS);
}
int rt_jtoc_get_box(t_object *obj, t_jnode *n)
{
t_jnode *tmp;
if (!(tmp = jtoc_node_get_by_path(n, "bounds")) || tmp->type != object)
return (rt_jtoc_sdl_log_error("BOUNDS TYPE ERROR OR BOUNDS IS MISSING", -1));
if (rt_jtoc_get_float3(&obj->params.box.bounds, tmp) ||
rt_jtoc_ispos_float3(&obj->params.box.bounds))
return (rt_jtoc_sdl_log_error("BOUNDS ERROR", -1));
return (FUNCTION_SUCCESS);
}
int rt_jtoc_get_round_box(t_object *obj, t_jnode *n)
{
t_jnode *tmp;
if (!(tmp = jtoc_node_get_by_path(n, "bounds")) || tmp->type != object)
return (rt_jtoc_sdl_log_error("BOUNDS TYPE ERROR OR BOUNDS IS MISSING", -1));
if (rt_jtoc_get_float3(&obj->params.round_box.bounds, tmp))
return (rt_jtoc_sdl_log_error("BOUNDS ERROR", -1));
if (rt_jtoc_ispos_float3(&obj->params.round_box.bounds))
return (rt_jtoc_sdl_log_error("BOUNDS ERROR", -1));
if (!(tmp = jtoc_node_get_by_path(n, "rounding_radius")) || tmp->type != fractional)
return (rt_jtoc_sdl_log_error("ROUNDING_RADIUS TYPE ERROR"
" OR ROUNDING_RADIUS IS MISSING", -1));
obj->params.round_box.r = jtoc_get_float(tmp);
if (obj->params.round_box.r <= 0 || obj->params.round_box.r >= 1000)
return (rt_jtoc_sdl_log_error("RADIUS ERROR", -1));
return (FUNCTION_SUCCESS);
}
int rt_jtoc_get_torus(t_object *obj, t_jnode *n)
{
t_jnode *tmp;
if (!(tmp = jtoc_node_get_by_path(n, "radius")) || tmp->type != fractional)
return (rt_jtoc_sdl_log_error("RADIUS TYPE ERROR OR RADIUS IS MISSING", -1));
obj->params.torus.radius = jtoc_get_float(tmp);
if (obj->params.torus.radius <= 0 || obj->params.torus.radius >= 1000)
return (rt_jtoc_sdl_log_error("RADIUS ERROR", -1));
if (!(tmp = jtoc_node_get_by_path(n, "inner_radius")) || tmp->type != fractional)
return (rt_jtoc_sdl_log_error("INNER_RADIUS TYPE ERROR"
" OR INNER_RADIUS IS MISSING", -1));
obj->params.torus.inner_radius = jtoc_get_float(tmp);
if (obj->params.torus.inner_radius <= 0 || obj->params.torus.inner_radius >= 1000)
return (rt_jtoc_sdl_log_error("INNER RADIUS ERROR", -1));
return (FUNCTION_SUCCESS);
}
int rt_jtoc_get_plane(t_object *obj, t_jnode *n)
{
t_jnode *tmp;
if (!(tmp = jtoc_node_get_by_path(n, "distance")) || tmp->type != fractional)
return (rt_jtoc_sdl_log_error("DISTANCE TYPE ERROR OR DISTANCE IS MISSING", -1));
obj->params.plane.distance = jtoc_get_float(tmp);
if (obj->params.plane.distance >= 1000)
return (rt_jtoc_sdl_log_error("DISTANCE ERROR", -1));
return (FUNCTION_SUCCESS);
}
int rt_jtoc_get_cone(t_object *obj, t_jnode *n)
{
t_jnode *tmp;
if (!(tmp = jtoc_node_get_by_path(n, "params")) || tmp->type != object)
return (rt_jtoc_sdl_log_error("PARAMS TYPE ERROR OR PARAMS IS MISSING", -1));
if (rt_jtoc_get_float2(&obj->params.cone.c, tmp) ||
rt_jtoc_ispos_float2(&obj->params.cone.c))
return (rt_jtoc_sdl_log_error("PARAMS ERROR", -1));
return (FUNCTION_SUCCESS);
}
int rt_jtoc_get_cylinder(t_object *obj, t_jnode *n)
{
t_jnode *tmp;
if (!(tmp = jtoc_node_get_by_path(n, "params")) || tmp->type != object)
return (rt_jtoc_sdl_log_error("PARAMS TYPE ERROR OR PARAMS IS MISSING", -1));
if (rt_jtoc_get_float3(&obj->params.cylinder.params, tmp) ||
rt_jtoc_ispos_float3(&obj->params.cylinder.params))
return (rt_jtoc_sdl_log_error("PARAMS ERROR", -1));
return (FUNCTION_SUCCESS);
}
int rt_jtoc_get_link(t_object *obj, t_jnode *n)
{
t_jnode *tmp;
if (!(tmp = jtoc_node_get_by_path(n, "le")) || tmp->type != fractional)
return (rt_jtoc_sdl_log_error("LE TYPE ERROR OR LE IS MISSING", -1));
obj->params.link.le = jtoc_get_float(tmp);
if (obj->params.link.le < 0)
return (rt_jtoc_sdl_log_error("LE ERROR", -1));
if (!(tmp = jtoc_node_get_by_path(n, "r1")) || tmp->type != fractional)
return (rt_jtoc_sdl_log_error("R1 TYPE ERROR OR R1 IS MISSING", -1));
obj->params.link.r1 = jtoc_get_float(tmp);
if (obj->params.link.r1 <= 0)
return (rt_jtoc_sdl_log_error("R1 ERROR", -1));
if (!(tmp = jtoc_node_get_by_path(n, "r2")) || tmp->type != fractional)
return (rt_jtoc_sdl_log_error("R2 TYPE ERROR OR R2 IS MISSING", -1));
obj->params.link.r2 = jtoc_get_float(tmp);
if (obj->params.link.r2 <= 0)
return (rt_jtoc_sdl_log_error("R2 ERROR", -1));
return (FUNCTION_SUCCESS);
}
int rt_jtoc_get_octahedron(t_object *obj, t_jnode *n)
{
t_jnode *tmp;
if (!(tmp = jtoc_node_get_by_path(n, "bounds")) || tmp->type != fractional)
return (rt_jtoc_sdl_log_error("BOUNDS ERROR OR MISSING", -1));
obj->params.octahedron.bounds = jtoc_get_float(tmp);
if (obj->params.octahedron.bounds <= 0)
return (rt_jtoc_sdl_log_error("BOUNDS ERROR", -1));
return (FUNCTION_SUCCESS);
}
int rt_jtoc_get_mandelbulb(t_object *obj, t_jnode *n)
{
t_jnode *tmp;
if (!(tmp = jtoc_node_get_by_path(n, "power")) || tmp->type != fractional)
return (rt_jtoc_sdl_log_error("POWER TYPE ERROR OR POWER IS MISSING", -1));
obj->params.mandelbulb.power = jtoc_get_float(tmp);
if (!(tmp = jtoc_node_get_by_path(n, "iteration")) || tmp->type != integer)
return (rt_jtoc_sdl_log_error("ITERTATION TYPE ERROR OR ITERTATION IS MISSING", -1));
obj->params.mandelbulb.iteration = jtoc_get_int(tmp);
if (!(tmp = jtoc_node_get_by_path(n, "breakout")) || tmp->type != integer)
return (rt_jtoc_sdl_log_error("BREAKOUT TYPE ERROR OR BREAKOUT IS MISSING", -1));
obj->params.mandelbulb.breakout = jtoc_get_int(tmp);
if (obj->params.mandelbulb.breakout <= 0 ||
obj->params.mandelbulb.breakout >= 50)
return (rt_jtoc_sdl_log_error("BREAKOUT ERROR", -1));
return (FUNCTION_SUCCESS);
}
int rt_jtoc_get_mandelbox(t_object *obj, t_jnode *n)
{
t_jnode *tmp;
if (!(tmp = jtoc_node_get_by_path(n, "scale")) || tmp->type != fractional)
return (rt_jtoc_sdl_log_error("POWER SCALE ERROR OR SCALE IS MISSING", -1));
obj->params.mandelbox.scale = jtoc_get_float(tmp);
if (obj->params.mandelbox.scale <= 0)
return (rt_jtoc_sdl_log_error("SCALE ERROR", -1));
if (!(tmp = jtoc_node_get_by_path(n, "fixedradius")) || tmp->type != fractional)
return (rt_jtoc_sdl_log_error("FIXEDRADUIS TYPE ERROR OR FIXEDRADIUS IS MISSING", -1));
obj->params.mandelbox.fixedradius = jtoc_get_float(tmp);
if (obj->params.mandelbox.fixedradius <= 0)
return (rt_jtoc_sdl_log_error("FIXED RADIUS ERROR", -1));
if (!(tmp = jtoc_node_get_by_path(n, "minradius")) || tmp->type != fractional)
return (rt_jtoc_sdl_log_error("MINRADIUS TYPE ERROR OR MINRADIUS IS MISSING", -1));
obj->params.mandelbox.minradius = jtoc_get_float(tmp);
if (obj->params.mandelbox.minradius <= 0)
return (rt_jtoc_sdl_log_error("MIN RADIUS ERROR", -1));
if (!(tmp = jtoc_node_get_by_path(n, "iteration")) || tmp->type != integer)
return (rt_jtoc_sdl_log_error("ITERTATION TYPE ERROR OR ITERTATION IS MISSING", -1));
obj->params.mandelbox.iteration = jtoc_get_int(tmp);
if (!(tmp = jtoc_node_get_by_path(n, "cube_size")) || tmp->type != object)
return (rt_jtoc_sdl_log_error("CUBE SIZE TYPE ERROR OR CUBE SIZE IS MISSING", -1));
if (rt_jtoc_get_float3(&obj->params.mandelbox.cube_size, tmp) ||
rt_jtoc_ispos_float3(&obj->params.mandelbox.cube_size))
return (rt_jtoc_sdl_log_error("CUBE SIZE ERROR", -1));
return (FUNCTION_SUCCESS);
}
int rt_jtoc_get_menger_sponge(t_object *obj, t_jnode *n)
{
t_jnode *tmp;
if (!(tmp = jtoc_node_get_by_path(n, "scale")) || tmp->type != fractional)
return (rt_jtoc_sdl_log_error("POWER SCALE ERROR OR SCALE IS MISSING", -1));
obj->params.menger_sponge.scale = jtoc_get_float(tmp);
if (obj->params.menger_sponge.scale <= 0)
return (rt_jtoc_sdl_log_error("SCALE ERROR", -1));
if (!(tmp = jtoc_node_get_by_path(n, "iteration")) || tmp->type != integer)
return (rt_jtoc_sdl_log_error("ITERTATION TYPE ERROR OR ITERTATION IS MISSING", -1));
obj->params.menger_sponge.iteration = jtoc_get_int(tmp);
if (!(tmp = jtoc_node_get_by_path(n, "offset")) || tmp->type != object)
return (rt_jtoc_sdl_log_error("OFFSET TYPE ERROR OR OFFSET IS MISSING", -1));
if (rt_jtoc_get_float3(&obj->params.menger_sponge.offset, tmp))
return (rt_jtoc_sdl_log_error("OFFSET ERROR", -1));
return (FUNCTION_SUCCESS);
} |
dolovnyak/ray-marching-render | libui/include/libui.h | <gh_stars>1-10
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* libui.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: edraugr- <<EMAIL>> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/03/10 19:09:04 by sbednar #+# #+# */
/* Updated: 2019/07/15 18:53:36 by edraugr- ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef LIBUI_H
# define LIBUI_H
# include <SDL.h>
# include <SDL_ttf.h>
# include <SDL_image.h>
# include <math.h>
# include "libft.h"
# include "libjtoc.h"
# define DEBUG_STATUS 0
# define KNRM "\x1B[0m"
# define KRED "\x1B[31m"
# define KGRN "\x1B[32m"
# define KYEL "\x1B[33m"
# define KBLU "\x1B[34m"
# define KMAG "\x1B[35m"
# define KCYN "\x1B[36m"
# define KWHT "\x1B[37m"
# define KEYS_COUNT 285
# define CAST_X_TO_Y(x, y) ((y)x)
# define SCROLL_SPEED 20
/*
** el params
*/
# define EL_IGNOR_RAYCAST (1 << 0)
# define EL_IS_HIDDEN (1 << 1)
# define EL_IS_PTR_INSIDE (1 << 2)
# define EL_IS_SCROLLABLE (1 << 3)
# define EL_IS_DEPENDENT (1 << 4)
# define EL_IS_TEXT (1 << 5)
# define EL_MODAL_OK (1 << 6)
# define EL_MODAL_OK_CANCEL (1 << 7)
# define EL_IS_ICON (1 << 8)
/*
** text params
*/
# define TEXT_IS_CENTERED (1 << 0)
# define TEXT_IS_INPUTTING (1 << 1)
# define TEXT_IS_REGULAR (1 << 2)
/*
** text render_params
*/
# define TEXT_IS_SOLID (1 << 0)
# define TEXT_IS_SHADED (1 << 1)
# define TEXT_IS_BLENDED (1 << 2)
/*
** main events/params
*/
# define MAIN_LMB_PRESSED (1 << 0)
# define MAIN_RMB_PRESSED (1 << 1)
# define MAIN_SCROLL_UP (1 << 2)
# define MAIN_SCROLL_DOWN (1 << 3)
# define MAIN_LMB_RELEASED (1 << 4)
# define MAIN_LMB_HOLD (1 << 5)
# define MAIN_RMB_RELEASED (1 << 6)
# define MAIN_RMB_HOLD (1 << 7)
# define MAIN_ON_QUIT (1 << 8)
/*
** win params
*/
# define WIN_RESIZABLE (1 << 0)
# define WIN_IS_SHOWN (1 << 1)
# define WIN_IS_HIDDEN (1 << 2)
/*
** img types
*/
# define IMG_TYPE_PNG 0
# define IMG_TYPE_JPG 1
/*
** for set/chage pos/size
*/
# define ABS (1 << 0)
# define PIXEL (1 << 1)
/*
** choto dlya tekstur
*/
# define RGBA8888 373694468
# define BLEND 1
# define NONE 0
# define STATIC 0
# define WIN_CENTER SDL_WINDOWPOS_CENTERED
typedef void (*t_func_ptr)(void *, void *);
typedef int (*t_pred_ptr)(void *, void *);
typedef t_list t_queue;
typedef SDL_Rect t_rect;
typedef SDL_Texture t_texture;
typedef t_list t_list_texture;
typedef SDL_Renderer t_renderer;
typedef SDL_Color t_color;
typedef SDL_Surface t_sur;
/*
** Smart things:
** 1) It's possible to replace t_name_init just by ft_bzero in code;
** ...To be continued...
*/
typedef struct s_frect
{
float x;
float y;
float w;
float h;
} t_frect;
typedef struct s_ui_event
{
t_list *events;
} t_ui_event;
typedef struct s_ui_text
{
TTF_Font *font;
SDL_Color text_color;
SDL_Color bg_color;
char *text;
size_t string_len;
size_t cursor_pos;
Uint32 render_param;
Uint32 params;
} t_ui_text;
typedef struct s_ui_el_events
{
t_ui_event *on_pointer_enter;
t_ui_event *on_pointer_stay;
t_ui_event *on_pointer_exit;
t_ui_event *on_pointer_left_button_pressed;
t_ui_event *on_pointer_left_button_hold;
t_ui_event *on_pointer_left_button_released;
t_ui_event *on_pointer_right_button_pressed;
t_ui_event *on_pointer_right_button_hold;
t_ui_event *on_pointer_right_button_released;
t_ui_event *on_scroll_up;
t_ui_event *on_scroll_down;
t_ui_event *on_render;
t_ui_event *on_resize;
t_ui_event **on_key_down;
t_ui_event **on_key_up;
} t_ui_el_events;
struct s_ui_win;
typedef struct s_ui_el
{
SDL_Surface *sdl_surface;
t_list *sdl_textures;
SDL_Renderer *sdl_renderer;
struct s_ui_el *parent;
t_list *children;
size_t current_texture;
t_rect rect;
t_rect crect;
t_frect rrect;
t_vec2 ptr_rel_pos;
Uint32 id;
Uint32 params;
t_ui_text *text_area;
struct s_ui_win *modal_win;
t_ui_el_events *events;
void *data;
} t_ui_el;
typedef struct s_cursor
{
SDL_Surface *s;
int hot_x;
int hot_y;
} t_cursor;
typedef struct s_ui_win_events
{
t_ui_event *on_pointer_moved;
t_ui_event *on_pointer_enter;
t_ui_event *on_pointer_exit;
t_ui_event *on_pointer_left_button_pressed;
t_ui_event *on_pointer_left_button_released;
t_ui_event *on_pointer_right_button_pressed;
t_ui_event *on_pointer_right_button_released;
t_ui_event *on_scroll_up;
t_ui_event *on_scroll_down;
t_ui_event *on_focus_gained;
t_ui_event *on_focus_lost;
t_ui_event *on_resize;
t_ui_event *on_close;
t_ui_event *on_moved;
t_ui_event **on_key_down;
t_ui_event **on_key_up;
} t_ui_win_events;
typedef struct s_ui_win
{
SDL_Window *sdl_window;
SDL_Renderer *sdl_renderer;
Uint32 sdl_window_id;
char *title;
t_vec2 size;
t_vec2 pos;
t_ui_el *canvas;
t_ui_win_events *events;
Uint32 id;
Uint32 params;
} t_ui_win;
typedef struct s_ui_raycaster
{
t_ui_win *focused_win;
t_ui_el *selected;
} t_ui_raycaster;
typedef struct s_ui_main
{
t_list *windows;
SDL_Event *sdl_event;
SDL_mutex *mutex;
t_ui_raycaster *raycaster;
t_list *sdl_surfaces;
t_list *sdl_fonts;
t_list *functions;
t_ui_el *modal_el;
t_ui_el *focused_el;
Uint8 cur_keycode;
Uint8 is_upper;
void *data;
Uint32 params;
t_vec2 ptr_pos;
const Uint8 *state;
} t_ui_main;
typedef struct s_scroll_m_pref
{
int type_pos;
t_fvec2 begin_pos;
int type_size;
t_fvec2 size;
int type_indent;
t_fvec2 indent;
int params;
int begin_id;
SDL_Renderer *sdl_renderer;
char *texture;
} t_scroll_m_pref;
typedef struct s_resize_data
{
t_fvec2 elem_pos;
t_fvec2 elem_size;
t_fvec2 indent;
} t_resize_data;
typedef struct s_font_params
{
int style;
int hinting;
int kerning;
int outline;
} t_font_params;
typedef struct s_text_params
{
SDL_Color text_color;
SDL_Color bg_color;
int string_len;
int params;
int render_param;
} t_text_params;
typedef int (*t_pred_ptr_event)(t_ui_main *, void *);
t_ui_el *ui_raycast(t_ui_main *m, t_ui_win *w);
void ui_main_run_program(t_ui_main *m);
t_ui_main *ui_main_init(void);
void ui_main_loop(t_ui_main *m);
void ui_main_handle_event(t_ui_main *m);
void ui_main_handle_raycast(t_ui_main *m);
void ui_main_handle_window_event(t_ui_main *m);
void ui_main_handle_mouse_event(t_ui_main *m);
void ui_main_handle_keyboard_event(t_ui_main *m);
void ui_main_handle_continious_event(t_ui_main *m,
t_ui_el *el);
void ui_main_try_invoke_modal_windows(t_ui_main *m);
int ui_main_event_close_window(t_ui_main *m, void *a);
int ui_main_event_close_program(t_ui_main *m, void *a);
int ui_main_event_pointer_moved(t_ui_main *m, void *a);
int ui_main_event_lmb_pressed(t_ui_main *m, void *a);
int ui_main_event_lmb_released(t_ui_main *m, void *a);
int ui_main_event_rmb_pressed(t_ui_main *m, void *a);
int ui_main_event_rmb_released(t_ui_main *m, void *a);
int ui_main_event_scroll_up(t_ui_main *m, void *a);
int ui_main_event_scroll_down(t_ui_main *m, void *a);
int ui_main_add_font_by_path(t_ui_main *m,
const char *path, const char *font_id);
int ui_main_add_surface_by_path(t_ui_main *m,
const char *path, const char *sur_id);
int ui_main_add_window(t_ui_main *m, t_ui_win *w);
int ui_main_add_function_by_id(t_ui_main *m,
t_pred_ptr_event f, const char *func_id);
t_ui_win *ui_main_find_window_by_sdl_id(t_ui_main *m,
Uint32 window_id);
t_ui_win *ui_main_find_window_by_id(t_ui_main *m,
Uint32 window_id);
TTF_Font *ui_main_get_font_by_id(t_ui_main *m,
const char *font_id);
SDL_Surface *ui_main_get_surface_by_id(t_ui_main *m,
const char *sur_id);
t_pred_ptr_event ui_main_get_function_by_id(t_ui_main *m,
const char *func_id);
void ui_main_fill_default_surfaces(t_ui_main *m);
void ui_main_fill_default_fonts(t_ui_main *m);
void ui_main_fill_default_functions(t_ui_main *m);
void ui_main_save_texture(t_ui_win *win, SDL_Texture *t,
const char *path, int type);
void ui_main_open_texture(SDL_Renderer *r, t_ui_el *e,
const char *path);
int ui_main_set_font_params(t_ui_main *m,
const char *font_id, t_font_params params);
SDL_Texture *ui_main_merge_layers(SDL_Renderer *r, t_list *l);
int ui_log_mouse_motion(t_ui_main *m, void *a);
int ui_log_mouse_button_up(t_ui_main *m, void *a);
int ui_log_mouse_button_down(t_ui_main *m, void *a);
int ui_log_window_focus_gained(t_ui_main *m, void *a);
int ui_log_window_focus_lost(t_ui_main *m, void *a);
int ui_log_window_closed(t_ui_main *m, void *a);
int ui_log_window_resized(t_ui_main *m, void *a);
int ui_log_window_moved(t_ui_main *m, void *a);
int ui_log_el_pointer_enter(t_ui_main *m, void *a);
int ui_log_el_pointer_stay(t_ui_main *m, void *a);
int ui_log_el_pointer_exit(t_ui_main *m, void *a);
int ui_log_el_scroll_up(t_ui_main *m, void *a);
int ui_log_el_scroll_down(t_ui_main *m, void *a);
int ui_log_el_left_button_hold(t_ui_main *m,
void *a);
int ui_log_el_left_button_pressed(t_ui_main *m,
void *a);
int ui_log_el_left_button_released(t_ui_main *m,
void *a);
int ui_log_el_right_button_pressed(t_ui_main *m,
void *a);
int ui_log_el_right_button_released(t_ui_main *m,
void *a);
int ui_log_el_right_button_hold(t_ui_main *m, void *a);
int ui_log_key_pressed(t_ui_main *m, void *a);
int ui_log_key_released(t_ui_main *m, void *a);
void q_push(t_queue **q, t_list *el);
void *q_pop(t_queue **q);
void bfs_iter(const t_list *root, const t_func_ptr f,
const void *arg);
void bfs_iter_root(const t_ui_el *root,
const t_func_ptr f, const void *arg);
void bfs_for_resize(const t_ui_el *root, t_ui_main *m);
void bfs_for_draw(t_ui_main *m, const t_ui_el *root);
t_ui_el *bfs_for_raycast(t_ui_main *m, const t_ui_el *root,
t_pred_ptr p);
t_ui_el *bfs_for_find_el_by_id(const t_ui_el *root,
Uint32 id);
void ui_draw(t_ui_main *m);
void ui_draw_window(t_ui_main *m, t_ui_win *w);
void ui_draw_windows(t_ui_main *m);
void ui_clear_windows(t_ui_main *m);
void ui_show_window(t_ui_win *w);
void ui_show_windows(t_ui_main *m);
t_ui_el *ui_el_init(void);
int ui_el_add_child(t_ui_el *el, t_ui_el *child);
void ui_el_destroy(t_ui_el *e);
void ui_el_destroy_children(t_list *c);
void ui_el_set_pos(t_ui_el *el, int type, t_fvec2 v);
void ui_el_set_size(t_ui_el *el, int type, t_fvec2 v);
void ui_el_set_new_pos(t_ui_el *el, t_ui_el *canvas,
int type, t_fvec2 v);
void ui_el_set_new_size(t_ui_el *el, t_ui_el *canvas,
int type, t_fvec2 v);
void ui_el_set_new_pos_for_children(void *a1, void *a2);
void ui_el_set_new_size_for_children(void *a1, void *a2);
void ui_el_set_new_pos(t_ui_el *el, t_ui_el *canvas,
int type, t_fvec2 v);
void ui_el_change_pos(t_ui_el *el, t_ui_el *canvas,
int type, t_fvec2 v);
SDL_Texture *ui_el_create_texture(t_ui_el *el);
SDL_Texture *ui_el_create_texture_from_surface(t_ui_el *el,
SDL_Surface *sur);
SDL_Texture *ui_el_get_current_texture(t_ui_el *el);
SDL_Texture *ui_el_get_texture_by_id(t_ui_el *el,
const char *id);
int ui_el_add_texture_from_file(t_ui_el *el,
const char *path, const char *texture_id);
int ui_el_add_empty_texture(t_ui_el *el, int w, int h,
const char *texture_id);
int ui_el_add_white_texture(t_ui_el *el, int w, int h,
const char *texture_id);
int ui_el_add_gradient_texture(t_ui_el *el, t_vec2 wh,
int color, const char *texture_id);
int ui_el_add_color_texture(t_ui_el *el, t_vec2 wh,
int color, const char *texture_id);
int ui_el_add_texture_from_file_dialog(t_ui_el *el);
int ui_el_add_texture_from_file_dialog_with_size(
t_ui_el *el, int w, int h);
int ui_el_add_texture_from_main_by_id(t_ui_main *m,
t_ui_el *el, const char *id, const char *texture_id);
int ui_el_set_current_texture_by_id(t_ui_el *el,
const char *texture_id);
int ui_el_load_surface_from(t_ui_el *el,
const char *path);
int ui_el_set_text(t_ui_el *el, TTF_Font *font,
t_text_params params);
int ui_el_update_text(t_ui_el *el, const char *text);
void ui_el_setup_default_draggable(t_ui_el *el);
void ui_el_setup_default_resizable(t_ui_el *el);
void ui_el_setup_default_scroll_menu_elem(t_ui_el *el);
void ui_el_setup_default_scroll_menu(t_ui_el *el);
void ui_el_setup_default(t_ui_el *el);
void ui_el_setup_horizontal_draggable(t_ui_el *el);
void ui_el_setup_menu_resizable(t_ui_el *el);
void ui_el_setup_radio(t_ui_el *el);
int ui_el_event_switch_radio(t_ui_main *m, void *a);
int ui_el_event_default_pointer_enter(t_ui_main *m,
void *a);
int ui_el_event_default_pointer_exit(t_ui_main *m,
void *a);
int ui_el_event_scroll_menu_up(t_ui_main *m, void *a);
int ui_el_event_scroll_menu_down(t_ui_main *m, void *a);
int ui_el_event_scroll_child_menu_up(t_ui_main *m,
void *a);
int ui_el_event_scroll_child_menu_down(t_ui_main *m,
void *a);
int ui_el_event_default_draw(t_ui_main *m, void *a);
int ui_el_event_drag(t_ui_main *m, void *a);
int ui_el_event_hor_slider_drag(t_ui_main *m, void *a);
int ui_el_event_menu_resize(t_ui_main *m, void *a);
int ui_el_event_default_resize(t_ui_main *m, void *a);
int ui_el_event_children_set_default(t_ui_main *m,
void *a);
int ui_el_event_show_child(t_ui_main *m, void *a);
int ui_el_event_show_window(t_ui_main *m, void *a);
int ui_el_event_close_window(t_ui_main *m, void *a);
int ui_el_event_set_default_texture(t_ui_main *m,
void *a);
int ui_el_event_set_focused_texture(t_ui_main *m,
void *a);
int ui_el_event_set_active_texture(t_ui_main *m,
void *a);
int ui_el_event_change_text(t_ui_main *m, void *a);
void ui_el_texture_x_w(t_ui_el *e, t_rect *srect,
t_rect *tmp_rect, int w);
void ui_el_texture_y_h(t_ui_el *e, t_rect *srect,
t_rect *tmp_rect, int h);
t_ui_win *ui_win_init(void);
void ui_win_create(t_ui_win *w, int params);
void ui_win_setup_default(t_ui_win *w);
void ui_win_destroy(t_ui_win *w);
t_ui_el *ui_win_find_el_by_id(t_ui_win *w, Uint32 id);
int ui_win_event_update_size(t_ui_main *m, void *a);
int ui_win_event_focus_lost(t_ui_main *m, void *a);
int ui_win_event_focus_gained(t_ui_main *m, void *a);
int ui_sdl_init(void);
void ui_sdl_deinit(int exit_status);
int ui_jtoc_main_from_json(t_ui_main *m, const char *p);
int ui_jtoc_win_from_json(t_ui_main *m, t_jnode *n);
int ui_jtoc_get_win_param_from_string(const char *str);
t_ui_event *ui_jtoc_win_from_json_get_event_by_name(
t_ui_win *w, const char *n);
int ui_jtoc_el_from_json(t_ui_main *m, t_ui_win *w,
t_jnode *n);
t_ui_event *ui_jtoc_el_from_json_get_event_by_name(t_ui_el *e,
const char *n);
int ui_jtoc_get_el_param_from_string(const char *str);
int ui_jtoc_el_setup_by_type(t_ui_el *e, t_jnode *n);
int ui_jtoc_el_pref_text(t_ui_main *m, t_ui_el *e,
t_jnode *n);
int ui_jtoc_pref_text_modal_win(t_ui_main *m,
t_jnode *n, t_ui_text *ui_text);
int ui_jtoc_el_pref_modal_win(t_ui_main *m, t_ui_el *e,
t_jnode *n);
void ui_jtoc_create_modal_ok(t_ui_main *m, t_ui_win *w,
t_ui_text *ui_text);
void ui_jtoc_create_modal_ok_cancel(t_ui_main *m,
t_ui_win *w, t_ui_text *ui_text);
int ui_jtoc_get_pos_size(const char *str);
int ui_jtoc_sdl_log_error(const char *p, const int id);
/*
**TODO NORMAL NAME
*/
int ui_el_from_json_textures(t_ui_main *m, t_ui_el *e,
t_jnode *n);
int ui_parse_canvas(t_ui_main *m, t_ui_el *e,
t_jnode *n);
int ui_el_from_json_size(t_ui_main *m,
t_ui_el *e, t_jnode *n);
int ui_el_from_json_texture(t_ui_main *m, t_ui_el *e,
t_jnode *n);
int ui_el_from_json_event(t_ui_main *m, t_ui_el *e,
t_jnode *n);
int ui_el_from_json_events(t_ui_main *m, t_ui_el *e,
t_jnode *n);
int ui_el_from_json_white_texture(t_ui_el *e,
t_jnode *n);
int ui_el_from_json_empty_texture(t_ui_el *e,
t_jnode *n);
int ui_el_from_json_color_texture(t_ui_el *e,
t_jnode *n);
int ui_el_from_json_gradient_texture(t_ui_el *e,
t_jnode *n);
int ui_el_from_json_cursor(t_ui_main *m, t_ui_el *e,
t_jnode *n);
t_ui_event *ui_event_init(void);
t_ui_el_events *ui_event_el_events_init(void);
t_ui_win_events *ui_event_win_events_init(void);
int ui_event_add_listener(t_ui_event *e,
t_pred_ptr_event f);
int ui_event_add_listener_front(t_ui_event *e,
t_pred_ptr_event f);
void ui_event_invoke(t_ui_event *e, t_ui_main *m,
void *a);
void ui_event_clear(t_ui_event *e);
void ui_event_destroy(t_ui_event *e);
void ui_event_win_events_destroy(t_ui_win_events *we);
void ui_event_el_events_destroy(t_ui_el_events *ee);
t_rect ui_util_get_rect_from_frect(t_frect frect);
SDL_Color ui_util_get_sdl_color(int color);
Uint32 ui_util_get_pixel_color_from_texture(
SDL_Renderer *renderer, SDL_Texture *texture, t_vec2 coord);
Uint32 ui_util_get_pixel_color_from_el(
SDL_Renderer *renderer, t_ui_el *el, t_vec2 coord);
void ui_util_set_pixel_color_to_texture_replace(
SDL_Renderer *renderer, SDL_Texture *texture,
t_vec2 coord, SDL_Color color);
t_cursor *ui_cursor_init(void);
void ui_cursor_to_default(t_ui_main *m, void *a);
int ui_cursor_from_el_data(t_ui_main *m, void *a);
void ui_cursor_from(t_cursor *c);
int ui_file_parse_path(char **res);
int ui_file_find_last_slash(const char *str);
int ui_file_open_file_dialog(char **res);
int ui_file_save_file_dialog(char **res);
/*
** IT'S HUITA, BUT NOT DEL, COULD BE USEFUL FOR CREATE JSON PREFAB
*/
void ui_prefab_scroll_menu(t_ui_main *m, t_ui_el *canvas,
t_ui_el *scroll_menu, t_scroll_m_pref *scroll_data);
void ui_prefab_get_pixel_pos(t_ui_el *p, t_ui_el *canvas,
int type, t_fvec2 *pos);
void ui_prefab_get_pixel_size(t_ui_el *p,
t_ui_el *canvas, int type, t_fvec2 *size);
/*
** TODO normal names, pack on groups
*/
int ctid(t_list_texture *lst, int tid);
void ui_el_remove_texture_by_id(t_ui_el *el,
const char *id);
void ui_sdl_set_render_target(SDL_Renderer *r,
SDL_Texture *t);
void ui_sdl_set_texture_color_mode(SDL_Texture *t,
Uint8 r, Uint8 g, Uint8 b);
void ui_sdl_set_texture_alpha_mode(SDL_Texture *t,
Uint8 a);
void ui_sdl_render_copy(SDL_Renderer *r, SDL_Texture *t,
SDL_Rect *r1,
SDL_Rect *r2);
void ui_sdl_set_render_draw_color(SDL_Renderer *r,
SDL_Color *c);
void ui_sdl_set_render_draw_blend_mode(SDL_Renderer *r,
SDL_BlendMode b);
void ui_sdl_render_draw_line(SDL_Renderer *r,
t_vec2 *v1, t_vec2 *v2);
void ui_sdl_render_fill_rect(SDL_Renderer *r,
SDL_Rect *rect);
void ui_sdl_destroy_texture(SDL_Texture *t);
SDL_Texture *ui_sdl_create_texture(SDL_Renderer *r, Uint32 f,
int a, t_vec2 *s);
SDL_Texture *ui_sdl_create_texture_from_surface(SDL_Renderer *r,
SDL_Surface *s);
void ui_sdl_render_clear(SDL_Renderer *r);
void ui_sdl_set_window_position(SDL_Window *w,
int x, int y);
void ui_sdl_get_window_position(SDL_Window *w,
int *x, int *y);
void ui_sdl_raise_window(SDL_Window *w);
void ui_sdl_free_surface(SDL_Surface *s);
SDL_Surface *ui_sdl_create_rgb_surface(t_vec2 *s);
void ui_sdl_renderer_read_pixels(SDL_Renderer *r,
Uint32 f, void *p, int ph);
void ui_surface_set_pixel(t_sur *surface, int x, int y,
Uint32 pixel);
Uint32 ui_surface_get_pixel(t_sur *surface, int x, int y);
int ui_jtoc_isnum(enum e_type type);
#endif
|
dolovnyak/ray-marching-render | libui/src/ui_el/ui_el_event_show_child.c | <gh_stars>1-10
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ui_el_event_show_child.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: sbecker <<EMAIL>> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/07/13 03:28:25 by sbecker #+# #+# */
/* Updated: 2019/07/13 09:19:50 by sbecker ### ########.fr */
/* */
/* ************************************************************************** */
#include "libui.h"
static void ui_el_hide_element(t_ui_el *el)
{
t_list *node;
node = el->children;
while (node)
{
el = (t_ui_el *)node->content;
if (!(el->params & EL_IS_ICON))
el->params |= (EL_IS_HIDDEN | EL_IGNOR_RAYCAST);
node = node->next;
}
}
int ui_el_event_show_child(t_ui_main *m, void *a)
{
t_list *node;
t_ui_el *el;
(void)m;
el = (t_ui_el *)a;
node = el->parent->children;
while (node)
{
ui_el_hide_element((t_ui_el *)node->content);
node = node->next;
}
node = el->children;
while (node)
{
el = (t_ui_el *)node->content;
if (!(el->params & EL_IS_ICON))
el->params &= ~(EL_IS_HIDDEN | EL_IGNOR_RAYCAST);
node = node->next;
}
return (1);
}
|
dolovnyak/ray-marching-render | libft/src/get_strs.c | /* ************************************************************************** */
/* */
/* ::: :::::::: */
/* get_strs.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: sbecker <<EMAIL>> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/07/09 01:35:42 by sbecker #+# #+# */
/* Updated: 2019/07/10 15:28:18 by sbednar ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char **get_strs(const char *s, size_t *nss,
size_t *num_words_in_strs)
{
size_t i;
size_t j;
size_t k;
char **strs;
i = -1;
j = -1;
k = -1;
strs = (char **)ft_memalloc(sizeof(char *) * (*nss + 1));
while (s[++i])
{
strs[++j] = cut_str_by_num_words(&(s[i]), num_words_in_strs[++k]);
while (num_words_in_strs[k])
{
num_words_in_strs[k]--;
while (s[i] == ' ' && s[i])
++i;
while (s[i] != ' ' && s[i])
++i;
}
if (!s[i])
break ;
}
free(num_words_in_strs);
return (strs);
}
|
dolovnyak/ray-marching-render | include/rt.h | <filename>include/rt.h
#ifndef RT_H
# define RT_H
# define CL_SILENCE_DEPRECATION
# define INPUT_SYSTEM_INDEX 0
# ifndef OPENCL___
# include "libjtoc.h"
# include "rt_camera.h"
# include "libcl.h"
# include "rt_utilities.h"
# endif
# include "rt_numerics.h"
# include "rt_light.h"
# include "rt_object.h"
# include "rt_camera.h"
# include "rt_raycast_hit.h"
# include "transform.h"
//RT PARAMS
#define RT_GAUSS_BLUR (1 << 0)
//SCENE PARAMS
#define RT_PATH_TRACE (1 << 0)
#define RT_PHONG (1 << 1)
#define RT_REPETITION (1 << 2)
typedef struct s_scene
{
t_camera camera;
# ifndef OPENCL___
t_vec *objects;
t_vec *lights;
cl_float3 ambient;
cl_int quality;
cl_int fsaa;
cl_int path_trace_number;
cl_int path_trace_bounces;
cl_int params;
# else
__global t_object *objects;
uint objects_count;
__global t_light *lights;
uint lights_count;
float3 ambient;
int quality;
int fsaa; // TODO IN JTOC IT MUST BECOME EVEN
int path_trace_number;
int path_trace_bounces;
int params;
# endif
} t_scene;
# ifndef OPENCL___
typedef struct s_static_gpu_mem
{
cl_mem cl_image;
cl_mem cl_aux;
cl_mem cl_pt_color_buf;
cl_mem cl_texture;
cl_mem cl_texture_w;
cl_mem cl_texture_h;
cl_mem cl_prev_texture_size;
} t_s_gpu_mem;
typedef struct s_obj_texture
{
char **textures_path;
unsigned int textures_count;
int w;
int h;
int *texture;
int bpp;
int texture_w[100];
int texture_h[100];
int prev_texture_size[100];
size_t texture_size;
} t_obj_texture;
typedef struct s_rt_main
{
t_obj_texture *texture;
t_cl *cl;
t_vec *pp;
t_scene *scene;
size_t systems_count;
void **systems;
t_s_gpu_mem *gpu_mem;
int params;
cl_int2 screen_size;
} t_rt_main;
t_rt_main *rt_setup(cl_int2 screen_size,
const char *textures_path,
const char *scene_path);
int rt_render(t_ui_main *ui, void *a);
void render_processing(t_rt_main *rt, size_t *global_size, cl_int path_trace_count);
int rt_render_update(t_ui_main *ui, void *el_v);
void post_processing(t_rt_main *rt);
int *get_texture(t_rt_main *rt);
t_transform *rt_find_transform_by_id(t_scene *scene, cl_uint id);
t_object *rt_find_object_by_id(t_vec *objects, cl_uint id);
t_light *rt_find_light_by_id(t_vec *lights, cl_uint id);
int rt_find_object_by_id_in_array(t_vec *objects, cl_uint id);
void get_textures(t_rt_main *rt, char **texture_file, int number_of_texture);
void
find_textures_size(t_rt_main *rt, char **texture_file, int number_of_texture);
# endif
#endif
|
dolovnyak/ray-marching-render | src/cl/pp/pp_dithering.c | #include "rt_cl.h"
__kernel void pp_dithering(
const __global int *input_data,
__global int *output_data,
int2 screen)
{
int tx = get_global_id(0);
int ty = get_global_id(1);
int index = ty * screen.x + tx;
float16 bayer = {0, 8, 2, 10, 12, 4, 14, 6, 3, 11, 1, 9, 15, 7, 13, 5};
bayer *= 0.0625f; // 1 / 16
int col = (int)(bayer[((tx % 4) * 4 + ty % 4)] * 255);
int red = (input_data[index] >> 16) & 0xFF;
int green = (input_data[index] >> 8) & 0xFF;
int blue = input_data[index] & 0xFF;
red = col > red ? 0 : 255;
green = col > green ? 0 : 255;
blue = col > blue ? 0 : 255;
output_data[index] = ((red << 16) | (green << 8) | blue);
}
|
dolovnyak/ray-marching-render | libui/src/ui_el/ui_el_event_menu_resize.c | <filename>libui/src/ui_el/ui_el_event_menu_resize.c<gh_stars>1-10
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ui_el_event_menu_resize.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: sbecker <<EMAIL>> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/07/12 10:04:13 by sbecker #+# #+# */
/* Updated: 2019/07/13 09:13:56 by sbecker ### ########.fr */
/* */
/* ************************************************************************** */
#include "libui.h"
static void ui_el_set_new_pos_for_resize(t_ui_el *el, t_fvec2 v)
{
el->rect.x = roundf(v.x + (float)el->parent->rect.x);
el->rect.y = roundf(v.y + (float)el->parent->rect.y);
el->crect.x = el->rect.x;
el->crect.y = el->rect.y;
}
static void ui_el_set_new_size_for_resize(t_ui_el *el, t_fvec2 v)
{
el->rect.w = roundf(v.x);
el->rect.h = roundf(v.y);
el->crect.w = el->rect.w;
el->crect.h = el->rect.h;
}
static void get_new_pos_size_indent(t_ui_el *el, t_resize_data *data)
{
t_fvec2 new_pos1;
t_fvec2 new_pos2;
t_fvec2 new_size;
t_ui_el *child;
child = (t_ui_el *)el->children->content;
new_size.x = (float)el->rect.w * child->rrect.w;
new_size.y = (float)el->rect.h * child->rrect.h;
new_pos1.x = (float)el->rect.x + (float)el->rect.w * child->rrect.x;
new_pos1.y = (float)el->rect.y + (float)el->rect.h * child->rrect.y;
if ((t_ui_el *)el->children->next)
{
child = (t_ui_el *)el->children->next->content;
new_pos2.x = (float)el->rect.x + (float)el->rect.w * child->rrect.x;
new_pos2.y = (float)el->rect.y + (float)el->rect.h * child->rrect.y;
data->indent.x = roundf(new_pos2.x - new_pos1.x - new_size.x);
data->indent.y = roundf(new_pos2.y - new_pos1.y - new_size.y);
}
data->elem_pos = ft_fvec2_round(new_pos1);
data->elem_size = ft_fvec2_round(new_size);
data->elem_pos.x = data->elem_pos.x - (float)el->rect.x;
data->elem_pos.y = data->elem_pos.y - (float)el->rect.y;
}
int ui_el_event_menu_resize(t_ui_main *m, void *a)
{
t_resize_data data;
t_list *list;
t_ui_el *el;
t_ui_el *cur_el;
ui_el_event_default_resize(m, a);
el = (t_ui_el *)a;
if (el && el->children)
{
get_new_pos_size_indent(el, &data);
list = el->children;
while (list)
{
cur_el = (t_ui_el *)list->content;
ui_el_set_new_pos_for_resize(cur_el, data.elem_pos);
ui_el_set_new_size_for_resize(cur_el, data.elem_size);
bfs_iter(cur_el->children, ui_el_set_new_pos_for_children, 0);
bfs_iter(cur_el->children, ui_el_set_new_size_for_children, 0);
data.elem_pos.y += data.elem_size.y + data.indent.y;
list = list->next;
}
}
return (1);
}
|
dolovnyak/ray-marching-render | libui/src/ui_main/ui_main_handle_raycast.c | <reponame>dolovnyak/ray-marching-render<gh_stars>1-10
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ui_main_handle_raycast.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: sbecker <<EMAIL>> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/04/15 00:43:05 by sbednar #+# #+# */
/* Updated: 2019/07/15 15:23:57 by sbecker ### ########.fr */
/* */
/* ************************************************************************** */
#include "libui.h"
static void invoke_status_pointer_events(t_ui_main *m,
t_ui_el *prev, t_ui_el *cur)
{
if (prev != NULL && cur != NULL && prev->id != cur->id)
{
ui_event_invoke(prev->events->on_pointer_left_button_released, m, prev);
ui_event_invoke(prev->events->on_pointer_right_button_released,
m, prev);
ui_event_invoke(prev->events->on_pointer_exit, m, prev);
ui_event_invoke(cur->events->on_pointer_enter, m, cur);
m->raycaster->selected = cur;
}
else if (prev == NULL && cur != NULL)
{
ui_event_invoke(cur->events->on_pointer_enter, m, cur);
m->raycaster->selected = cur;
}
else if (cur == NULL && prev != NULL)
{
ui_event_invoke(prev->events->on_pointer_left_button_released, m, prev);
ui_event_invoke(prev->events->on_pointer_right_button_released,
m, prev);
ui_event_invoke(prev->events->on_pointer_exit, m, prev);
m->raycaster->selected = NULL;
}
}
static void invoke_button_events(t_ui_main *m, t_ui_el *cur)
{
if (m->params & MAIN_LMB_PRESSED)
{
m->focused_el = cur;
ui_event_invoke(cur->events->on_pointer_left_button_pressed, m, cur);
m->params &= ~MAIN_LMB_PRESSED;
}
else if (m->params & MAIN_LMB_RELEASED)
{
ui_event_invoke(cur->events->on_pointer_left_button_released, m, cur);
m->params &= ~MAIN_LMB_RELEASED;
}
else if (m->params & MAIN_RMB_PRESSED)
{
ui_event_invoke(cur->events->on_pointer_right_button_pressed, m, cur);
m->params &= ~MAIN_RMB_PRESSED;
}
else if (m->params & MAIN_RMB_RELEASED)
{
ui_event_invoke(cur->events->on_pointer_right_button_released, m, cur);
m->params &= ~MAIN_RMB_RELEASED;
}
}
void ui_main_handle_raycast(t_ui_main *m)
{
t_ui_el *prev;
t_ui_el *cur;
prev = m->raycaster->selected;
cur = ui_raycast(m, m->raycaster->focused_win);
if (prev == NULL && cur == NULL)
return ;
invoke_status_pointer_events(m, prev, cur);
cur = m->raycaster->selected;
if (cur)
{
if (cur->params & EL_IS_SCROLLABLE && m->params &
(MAIN_SCROLL_DOWN | MAIN_SCROLL_UP))
{
if (m->params & MAIN_SCROLL_DOWN)
ui_event_invoke(cur->events->on_scroll_down, m, cur);
if (m->params & MAIN_SCROLL_UP)
ui_event_invoke(cur->events->on_scroll_up, m, cur);
m->params &= ~(MAIN_SCROLL_DOWN | MAIN_SCROLL_UP);
}
else
invoke_button_events(m, cur);
}
if (cur)
ui_main_handle_continious_event(m, cur);
}
|
dolovnyak/ray-marching-render | src/rt_jtoc/rt_jtoc_scene_setup.c | <filename>src/rt_jtoc/rt_jtoc_scene_setup.c
#include "rt.h"
#include "rt_jtoc.h"
int rt_jtoc_get_oper_id(t_jnode *n, t_object *obj, t_vec **objects, int id)
{
t_jnode *tmp_obj_id;
t_jnode *tmp_oper_name;
t_object *objct;
char *str;
int object_id;
if (obj->sub_mult_flag == 3)
return (FUNCTION_SUCCESS);
if ((tmp_obj_id = jtoc_node_get_by_path(n ,"operation")) && tmp_obj_id->type == object)
{
tmp_oper_name = tmp_obj_id;
if (!(tmp_obj_id = jtoc_node_get_by_path(tmp_obj_id, "object_id")) ||
tmp_obj_id->type != integer)
return (rt_jtoc_sdl_log_error("OBJECT ID ERROR OR MISSING", -1));
object_id = jtoc_get_int(tmp_obj_id);
id = rt_find_object_by_id_in_array(*objects, object_id);
if (!(rt_find_object_by_id(*objects, object_id)))
return (rt_jtoc_sdl_log_error("THERE IS NO SUCH OBJECT!", -1));
obj->obj_with_oper_id = id;
objct = (t_object *)vec_at(*objects, id);
objct->sub_mult_flag = 3;
if (!(tmp_oper_name = jtoc_node_get_by_path(tmp_oper_name, "operation_name")) ||
tmp_oper_name->type != string)
return (rt_jtoc_sdl_log_error("THERE IS NO SUCH OPERATION NAME!",-1));
if (!(str = (char *)ft_x_memalloc(sizeof(char) * 16)))
return (FUNCTION_FAILURE);
ft_strncpy(str, jtoc_get_string(tmp_oper_name), 15);
if (!(ft_strcmp(str, "none")))
{
free(str);
return (FUNCTION_SUCCESS);
}
else if (!(ft_strcmp(str, "sub")))
obj->sub_mult_flag = 1;
else if (!(ft_strcmp(str, "plus")))
obj->sub_mult_flag = 2;
else
{
free(str);
return (rt_jtoc_sdl_log_error("OPERATION NAME ERROR", -1));
}
}
return (FUNCTION_SUCCESS);
}
int rt_jtoc_get_objects_operation(t_scene *scene, t_jnode *n)
{
t_jnode *tmp;
int i;
tmp = n->down;
i = 0;
while (tmp)
{
t_object *obj;
if (rt_jtoc_get_oper_id(tmp, (t_object *)vec_at(scene->objects, i), &scene->objects, i))
return (rt_jtoc_sdl_log_error("OPER ID ERROR", i));
obj = (t_object *)vec_at(scene->objects, i);
// SDL_Log("%d", (uint)obj->sub_mult_flag);
// SDL_Log("%s", obj->local_name);
SDL_Log("object %d: %d", i , obj->transform.id);
// SDL_Log("%f\n", obj[obj->obj_with_oper_id].params.sphere.radius);
// SDL_Log("operation: %d", obj->sub_mult_flag);
// SDL_Log("object with operat: %d", obj->obj_with_oper_id);
i++;
tmp = tmp->right;
}
return (FUNCTION_SUCCESS);
}
static int rt_jtoc_get_scene_params(t_scene *scene, t_jnode *n)
{
t_jnode *tmp;
char *str;
int params;
params = 0;
tmp = n->down;
while (tmp)
{
if (tmp->type != string)
return (rt_jtoc_sdl_log_error("PARAMS TYPE ERROR", -1));
str = jtoc_get_string(tmp);
params |= ft_strcmp(str, "repetition") ? 0 : RT_REPETITION;
params |= ft_strcmp(str, "path_trace") ? 0 : RT_PATH_TRACE;
params |= ft_strcmp(str, "phong") ? 0 : RT_PHONG;
if ((params & RT_PATH_TRACE) && (params & RT_PHONG))
return (rt_jtoc_sdl_log_error("BOTH PATH_TRACE AND PHONG - ERROR", -1));
tmp = tmp->right;
}
scene->params |= params;
return (FUNCTION_SUCCESS);
}
static int rt_jtoc_get_scene(const char *path, t_scene *scene, t_obj_texture *texture)
{
t_jnode *root;
t_jnode *tmp;
if (!(root = jtoc_read(path)))
return (rt_jtoc_sdl_log_error("JSON", -1));
if ((tmp = jtoc_node_get_by_path(root, "params")) && tmp->type == array)
{
if (rt_jtoc_get_scene_params(scene, tmp))
return (rt_jtoc_sdl_log_error("SCENE PARAMS ERROR", -1));
}
if (!(tmp = jtoc_node_get_by_path(root, "quality")) || tmp->type != integer)
return (rt_jtoc_sdl_log_error("QUALITY ERROR", -1));
scene->quality = jtoc_get_int(tmp);
if (scene->quality > 100)
return (rt_jtoc_sdl_log_error("MAX QUALITY IS 100", -1));
if (!(tmp = jtoc_node_get_by_path(root, "smoothing")) || tmp->type != integer)
return (rt_jtoc_sdl_log_error("SMOOTHING ERROR", -1));
scene->fsaa = jtoc_get_int(tmp);
scene->fsaa = scene->fsaa % 2 ? scene->fsaa + 1 : scene->fsaa;
if (scene->fsaa > 10)
return (rt_jtoc_sdl_log_error("MAX SMOOTHING IS 10", -1));
if (!(tmp = jtoc_node_get_by_path(root, "path_trace_number")) || tmp->type != integer)
return (rt_jtoc_sdl_log_error("PATH_TRACE_NUMBER ERROR", -1));
scene->path_trace_number = jtoc_get_int(tmp);
if (!(tmp = jtoc_node_get_by_path(root, "path_trace_bounces")) || tmp->type != integer)
return (rt_jtoc_sdl_log_error("PATH_TRACE_BOUNCES ERROR", -1));
scene->path_trace_bounces = jtoc_get_int(tmp);
if (!(tmp = jtoc_node_get_by_path(root, "camera")) || tmp->type != object)
return (rt_jtoc_sdl_log_error("CAMERA TYPE ERROR OR CAMERA IS NOT SET", -1));
if (rt_jtoc_get_camera(&(scene->camera), tmp))
return (rt_jtoc_sdl_log_error("CAMERA DATA ERROR", -1));
if (!(tmp = jtoc_node_get_by_path(root, "lights")) || tmp->type != object)
return (rt_jtoc_sdl_log_error("LIGHTS TYPE ERROR OR LIGHTS AREN'T SET", -1));
if (rt_jtoc_get_lights(scene, tmp))
return (rt_jtoc_sdl_log_error("LIGHTS ERROR", -1));
if (!(tmp = jtoc_node_get_by_path(root, "objects")) || tmp->type != array)
return (rt_jtoc_sdl_log_error("OBJECTS TYPE ERROR OR OBJECTS AREN'T SET", -1));
if (rt_jtoc_get_objects(scene, tmp, texture))
return (rt_jtoc_sdl_log_error("OBJECTS ERROR", -1));
if (rt_jtoc_get_objects_operation(scene, tmp))
return (rt_jtoc_sdl_log_error("OBJECT OPERATION ERROR", -1));
if (!(tmp = jtoc_node_get_by_path(root, "quality")) || tmp->type != integer)
return (rt_jtoc_sdl_log_error("QUALITY ERROR", -1));
scene->quality = jtoc_get_int(tmp);
if (scene->quality > 100)
return (rt_jtoc_sdl_log_error("MAX QUALITY IS 100", -1));
jtoc_node_clear(root);
return (FUNCTION_SUCCESS);
}
int rt_jtoc_scene_setup(t_rt_main *rt, const char *json)
{
int i;
t_scene *scene;
scene = (t_scene *)ft_x_memalloc(sizeof(t_scene));
i = -1;
if (rt_jtoc_get_scene(json, scene, rt->texture))
{
rt_jtoc_sdl_log_error("SCENE ERROR", i);
exit(-1);
}
rt->scene = scene;
return (FUNCTION_SUCCESS);
} |
dolovnyak/ray-marching-render | include/transform.h | <reponame>dolovnyak/ray-marching-render
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* transform.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: sbecker <<EMAIL>> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/04/10 05:13:21 by sbecker #+# #+# */
/* Updated: 2019/07/03 20:16:18 by sbecker ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef TRANSFORM_H
# define TRANSFORM_H
typedef struct s_transform
{
# ifndef OPENCL___
cl_uint id;
cl_float3 pos;
cl_float3 right;
cl_float3 up;
cl_float3 forward;
# else
uint id;
float3 pos;
float3 right;
float3 up;
float3 forward;
# endif
} t_transform;
#endif
|
dolovnyak/ray-marching-render | libui/src/ui_jtoc/ui_jtoc_win_from_json.c | <reponame>dolovnyak/ray-marching-render<filename>libui/src/ui_jtoc/ui_jtoc_win_from_json.c
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ui_jtoc_win_from_json.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: sbecker <<EMAIL>> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/07/12 06:54:11 by sbecker #+# #+# */
/* Updated: 2019/07/15 15:08:51 by sbecker ### ########.fr */
/* */
/* ************************************************************************** */
#include "libui.h"
static int ui_win_from_json_events(t_ui_main *m, t_ui_win *w, t_jnode *n)
{
char *event_name;
char *func_name;
t_ui_event *e;
t_pred_ptr_event f;
t_jnode *t;
n = n->down;
while (n)
{
if (n->type != object ||
!(t = jtoc_node_get_by_path(n, "event_name")) ||
t->type != string ||
!(event_name = jtoc_get_string(t)) ||
!(e = ui_jtoc_win_from_json_get_event_by_name(w, event_name)) ||
!(t = jtoc_node_get_by_path(n, "func_name")) ||
t->type != string ||
!(func_name = jtoc_get_string(t)) ||
!(f = ui_main_get_function_by_id(m, func_name)))
return (ui_jtoc_sdl_log_error("NODE WINDOW (EVENTS)", -1));
ui_event_add_listener(e, f);
n = n->right;
}
return (FUNCTION_SUCCESS);
}
static int ui_win_from_json_size(t_ui_main *m, t_ui_win *w, t_jnode *n)
{
t_jnode *t;
if (!(t = jtoc_node_get_by_path(n, "size.x")) || !ui_jtoc_isnum(t->type))
return (ui_jtoc_sdl_log_error("NODE WINDOW (SIZE.X)", -1));
w->size.x = jtoc_get_int(t);
if (!(t = jtoc_node_get_by_path(n, "size.y")) || !ui_jtoc_isnum(t->type))
return (ui_jtoc_sdl_log_error("NODE WINDOW (SIZE.Y)", -1));
w->size.y = jtoc_get_int(t);
ui_win_setup_default(w);
ui_win_create(w, SDL_WINDOW_SHOWN);
if (!(t = jtoc_node_get_by_path(n, "elements")))
return (ui_jtoc_sdl_log_error("NODE WINDOW (NO ELEMENTS)", -1));
t = t->down;
while (t)
{
if (ui_jtoc_el_from_json(m, w, t))
ui_sdl_deinit(228);
t = t->right;
}
if ((t = jtoc_node_get_by_path(n, "events")))
if (t->type != array || ui_win_from_json_events(m, w, t))
ui_sdl_deinit(228);
free(w->events->on_key_down[SDL_SCANCODE_ESCAPE]);
w->events->on_key_down[SDL_SCANCODE_ESCAPE] = w->events->on_close;
return (FUNCTION_SUCCESS);
}
static int ui_win_from_json_pos(t_ui_main *m, t_ui_win *w, t_jnode *n)
{
t_jnode *t;
if (!(t = jtoc_node_get_by_path(n, "pos.x")) || !ui_jtoc_isnum(t->type))
return (ui_jtoc_sdl_log_error("NODE WINDOW (POS.X)", -1));
w->pos.x = jtoc_get_int(t);
if (!(t = jtoc_node_get_by_path(n, "pos.y")))
w->pos.y = SDL_WINDOWPOS_CENTERED;
else
{
if (!ui_jtoc_isnum(t->type))
return (ui_jtoc_sdl_log_error("NODE WINDOW (POS.Y/TYPE)", -1));
w->pos.y = jtoc_get_int(t);
}
return (ui_win_from_json_size(m, w, n));
}
int ui_jtoc_win_from_json(t_ui_main *m, t_jnode *n)
{
t_ui_win *w;
t_jnode *t;
if (!(w = ui_win_init()))
return (ui_jtoc_sdl_log_error("NODE WINDOW (INIT/ID)", -1));
if (!(t = jtoc_node_get_by_path(n, "id")) || !ui_jtoc_isnum(t->type))
return (ui_jtoc_sdl_log_error("NODE WINDOW (INIT/ID)", -1));
w->id = jtoc_get_int(t);
if (!(t = jtoc_node_get_by_path(n, "title")) || t->type != string ||
!(w->title = ft_strdup(jtoc_get_string(t))))
return (ui_jtoc_sdl_log_error("NODE WINDOW (TITLE/TYPE)", -1));
if ((t = jtoc_node_get_by_path(n, "params")) &&
(t = t->down))
while (t)
{
if (t->type != string)
return (ui_jtoc_sdl_log_error("NODE WINDOW (PARAMS)", -1));
w->params |=
ui_jtoc_get_win_param_from_string(jtoc_get_string(t));
t = t->right;
}
if (ui_win_from_json_pos(m, w, n))
ui_sdl_deinit(228);
ui_main_add_window(m, w);
return (FUNCTION_SUCCESS);
}
|