C/C++ :: How To Put Together A Basic Ray Tracer Which Can Model Spheres And Planes

Dec 9, 2014

how to put together a basic ray tracer which can model spheres and planes. I have an example ray tracer which I am currently pulling apart and sifting through line by line to try and understand exactly how it works. I have come to a point in the code which I am having trouble explaining adequately. It's a method of the Plane class, which is a class defining the planes in the scene. The method is called findIntersection and I believe its purpose is to return the distance between the origin of the ray and the point of intersection, it looks like this

double findIntersection(Ray ray){
Vector ray_direction=ray.getDirection();
double a = ray_direction.DotProduct(normal);
if(a==0){
return -1;
}
else{
double b=normal.DotProduct(ray.getStart()+((normal*distance).Inverse()));
return -1*b/a;
}
}

The method accepts arguments of type Ray which is a class defining rays, rays are constructed from this class by supplying two vectors, a starting vector and a direction vector, the Ray class has a method function getDirection which is used in the first line of the findIntersection function which clearly just returns the direction vector. The DotProduct method being accessed belongs to the Vector class and is a standard method for finding the dot product of two vectors. "normal" is a variable of type Vector and is used in the construction of an instance of the Plane class, along with a distance from the centre of the scene and a colour. Also, in the line double b=normal.DotProduct(ray.getStart()+((normal*distance).Inverse())); the plus sign between the two vectors is an overloaded operator which adds the two vectors in the usual mathematical way, I overloaded it for neatness.

The trouble I'm having is working out what the variables a and b are doing, what they mean geometrically and how they correspond to getting the distance between ray origin and point of intersection. Clearly if the dot product of the normal with the ray equals zero then the ray is parallel to the plane and so there is no intersection but what is a's role in the return statement.

View 3 Replies


ADVERTISEMENT

C++ :: Model A Triangle With Three Vertices

Dec 27, 2013

Write a class called MyTriangle, which models a triangle with 3 vertices, is designed as follows. It contains:

1. The MyTriangle class uses three MyPoint instances as the three vertices.

2. Three private instance variables v1, v2, v3 (instances of MyPoint), for the three vertices.

3. A constructor that constructs a MyTriangle with three points v1=(x1, y1), v2=(x2, y2), v3=(x3, y3).

4. An overloaded constructor that constructs MyTriangle given three instances of MyPoint.

5. A toString() function that returns a string description of the instance in the format "Triangle @ (x1, y1), (x2, y2), (x3, y3)".

6. A getPerimeter() function that returns the length of the perimeter in double. You should use the distance() method of MyPoint to compute the perimeter.

7. Also write a test program (called main.cpp) to test all the functions defined in the class (example of a triangle: (-2, 1), (1, 3) and (3, -3)).

class MyTriangle {
MyPoint v1;
MyPoint v2;
MyPoint v3;

public:
MyTriangle(int x1,int y1,int x2,int y2,int x3,int y3) {

[Code] .....

View 3 Replies View Related

C++ :: If Else Statement To Check Multiple Model Numbers

May 2, 2013

I need to create a if else statement to check multiple model numbers (200+)... How can i build this? I basically want the user to enter their model number and if its on the list they get a approved or denied message.

So far I have this, the "if(model == 9002||1002)" doesnt seem right, it needs to basically check 200+ model numbers... am I even on the right track?

Code:
#include <iostream>
using namespace std;
int main(){
int model;
cout << "Enter model" << endl;

[Code] .....

View 3 Replies View Related

C :: Dynamic Load 3D Model From A File Located In Web Server

Feb 2, 2013

I have done a test, I have edited with the WordPad in Windows on my Local Webserver a file banana.h which contains a list of float arrays in order to extract one array and create a text file named ObjVerts.txt I have done a lot of search in the Web in order to find a small piece of code that can read the text file and convert it to a float array GLfloat, but I did not find any. I have found a lot of piece of code that read the file and make a NSData but many of the code seem to not work. It seem that the last statement return nothing!

NSURL *myurl = [NSURL URLWithString:@"http://localhost/ObjVerts.txt"];
//NSString *mystring = [NSString stringWithContentsOfURL:myurl];
NSData *mydata = [NSData dataWithContentsOfURL:myurl];

View 1 Replies View Related

C/C++ :: Analyze Population Dynamics - Forest Fire Model

May 15, 2014

I'm trying to analyze Population Dynamics. I found some articles and read them but what kind of model i need to use. I tried Forest Fire model but i failed in modificating.

#include <stdio.h>
#include <stdlib.h>
#define MaxPopulation 10000
#define MaxChildren 10
#define maxAge 70
#define ranf() ((double) random()/(double)RAND_MAX)

View 7 Replies View Related

C++ :: Program To Model Operation Of Incoming Flights Computer Screen

Apr 14, 2013

The project is "Design and write a program to model the operation of incoming flights computer screen that is normally found at a typical small airport like Moshoeshoe I airport (if they do have one). The following provides the information that needs to be displayed about each flight:

• Airline - [string of maximum length 15] Name of the airline, eg. FlySAA
• Flight Number - [string of maximum length 5] eg. 04120
• Origin - [string of maximum length 25] Place where the flight originated from eg. Johannesburg
• Date/Time - [integers: Hour, Minute, Day, Month, Year] Arrival time of the flight
• Status - [string of maximum length 15] Whether the flight is "OnTime" or "Delayed"

View 4 Replies View Related

C/C++ :: Run Basic Stats On 150 Tables

Mar 7, 2014

I need to run some basic statistics on about ~150 tables that are currently in dBase format. Rather than use excel to do them all individually, i was told to use s+ and write a code to loop through them, but I have never written any code and my experience with spotfire s+ is limited (the stat software i have available) ....

View 4 Replies View Related

C++ :: Basic Encryption And Decryption Program

Sep 29, 2013

I am having trouble with an assignment. The assignment consists of a basic encryption and decryption program already written for me, I just have to write the encryption function. What we have to get the program to do is enter an integer and a text, and get the program to increment each letter in the text by the integer given. I did this by using a for loop and incrementing each value in the string by the integer.

However, I still can't get it to decrypt and I need the program to work with only a-z letters (if I increment each letter by 3 and I have the letter Z, it should go to Z+3 = C).

I attached the description of the attachment and below are the codes: The first file does not need to be edited.

Code:
/*******************Programming Assignment 1***************/
/****************Caesar's substitution cipher**************/
/*****************YOU MUST NOT EDIT THIS FILE**************/
/****Substitute alphabets in a string using rotation key***/
/****Leave all other characters unchanged******************/
/****Confirm correct encryption by decrypting**************/

[Code] ......

View 1 Replies View Related

C++ :: Variadic Template Basic Syntax

Jul 31, 2014

I had to learn how to use variadic templates recently, and had trouble finding simple examples that just showed the basic syntax.

So I decided to write one myself. Admittedly, it's a bit on the long side, but that is mostly because it includes five specializations.

insert Code:
// Variadic.C
// Compile command: g++ Variadic.C -std=c++0x
// I used GCC version 4.6.3 on Ubuntu.

// This file contains a basic variadic template with five specializations.
// It is intended for non-software engineers who are looking for a simple
// example of variadic template syntax.

[Code] ....

View 3 Replies View Related

C :: Basic Array Pointers Program

Feb 4, 2014

Code:

#include <stdio.h>
void Swap(int *x, int *y);
int *Largest(int *array, int size);
int main()
{
int a, b, i;
int c[10];
int maxaddress;
}

[code]...

My swap function works fine, but I am trying to find the ADDRESS of the largest element in my array and I am getting an error using gcc on my "return &largest;" and my printf line in my main function.How can I fix this and return the address of the largest?

View 8 Replies View Related

C++ :: Basic Encryption / Decryption - While Loop

Jul 14, 2013

while(!in.eof()) {
in >> ch;
char d = int(ch) + 10;
out << d;

[Code] ....

The first while loop would be to encrypt it, and the second would decrypt it, the decrypting is not giving the original content. For example:

in = Hello
encrypt...
decrypt...
out = Hellooo

View 2 Replies View Related

C++ :: Calculating Net Pay - Adding Basic Procedures?

Nov 18, 2014

So I am currently in the middle of learning c++ and I decided to jump ahead of the book and tried to do add procedures. My goal is to have main calling other procedures such as welcome message().

#include <iostream>
#include <iomanip>
#include <string>

using namespace std;

#define MIN_HOURS 0.00 // minimum hours per week
#define MAX_HOURS 60.00 // maximum hours per week
#define MIN_RATE 0.00 // minimum pay rate
#define MAX_RATE 99.99 // maximum pay rate

[Code] .....

View 5 Replies View Related

C++ :: Configure Netbeans Basic Settings

Nov 22, 2013

I want to configure netbeans 7.4 settings for c++.I'm posting here because netbeans forums are close to dead. How to do the following things :-

1) When you create a new project of a 'new application' type, main.cpp is already there with some code. I want that main.cpp to be completely empty when I create a new project.

2) When you compile/build your program and run it, the output is shown in a small log window at the bottom. I want it to be shown like in a black output terminal (console ?) just like in Visual Studio or CodeBlocks. (I have some reasons for not using them instead, so don't bother about me not using them)

3) When you click the green 'Run' icon in the upper toolbar, the project is compiled/build again and then runs afterwards. I want it to just run without compiling. (Compiling/Building should be done by 'Build' icon, just like in CodeBlocks or Visual Studio)

View 3 Replies View Related

C++ :: Make Basic GUI From Scratch Without Using Any Programs?

May 26, 2013

I have learned the basics you need to know about c++ so I was wondering, how do you make a GUI from scratch without using any programs like qt, daniweb, ect. Is there like a ongui() or something?

View 6 Replies View Related

C/C++ :: Basic 2D Array Displaying Output?

Feb 23, 2014

I been for trying to create 5x5 2d array that

basically display first column, last column , and diagonally (like " N " display). but i cant get it to work.
this is what i have so far.

int _tmain(int argc, _TCHAR* argv[]) {
char Test[5][5];
for (int i = 0; i < 5; i++)

[Code]....

View 4 Replies View Related

C/C++ :: How To Do Basic Animation With GTK3 And Cairo Only

Apr 22, 2014

Let assume i have a gtk window with a drawing area and a button in it....

When the application is run it will show ball... when the button is pressed it will start bouncing from one side to other... When the button is pressed again it stop bouncing...

Also the window shows the current XY co-ordinates of the ball in the bottom left corner(inside the drawing area)...

I want to use C , GTK3 and CAIRO only...

I have googled and found animation example not with GTk3 but GTK's previous versions instead...those doesnt work with GTK3..i have also read cairo's official,zetecode's tutorails and some other sites..but nowhere found any solution to my problem...

I know how to do so with OpenGL and it's very easy...but i cannot apply the same logic with cairo and gtk3...please dont suggest to use GtkGlExt...i don't want to use it...

View 1 Replies View Related

Visual C++ :: How To Create A Basic Window

Dec 29, 2012

I want to create a basic window using visual c++ 2010 express.

View 1 Replies View Related

C# :: Created A Simple Basic Program That Uses Sockets

Feb 22, 2012

I have created a simple basic program that uses sockets but it can only handle one connection, how do I make it so it handles multiple connections?

Server code:

Code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net.Sockets;
}

[code]...

View 5 Replies View Related

C++ :: Basic Array Based Binary Tree

Oct 20, 2013

I've been working on this assignment and but I know that I'm not handling my array properly.

#include<conio.h>
#include<iostream>
#include<stdio.h>
using namespace std;
class binaryTree {

[Code] .....

View 1 Replies View Related

C++ :: Unresolved External Symbol - Basic Keylogger Using SDL

Feb 25, 2014

My code is rather short, but when I compile it, I get 1 error about an unresolved external symbol, it probably has something to do with the file processing. . .

Just a basic keylogger using SDL

Keylogger.h
#ifndef KEYLOGGER_H
#define KEYLOGGER_H
#include <fstream>
#include <SDL.h>
using namespace std;
class Keylogger{

[Code] .....

Errors

Error1error LNK2019: unresolved external symbol __imp___CrtDbgReportW referenced in function "public: char const & __thiscall std::_String_const_iterator<class std::_String_val<struct std::_Simple_types<char> > >::operator*(void)const " (??D?$_String_const_iterator@V?$_String_val@U?$_Simple_types@D@std@@@std@@@std@@QBEABDXZ)C:Usersaviedocumentsvisual studio 2013ProjectsPracticePracticeKeylogger.objPractice

View 3 Replies View Related

C++ :: Basic Parts Of Text Based RPGs?

Oct 22, 2013

How you'd type yes or no scenarios for a text based RPG? And I mean a really basic like 'you see ..... what do you do?'. Also, how would you finish a code like this.

View 9 Replies View Related

C/C++ :: Basic Console Calculator - Void Function Getting Ignored?

Jun 16, 2014

I made a basic console calculator in C++ using the Code::Blocks IDE and using the GNU GCC compiler. The problem in my code is my void function called 'operate' is getting ignored by not showing up in the console. After the first if statement I added a user input by saying Y for yes or N for no. Another if statement inside the first one shows if you type either 'Y' or 'y' it will execute the 'operate' function which will restart the calculator by having the same selection menu as in the int main function. When I call the function it does not show up in the console but just ends the program.

Here is my code:

#include <iostream>
#include <cstdlib>
#include <string>
using namespace std;
int input,input2, numAdd, numAdd2, numSub, numSub2, numMult, numMult2, numDiv, numDiv2;
void operate() {
cout << "Select a operator." << endl;

[code].....

View 2 Replies View Related

C/C++ :: Too Many Types In Declaration In A Basic Structure Program

May 18, 2014

This is my program

#include<iostream.h>
#include<conio.h>
#include<string.h>
#include<stdio.h>
#include<math.h>    
struct date
{int dd,mm,yy;}  

[Code] ....

Error in Line 11:Too many types in declaration

View 2 Replies View Related

C/C++ :: Can't Get Basic Input / Output Program To Work

Feb 29, 2012

im trying to write a program that prompts the user to enter three numbers and then prints them vertically (each on one line), first forward and then reversed. this is how the design should look:

enter three numbers: 1 43 54

your numbers fowards:

1
43
54

your numbers backwards:

54
43
1

this is what i have thus far when it comes to code....
   
#include <stdio>  
int main (void) {
// local declarations 
int a;
int b;
int c

[code].....

View 1 Replies View Related

C :: Create A Basic Soccer Points Projection Program

Nov 12, 2014

I'm basically trying to create a program that will project a soccer teams points for the whole season. Here are the basics:

Total games: 38
Win: 3 pts
Draw: 1 pt
Loss: 0 pts

My program compiles fine, but inevitably crashes right before the if statement..

Code:

#include<stdio.h>
int main(void)
{
float ppg, games_played, games_left, points_earned, pts_proj;
char team_one;
}

[code]....

View 4 Replies View Related

C :: Binary Game - Using Values With Some Basic Logical Operations

Apr 24, 2014

When things at work get overwhelming, it's not unusual for me to briefly "escape" by writing small programs simply for fun. A few days ago, I had an idea for a "binary game". I completed the first draft of it yesterday.

The idea is simple. The game uses 8-bit values. At the start of the game, a random "target" value is generated. The player is dealt a "hand" of seven values. The object is to use the values in your hand, along with some basic logical operations, to create the "target" value. While the idea is simple, the game itself can be quite difficult.

Here is an example of the output:

Code: --------------------
T: 1111 1100 (0xFC)
--------------------
0: 0000 0000 (0x00)
--------------------
1: 1100 1110 (0xCE)
2: 1010 0011 (0xA3)
3: 1100 0101 (0xC5)
4: 1011 1111 (0xBF)
5: 1010 1011 (0xAB)
6: 0001 1011 (0x1B)
7: 0001 1011 (0x1B)
--------------------

: Looking at the first column:
- 'T' is the "target" value
- '0' can be thought of as the "game board" - this is the value that needs to match the target value for a win
- '1' - '7' are the values in your "hand"

You can apply logic AND ('A'), OR ('O'), or XOR ('X') to a value in your hand with the value on the "game board". You are also allowed to apply logic to two values in your hand to create a new value for your hand. When a value from your hand is used, it is removed.

Some examples of the commands:

A30 --- apply logic AND to value #3 in your hand, and the "game board" value
O23 --- apply logic OR to value #2 in your hand and value #3 in your hand
X70 --- apply logic XOR to value #7 in your hand, and the "game board" value

You can also be dealt new values (as long as there's room in your hand) with the '+' command. 'H' or 'h' prints the help, and 'Q' or 'q' exits the game.

I haven't thoroughly tested it yet, since I just finished it a yesterday, but so far it looks good. The program itself uses only standard C.

I was dickering with the idea of supporting more logical operators (NOT, NAND, NOR, XNOR, shift), but I like the simplicity and resulting difficulty of the current implementation.

During initial testing, I realized it's possible to have doubles in your hand. Also, it's quite possible to be dealt the target value directly, which means that you could potentially win with one move, chance permitting. At first I thought about defending against these conditions, but came to the conclusion that it is fine as is - chances of an instant win are small, and if it does occur, would still be an enjoyable experience. Besides, if you're dealt the target value after the "game board" value has been modified.

Also, I did not allow a value of "zero" in the players hand. This was originally because I thought it would be of little use (though I've been reconsidering this). This also means that if two values in the hand are combined and result in zero, both values are removed and no new value is added. This was originally a bug, but I think I'll just reclassify it as a feature

So far, I found that the best strategy is to avoid modifying the "game board" value, and just play with the values in your hand. If you can get the target value in your hand, you just OR it with the "game board" and you're done.

View 2 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved