# Gaius Baltar

Member

34

300 Neutral

• Rank
Member

• Interests
Art
1. ## Ray-Sphere intersection explanation

I found a great site that goes in-depth about how this method works: https://www.scratchapixel.com/lessons/3d-basic-rendering/minimal-ray-tracer-rendering-simple-shapes/ray-sphere-intersection Solved my problem.
2. ## Ray-Sphere intersection explanation

Hey there, I recently came across this: https://github.com/ssloy/tinyraytracer It's a raytracer implemented in a very minimal way. This person uses a method to find intersections between a ray and a sphere that I can't understand. His implementation is as follows: bool ray_intersect(const Vec3f &orig, const Vec3f &dir, float &t0) const { Vec3f L = center - orig; float tca = L*dir; float d2 = L*L - tca*tca; if (d2 > radius*radius) return false; float thc = sqrtf(radius*radius - d2); t0 = tca - thc; float t1 = tca + thc; if (t0 < 0) t0 = t1; if (t0 < 0) return false; return true; } This code confuses me, because I've always used the quadratic formula to get the discriminant of the ray-sphere function. It looks like he is doing the same thing, but perhaps using a different formula to begin with? If someone has the time I'd appreciate an explanation or a breakdown of this method.
3. ## Jumbled Texture output when using D3D11_MAPPED_SUBRESOURCE and Map/Unmap

Thanks... I knew it was gonna be something simple...
4. ## DX11 Jumbled Texture output when using D3D11_MAPPED_SUBRESOURCE and Map/Unmap

I'm trying to change the data in a Texture2D with Map/Unmap and am running into an issue where the texture seems to only appear in the top 5th of the screen and the rest is just random pixels. (screenshot for clarification) Here's some code: uint32_t* m_colorBuffer; //buffer to fill the texture with random colors D3D11_SUBRESOURCE_DATA m_textureData; ID3D11Texture2D* m_texture; D3D11_MAPPED_SUBRESOURCE mappedResource; m_deviceContext->Map(m_texture, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource); uint32_t rowSize = 256 * 4; BYTE* mappedData = reinterpret_cast<BYTE*>(mappedResource.pData); for (int i = 0; i < 256; i++) { memcpy(mappedData, &(m_colorBuffer[i*rowSize]), rowSize); mappedData += mappedResource.RowPitch; } m_deviceContext->Unmap(m_texture, 0); Can Someone please tell me what I'm doing wrong here? I'd be happy to supply more code if needed.
5. ## Issue with personal DirectX Framework

Okay, I just realized that I forgot to add the InputLayout to the immediateContext. That basically solved the issue.   After some edits to the code I finally get the output I was hoping for:

7. ## c# method question

It appears, I was wrong, go with Nypyren's suggestion, in this case it would be the better solution overall.
8. ## c# method question

Disregard this post.
9. ## c# method question

Disregard this post
10. ## Line vs Triangle collision in 3D

You're welcome! The thing is, I've never actually done anything in 3d so this is completely theoretical... would be logical though.   Also I would be interested to know how one would find the position where the line and triangle pass each other, I could probably figure it out for 2d but it seems more complex for 3d.If anyone knows, would be great to note into my reference book.
11. ## Line vs Triangle collision in 3D

I'm just guessing right now, so this might be wrong:   First check if the line ever passes the triangle, if yes, take the point where the line passes the triangle and make three more triangles with each of the points of the original triangle and the point like so:       If the area of the three triangles is equal to the area of the larger triangle, you have yourself an intersection. I actually had a quick glimpse at a youtube video talking about this kind of intersection, thought it might be worth sharing my two cents.   Edit: Here's the video:
12. ## Missile Command code review request

I figured that, but I thought Visual Studio somehow did it differently. Suppose not.
13. ## Missile Command code review request

Oh, I missed the static part. Thanks for clarification.
14. ## Missile Command code review request

I'm using Visual Studio, as far as I can tell it only compiles the files that have been edited, and if I'm not mistaken, I believe that it doesn't compile files just because they were included by another. Or, I could be totally wrong about that... I never really considered the possibility of simply creating a data array to fill another array. Wouldn't it be expensive though to recreate the array every iteration of the loop?
15. ## Missile Command code review request

So, I should make multiple headers? includes.h and constants.h?   But I also don't really see how "init.h" isn't scalable, is it because of the merging of includes and constants in a single file, or is there another reason?   Even with the "classname.cpp #includes classname.h" thing, wouldn't it still be the same? Because the classname.h still might depend on stuff from init.h. Or am I getting this wrong somehow?     Yeah, I try to spend the least amount of time on naming my variables, if I don't think of a name fast, it might get a bad name .     I know. After a while it got really confusing to try and find code I was looking for in that file, In my next project I'm going to have my entire GUI in a separate class, that should save me a few lines.        I was thinking of doing that, but then I didn't... I suppose it was too much work for me , especially because it was only used for the high scores.       Yeah, KulSeran told me the same thing just about. And my question to him still stands:  "[background=#fafbfc]...I believe sfml takes care of deallocating it's own allocated memory, so the destructor wouldn't really be necessary(?)[/background]". Is it always necessary to implement all three? Because in the case of the button class, the destructor would be empty.      I remember someone posting on a previous thread of mine that I shouldn't keep the application running after an error has occured. Should I keep it running or not? I'm confused, but I suppose I could write the error to a error log file or something.     My attempt at trying to stay consistent with the sfml naming convention (mostly inspired by the sf::Vector<> class) , I suppose I failed.      That's a mistake, I think most of the time I just completely forget that I'm following any kind of naming convention and just name the damn thing whatever seems right at the time .       Huh, but how would I integrate the jump from 300 to 600? I can't think of a way.      Woops, I think the problem here is that I used to have a text class. When I got rid of that I tried to rewrite everything into the button class, I suppose I just missed a few things on the way.       I keep forgetting some of these built in methods to make life easier... I'll implement that.        I used a whole button class, because I thought there was a method to test if one class was equal to another, that failed, so I used the string value in the button, seems stupid now that I think about it.       That's what I did with the missiles, because I first had like five vectors just for the missiles in my Missile_Command class. But I didn't want to make a whole new class for the enemies, I suppose it slipped my mind that I could have easily used a structure to store both items...       Thanks for reading through my code, I appreciate the time that you took to do so. This review really gave me a further push in the right direction and I'll most likely use this as a reference for future projects.      vector.end() is 1) you could do (vector.end() - 1) as well.  The end iterator is one-past the end of the array, and does not point at a valid object. 2) It's all relative to the container.  Not all containers provide iterators that support (end() -1).  Vector happens to be a random-access iterator, so vector.begin() + x is just as fast as vector.end() - y.  So yes, you could base the second point off the end iterator.     Oh, I thought vector.end() was just the last item in the array.   You're right, in my case it wouldn't matter for the _trails particles, because they all have a one pixel area and are mostly white.