Giter Site home page Giter Site logo

scratchapixel-code's Introduction

scratchapixel-code's People

Contributors

aviralgoel avatar jeancolasp avatar kristopolous avatar scratchapixel avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

scratchapixel-code's Issues

My ppm file is corrupted.

image
Why my image looks like that? By the way, this is not the first time I encountered situation like that.
I printed out the result (before saving) which is correct.
image
The above file (I only print first 10 rgb values) indicates that from line 311 to line 341 is constantly with color 59, -84, -42 however in the first screenshot we can see something else in this range.

I also did another expriments: read the ppm file and print them on the console.
image

I think the codes crashed halfway. Down below, 971547 is the counter of CHARs. I did the math (also we can see from the pic) 971547 is at H:316, W795. If finish well, the counter should be 1024 x 747 x 3 = 2294784.

I will also upload the codes.

// stdafx.cpp : source file that includes just the standard includes
// CPPTEST2.pch will be the pre-compiled header
// stdafx.obj will contain the pre-compiled type information

#include "stdafx.h"
#include <fstream>  
#include <iostream>
#include <string>  

// TODO: reference any additional headers you need in STDAFX.H
// and not in this file

int main123()
{
	std::ifstream infile("out_phong.ppm");

	if (!infile.is_open()) {
		std::cerr << "ERR\n";
		return 1; 
	}
 
	std::string line;
	while (std::getline(infile, line)) {
		int char_num = 0;
		for (char c : line) { 
			//if (char_num % (1024 * 3) == 0)
			//{
			//	std::cout << std::endl << (char_num/3072) << std::endl;
			//}
			if (char_num > 970752)
			{
				std::cout << (int)c << ' ';
			}
			else
			{

				if (char_num % 3072 == 0)
				{
					std::cout << char_num / 3072 << std::endl;
				}
				if (char_num % (3072) < 30)
				{
					std::cout << (int)c << ' ';
					//std::cout << std::endl;
				}
				if (char_num % (3072) == 31)
				{
					std::cout << std::endl;
				}
			}
			//std::cout << c; 
			char_num++;
		}
		std::cout << std::endl << (char_num) << std::endl;
		std::cout << std::endl; 
	}

	infile.close();
	printf("sdadasds\n");
	return 0;
}

interpolation.cpp crashes

There seems to be a number of interesting issues here:

https://github.com/scratchapixel/scratchapixel-code/blob/main/interpolation/interpolation.cpp#L183 which as of this writing is:

#define IX(size, i, j, k) ( i * j * k * size + i * j * size + i )

You're going to overflow your structure with this. Since i,j,k max is size, then the loop will stop at size^4 + size^2 + size in indexing size^3. You probably want something like this instead:

#define IX1(size, i, j, k) ( k * size * size + j * size + i )

Beyond that, there appears to be a double free error in the trilinear interpolation. This can be fixed as follows:

for (int k = 0; k < numVertices; ++k) {
   for (int j = 0; j < numVertices; ++j) {
      for (int i = 0; i < numVertices; ++i) {

Finally, the e, f, g triplet that's computed doesn't go anywhere (here: https://github.com/scratchapixel/scratchapixel-code/blob/main/interpolation/interpolation.cpp#L229), maybe you intended to write it to a file? I understand there's no simple 3D ppm format (which is kind of a crazy oversight) so perhaps just doing the slices. Is the right way. I have that in a PR I'm going to be opening shortly after this comment

Also the code https://www.scratchapixel.com/lessons/mathematics-physics-for-computer-graphics/interpolation/bilinear-filtering.html has a syntactic error:

#if 1
    float  a = c00 * (1 - tx) + c10 * tx;
    float  b = c01 * (1 - tx) + c11 * tx;
    return a * (1) - ty) + b * ty;
#else

That block won't compile. There's a parenthesis missing.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.